Skip to content

Commit a02ca27

Browse files
committed
fix: normalize pi-plugin indentation to match biome config
Biome config enforces 4-space indentation but these files used tabs. Also fixes missing trailing newline in strip-tag-prefix.ts. Run: bun run --cwd packages/pi-plugin lint passes clean. Related to #97
1 parent 5a553b8 commit a02ca27

2 files changed

Lines changed: 60 additions & 49 deletions

File tree

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,57 @@
1-
/**
2-
* Strip injected `§N§` tag prefixes AND defensively strip cargo-cult MC tag
3-
* notation from assistant text before Pi persists the message.
4-
*
5-
* Mirrors OpenCode's `text-complete.ts` via {@link stripPersistedAssistantText}:
6-
* whole `§N§` pairs globally, malformed hybrids, then stray `§`. Does not strip
7-
* bare leading digits on the transform path.
8-
*
9-
* Pi persists raw assistant text from `message_end`; this hook mutates text parts
10-
* before `agent-session.ts:appendMessage()` writes jsonl.
11-
*
12-
* Only `assistant` messages are stripped. User/tool messages keep intentional tags.
13-
*/
14-
15-
import { stripPersistedAssistantText } from "../../plugin/src/hooks/magic-context/tag-content-primitives";
16-
17-
/**
18-
* Mutate the given assistant message's text parts in place to strip MC tag notation.
19-
*
20-
* Returns true if any text was modified. Production callers use `registerStripTagPrefix`.
21-
*/
22-
export function stripTagPrefixFromAssistantMessage(message: {
23-
role: string;
24-
content: unknown;
25-
}): boolean {
26-
if (message.role !== "assistant") return false;
27-
if (!Array.isArray(message.content)) return false;
28-
29-
let mutated = false;
30-
for (const part of message.content) {
31-
if (
32-
part === null ||
33-
typeof part !== "object" ||
34-
(part as { type?: unknown }).type !== "text"
35-
) {
36-
continue;
37-
}
38-
const textPart = part as { type: "text"; text: unknown };
39-
if (typeof textPart.text !== "string") continue;
40-
const stripped = stripPersistedAssistantText(textPart.text);
41-
if (stripped !== textPart.text) {
42-
textPart.text = stripped;
43-
mutated = true;
44-
}
45-
}
46-
return mutated;
47-
}
48-
1+
/**
2+
* Strip injected `§N§` tag prefixes AND defensively strip cargo-cult MC tag
3+
* notation from assistant text before Pi persists the message.
4+
*
5+
* Mirrors OpenCode's `text-complete.ts` via {@link stripPersistedAssistantText}:
6+
* whole `§N§` pairs globally, malformed hybrids, then stray `§`. Does not strip
7+
* bare leading digits on the transform path.
8+
*
9+
* Pi persists raw assistant text from `message_end`; this hook mutates text parts
10+
* before `agent-session.ts:appendMessage()` writes jsonl.
11+
*
12+
* Only `assistant` messages are stripped. User/tool messages keep intentional tags.
13+
*/
14+
15+
import { stripPersistedAssistantText } from "../../plugin/src/hooks/magic-context/tag-content-primitives";
16+
17+
/**
18+
* Mutate the given assistant message's text parts in place to strip MC tag notation.
19+
*
20+
* Returns true if any text was modified. Production callers use `registerStripTagPrefix`.
21+
*/
22+
23+
export function stripTagPrefixFromAssistantMessage(message: {
24+
role: string;
25+
26+
content: unknown;
27+
}): boolean {
28+
if (message.role !== "assistant") return false;
29+
30+
if (!Array.isArray(message.content)) return false;
31+
32+
let mutated = false;
33+
34+
for (const part of message.content) {
35+
if (
36+
part === null ||
37+
typeof part !== "object" ||
38+
(part as { type?: unknown }).type !== "text"
39+
) {
40+
continue;
41+
}
42+
43+
const textPart = part as { type: "text"; text: unknown };
44+
45+
if (typeof textPart.text !== "string") continue;
46+
47+
const stripped = stripPersistedAssistantText(textPart.text);
48+
49+
if (stripped !== textPart.text) {
50+
textPart.text = stripped;
51+
52+
mutated = true;
53+
}
54+
}
55+
56+
return mutated;
57+
}

packages/pi-plugin/src/temporal-awareness-pi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export function injectPiTemporalMarkers(messages: unknown[]): number {
7878
const userMsg = msg as PiUserMessage;
7979
if (typeof userMsg.content === "string") {
8080
if (!TEMPORAL_MARKER_PATTERN.test(stripTagPrefix(userMsg.content))) {
81-
const { tagPrefix, body } = peelLeadingMcTagNotation(userMsg.content);
81+
const { tagPrefix, body } = peelLeadingMcTagNotation(
82+
userMsg.content,
83+
);
8284
(messages as PiAgentMessage[])[i] = {
8385
...userMsg,
8486
content: tagPrefix + prefix + body,

0 commit comments

Comments
 (0)