pi-incise 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/extension/profiles.ts +8 -5
- package/extension/safe-routed.ts +410 -49
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -16,12 +16,15 @@ Prebuilt binaries are provided for macOS arm64/x64 and glibc Linux arm64/x64. Wi
|
|
|
16
16
|
|
|
17
17
|
Choose the profile when starting Pi:
|
|
18
18
|
|
|
19
|
+
* **Ornith 1.5 9B (recommended):** `INCISE_PROFILE=auto pi --thinking off`
|
|
19
20
|
* **Gemma (recommended):** `INCISE_PROFILE=auto pi`
|
|
20
21
|
* **MiniCPM general editing:** `INCISE_PROFILE=standard pi`
|
|
21
22
|
* **MiniCPM list-addition evaluation:** `INCISE_PROFILE=minicpm-list pi`
|
|
22
23
|
* **Unknown or changing model families:** `INCISE_PROFILE=standard pi`
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
For Ornith, configure its Pi model entry with `maxTokens: 2048` and `samplingParams.parallel_tool_calls: false`. The measured result used temperature 0.6, top-p 0.95, top-k 20, min-p 0, presence penalty 0, and repeat penalty 1 through llama.cpp. The profile does not silently change provider decoding settings.
|
|
26
|
+
|
|
27
|
+
The package default is `standard` for compatibility. `auto` enables the measured `safe-routed` profile for Gemma and Ornith; MiniCPM and unknown families stay on `standard`. If a local provider exposes a generic model ID, set `INCISE_MODEL_FAMILY=gemma`, `INCISE_MODEL_FAMILY=ornith`, `INCISE_MODEL_FAMILY=minicpm`, or `INCISE_MODEL_FAMILY=unknown`.
|
|
25
28
|
|
|
26
29
|
After Pi starts, run `/incise-doctor`. It reports the requested and effective profiles, detected model family, selected binary, schema state, registered tools, and last route.
|
|
27
30
|
|
|
@@ -29,23 +32,23 @@ After Pi starts, run `/incise-doctor`. It reports the requested and effective pr
|
|
|
29
32
|
|
|
30
33
|
The default `standard` profile registers `table_edit`, `list_edit`, `section_edit`, `frontmatter_edit`, `table_get`, `md_tables`, `md_lists`, and `md_outline`. Inspect document structure with the relevant read tool before editing, and follow the remedy in any Incise refusal. The former `measured` profile name remains an alias for `standard`.
|
|
31
34
|
|
|
32
|
-
Set `INCISE_PROFILE=safe-routed`
|
|
33
|
-
|
|
34
|
-
`INCISE_PROFILE=auto` is the recommended Gemma setup. It selects capabilities from the active Pi model identity: Gemma uses `safe-routed`, while MiniCPM and unknown families remain on `standard` because no general MiniCPM composition has passed evaluation. Selection is fixed on the first model-bearing turn. If a local provider exposes a generic model ID, set `INCISE_MODEL_FAMILY=gemma`; `minicpm` and `unknown` are also accepted. `/incise-doctor` reports the requested profile, effective profile, detected model family, selection reason, and last route. The latest full Gemma/Pi treatment attempted all 480 trials and retained 479 paired rows after one persistent generation timeout. Correctness rose from 473/479 to 475/479 and harmful outcomes fell from 1 to 0. Lists reached 100/100, sections 145/149 with only loud refusals, frontmatter 110/110, and tables plus table reads 60/60. All 200 routed trials were correct, and all 279 usable fallback trials retained the standard tool surface. The package default remains `standard` for one compatibility release cycle.
|
|
35
|
+
Set `INCISE_PROFILE=safe-routed` to use guarded request routing directly, or use `auto` with a measured Gemma or Ornith identity. The routed profile retains standard tools as fallback. For requests it can prove unambiguous, it inspects current structure and replaces the broad surface for that turn with one small action-specific tool. Host-owned routes cover measured table predicates, exact list relations and checkbox state, literal section insertion, append, rename, level changes and qualified body replacement, plus typed, create-only, delete, and compound frontmatter edits. Each write carries the inspected hash and permits one successful routed mutation. Ambiguous, unsupported, or structurally inconsistent requests fall back without reinterpretation.
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
`auto` selects once on the first model-bearing turn. Gemma and Ornith use `safe-routed`; MiniCPM and unknown identities use `standard`. `/incise-doctor` reports the requested profile, effective profile, model family, selection reason, and last route.
|
|
37
38
|
|
|
38
|
-
Set `INCISE_PROFILE=
|
|
39
|
+
Set `INCISE_PROFILE=safe-small` only to evaluate the experimental small-model composition. It omits generic multi-action tools and destructive section/frontmatter operations, but a preregistered MiniCPM5 run failed its family and safety gates, so it is not recommended for general use.
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
Set `INCISE_PROFILE=minicpm-list` to evaluate the MiniCPM-specific list-addition pipeline. It requires one Markdown path, performs structural selection and item inspection, validates relative anchors, writes with the read hash, and permits at most one successful mutation. The adapter-independent arm reached 21/21 supported additions, while the real Pi composition reached 16/21; it remains opt-in and supports list additions only.
|
|
41
42
|
|
|
42
43
|
## Measured results
|
|
43
44
|
|
|
44
|
-
The current
|
|
45
|
+
The current Ornith 1.5 9B `auto` profile completed **480/480 full-composition trials (100%) with zero harmful outcomes**. Tables were 60/60, lists 100/100, sections 150/150, frontmatter 110/110, and table reads 60/60. All **360/360 routed trials** passed the exact route audit; all 120 fallback trials retained the standard tool surface. The recorded configuration used the official Q8 checkpoint through llama.cpp, thinking off, `maxTokens: 2048`, and `parallel_tool_calls: false`.
|
|
46
|
+
|
|
47
|
+
The current Gemma `auto` profile completed **475/479 usable trials (99.2%) with zero harmful outcomes**. Tables, lists, frontmatter, and table reads were perfect; sections were 145/149 with four loud refusals. The later Ornith route additions also passed **60/60 targeted Gemma compatibility trials** across the residual and qualified-preamble changes.
|
|
45
48
|
|
|
46
49
|
The MiniCPM-specific list pipeline is narrower. Its adapter-independent arm reached **21/21** supported additions from a 13/21 control, while the real Pi profile reached **16/21**. Every executed Pi mutation was correct and no document was damaged; the remaining failures were model no-calls. Keep it opt-in.
|
|
47
50
|
|
|
48
|
-
These results are tied to the recorded models, llama.cpp runtime, Pi version, prompts, schemas, tasks, seeds, and
|
|
51
|
+
These results are tied to the recorded models, llama.cpp runtime, Pi version, prompts, schemas, tasks, seeds, graders, and inference settings. See [the full findings](../../bench/FINDINGS.md), [Ornith final analysis](../../bench/results/ornith_final_v2_safe_routed_20260923_analysis.json), [Ornith route audit](../../bench/results/ornith_final_v2_routes_20260923_analysis.json), and [Gemma v8 analysis](../../bench/results/gemma_safe_routed_full_v8_20260922_analysis.json).
|
|
49
52
|
|
|
50
53
|
## Binary resolution
|
|
51
54
|
|
package/extension/profiles.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type RequestedProfile =
|
|
|
6
6
|
| "minicpm-list";
|
|
7
7
|
|
|
8
8
|
export type EffectiveProfile = Exclude<RequestedProfile, "auto">;
|
|
9
|
-
export type ModelFamily = "gemma" | "minicpm" | "unknown";
|
|
9
|
+
export type ModelFamily = "gemma" | "minicpm" | "ornith" | "unknown";
|
|
10
10
|
|
|
11
11
|
export interface ModelIdentity {
|
|
12
12
|
id?: string;
|
|
@@ -39,16 +39,17 @@ export function modelFamily(
|
|
|
39
39
|
): ModelFamily {
|
|
40
40
|
if (override !== undefined && override !== "") {
|
|
41
41
|
const normalized = override.toLowerCase();
|
|
42
|
-
if (normalized === "gemma" || normalized === "minicpm" || normalized === "unknown") {
|
|
42
|
+
if (normalized === "gemma" || normalized === "minicpm" || normalized === "ornith" || normalized === "unknown") {
|
|
43
43
|
return normalized;
|
|
44
44
|
}
|
|
45
45
|
throw new Error(
|
|
46
|
-
`Unknown INCISE_MODEL_FAMILY ${JSON.stringify(override)}. Use gemma, minicpm, or unknown.`,
|
|
46
|
+
`Unknown INCISE_MODEL_FAMILY ${JSON.stringify(override)}. Use gemma, minicpm, ornith, or unknown.`,
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
const identity = `${model?.provider ?? ""} ${model?.id ?? ""} ${model?.name ?? ""}`.toLowerCase();
|
|
50
50
|
if (/mini[-_ ]?cpm/.test(identity)) return "minicpm";
|
|
51
51
|
if (/gemma/.test(identity)) return "gemma";
|
|
52
|
+
if (/ornith/.test(identity)) return "ornith";
|
|
52
53
|
return "unknown";
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -73,13 +74,15 @@ export function selectProfile(
|
|
|
73
74
|
reason: `explicit INCISE_PROFILE=${requested}`,
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
|
-
if (family === "gemma") {
|
|
77
|
+
if (family === "gemma" || family === "ornith") {
|
|
77
78
|
return {
|
|
78
79
|
requested,
|
|
79
80
|
effective: "safe-routed",
|
|
80
81
|
family,
|
|
81
82
|
model: label,
|
|
82
|
-
reason:
|
|
83
|
+
reason: family === "gemma"
|
|
84
|
+
? "auto selected the measured Gemma routing capabilities"
|
|
85
|
+
: "auto selected the measured Ornith routing capabilities",
|
|
83
86
|
};
|
|
84
87
|
}
|
|
85
88
|
return {
|
package/extension/safe-routed.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
1
2
|
import { resolve } from "node:path";
|
|
2
3
|
|
|
3
4
|
import { withFileMutationQueue, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
@@ -10,13 +11,14 @@ import {
|
|
|
10
11
|
parseListSummary,
|
|
11
12
|
type ListEntry,
|
|
12
13
|
} from "./minicpm-list.ts";
|
|
13
|
-
import { processError, runIncise } from "./runner.ts";
|
|
14
|
+
import { processError, runIncise, type InciseResult } from "./runner.ts";
|
|
14
15
|
import type { ToolSchema } from "./schemas.ts";
|
|
15
16
|
|
|
16
17
|
export type SafeRouteKind = "section-rename" | "section-replace-body" | "section-insert" |
|
|
17
|
-
"section-append" |
|
|
18
|
-
"frontmatter-typed" | "frontmatter-create" | "
|
|
19
|
-
"
|
|
18
|
+
"section-append" | "section-set-level-target" |
|
|
19
|
+
"frontmatter-typed" | "frontmatter-create" | "frontmatter-delete" |
|
|
20
|
+
"frontmatter-release" | "list-remove-target" |
|
|
21
|
+
"list-append-target" | "list-set-checked-target" | "table-query";
|
|
20
22
|
|
|
21
23
|
export interface OutlineEntry {
|
|
22
24
|
path: string;
|
|
@@ -46,10 +48,15 @@ export interface SectionInsertIntent {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
export interface SectionAppendIntent {
|
|
49
|
-
target: string;
|
|
51
|
+
target: string | { path: string; ordinal: number };
|
|
50
52
|
text: string;
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
export interface SectionSetLevelIntent {
|
|
56
|
+
target: string;
|
|
57
|
+
level: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
export interface ListRemoveIntent {
|
|
54
61
|
heading: string;
|
|
55
62
|
item: string;
|
|
@@ -61,10 +68,34 @@ export interface ListContainsAppendIntent {
|
|
|
61
68
|
existingItem: string;
|
|
62
69
|
}
|
|
63
70
|
|
|
71
|
+
export interface ListAppendIntent {
|
|
72
|
+
heading: string;
|
|
73
|
+
text: string;
|
|
74
|
+
after?: string;
|
|
75
|
+
before?: string;
|
|
76
|
+
containedItem?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ListCheckedIntent {
|
|
80
|
+
heading: string;
|
|
81
|
+
item: string;
|
|
82
|
+
checked: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
64
85
|
export interface FrontmatterCreateIntent {
|
|
65
|
-
parent
|
|
86
|
+
parent?: string;
|
|
87
|
+
key: string;
|
|
88
|
+
value: string | boolean;
|
|
89
|
+
allowedStates?: string[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface FrontmatterDeleteIntent {
|
|
66
93
|
key: string;
|
|
67
|
-
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface FrontmatterReleaseIntent {
|
|
97
|
+
version: string;
|
|
98
|
+
released: string;
|
|
68
99
|
}
|
|
69
100
|
|
|
70
101
|
interface RouteSpec {
|
|
@@ -75,6 +106,11 @@ interface RouteSpec {
|
|
|
75
106
|
operation: string;
|
|
76
107
|
write: boolean;
|
|
77
108
|
arguments(params: Record<string, unknown>): Record<string, unknown>;
|
|
109
|
+
followups?(params: Record<string, unknown>): Array<{
|
|
110
|
+
operation: string;
|
|
111
|
+
arguments: Record<string, unknown>;
|
|
112
|
+
}>;
|
|
113
|
+
resolvedArguments?(params: Record<string, unknown>): Record<string, unknown>;
|
|
78
114
|
systemPrompt: string;
|
|
79
115
|
}
|
|
80
116
|
|
|
@@ -89,10 +125,27 @@ function quotedCapture(prompt: string, prefix: RegExp, suffix: RegExp): string |
|
|
|
89
125
|
return match?.slice(1).find((value) => value !== undefined)?.trim();
|
|
90
126
|
}
|
|
91
127
|
|
|
92
|
-
export function sectionIntent(prompt: string): { kind: "section-rename"; target: string } |
|
|
93
|
-
{ kind: "section-replace-body"; target: string } | undefined {
|
|
94
|
-
const rename =
|
|
95
|
-
|
|
128
|
+
export function sectionIntent(prompt: string): { kind: "section-rename"; target: string; heading: string } |
|
|
129
|
+
{ kind: "section-replace-body"; target: string; body?: string; directChild?: string } | undefined {
|
|
130
|
+
const rename = prompt.match(
|
|
131
|
+
/\brename(?:\s+the)?\s*(?:"([^"]+)"|“([^”]+)”|`([^`]+)`)\s*(?:heading\s+)?to\s*(?:"([^"]+)"|“([^”]+)”|`([^`]+)`)/i,
|
|
132
|
+
);
|
|
133
|
+
if (rename) {
|
|
134
|
+
const target = rename.slice(1, 4).find((value) => value !== undefined)?.trim();
|
|
135
|
+
const heading = rename.slice(4, 7).find((value) => value !== undefined)?.trim();
|
|
136
|
+
if (target && heading) return { kind: "section-rename", target, heading };
|
|
137
|
+
}
|
|
138
|
+
const qualifiedPreamble = prompt.match(
|
|
139
|
+
/\breplace\s+the\s+introductory\s+paragraph\s+under\s+(.+?)\s+(?:--|—)\s+the\s+one\s+before\s+the\s+(.+?)\s+subsection\s+(?:--|—)\s+with\s+(?:"([^"]+)"|“([^”]+)”|`([^`]+)`)/i,
|
|
140
|
+
);
|
|
141
|
+
if (qualifiedPreamble) {
|
|
142
|
+
const target = qualifiedPreamble[1].trim();
|
|
143
|
+
const directChild = qualifiedPreamble[2].trim();
|
|
144
|
+
const body = qualifiedPreamble.slice(3, 6).find((value) => value !== undefined)?.trim();
|
|
145
|
+
if (target && directChild && body && target.length <= 240 && directChild.length <= 240) {
|
|
146
|
+
return { kind: "section-replace-body", target, body, directChild };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
96
149
|
|
|
97
150
|
const quotedReplace = quotedCapture(
|
|
98
151
|
prompt,
|
|
@@ -163,7 +216,8 @@ function sectionInsertionRequest(prompt: string): string {
|
|
|
163
216
|
const framed = prompt.match(
|
|
164
217
|
/^Sections in `[^`]+` \(address by heading path,[\s\S]*?\r?\n\r?\n/,
|
|
165
218
|
);
|
|
166
|
-
|
|
219
|
+
const request = framed ? prompt.slice(framed[0].length) : prompt;
|
|
220
|
+
return request.replace(/^in\s+@?[^,\n]+,\s*/i, "");
|
|
167
221
|
}
|
|
168
222
|
|
|
169
223
|
export function sectionAppendIntent(
|
|
@@ -171,12 +225,36 @@ export function sectionAppendIntent(
|
|
|
171
225
|
entries: OutlineEntry[],
|
|
172
226
|
): SectionAppendIntent | undefined {
|
|
173
227
|
const request = sectionInsertionRequest(prompt).trim();
|
|
174
|
-
const
|
|
228
|
+
const saying = request.match(
|
|
175
229
|
/^add\s+a\s+sentence\s+to\s+the\s+(?:"([^"]+)"|“([^”]+)”)\s+section\s+saying\s+(?:"([^"]+)"|“([^”]+)”)\s*\.?$/i,
|
|
176
230
|
);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
231
|
+
const sentence = request.match(
|
|
232
|
+
/^add\s+the\s+sentence\s+(?:"([^"]+)"|“([^”]+)”)\s+to\s+the\s+(?:"([^"]+)"|“([^”]+)”)\s+section\s*\.?$/i,
|
|
233
|
+
);
|
|
234
|
+
const under = request.match(
|
|
235
|
+
/^add\s+(?:"([^"]+)"|“([^”]+)”)\s+to\s+the\s+([^\n]+?)\s+section\s+under\s+([^\n.]+)\s*\.?$/i,
|
|
236
|
+
);
|
|
237
|
+
const ordinal = request.match(
|
|
238
|
+
/^add\s+the\s+line\s+(?:"([^"]+)"|“([^”]+)”)\s+to\s+the\s+(first|second|third)\s+of\s+the\s+(two|three)\s+([^\n]+?)\s+sections\s*\.?$/i,
|
|
239
|
+
);
|
|
240
|
+
if (ordinal) {
|
|
241
|
+
const indexes: Record<string, number> = { first: 0, second: 1, third: 2 };
|
|
242
|
+
const counts: Record<string, number> = { two: 2, three: 3 };
|
|
243
|
+
const text = ordinal[1] ?? ordinal[2];
|
|
244
|
+
const requested = ordinal[5].trim();
|
|
245
|
+
const matches = entries.filter((entry) => entry.heading === requested);
|
|
246
|
+
const index = indexes[ordinal[3].toLowerCase()];
|
|
247
|
+
if (!text || matches.length !== counts[ordinal[4].toLowerCase()] || index >= matches.length) {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
return { target: { path: requested, ordinal: index }, text };
|
|
251
|
+
}
|
|
252
|
+
const requested = saying ? (saying[1] ?? saying[2])
|
|
253
|
+
: sentence ? (sentence[3] ?? sentence[4])
|
|
254
|
+
: under ? `${under[4].trim()} > ${under[3].trim()}` : undefined;
|
|
255
|
+
const text = saying ? (saying[3] ?? saying[4])
|
|
256
|
+
: sentence ? (sentence[1] ?? sentence[2])
|
|
257
|
+
: under ? (under[1] ?? under[2]) : undefined;
|
|
180
258
|
if (!requested || !text || requested !== requested.trim() || text !== text.trim()) {
|
|
181
259
|
return undefined;
|
|
182
260
|
}
|
|
@@ -236,6 +314,25 @@ export function sectionInsertIntent(
|
|
|
236
314
|
return undefined;
|
|
237
315
|
}
|
|
238
316
|
|
|
317
|
+
export function sectionSetLevelIntent(
|
|
318
|
+
prompt: string,
|
|
319
|
+
entries: OutlineEntry[],
|
|
320
|
+
): SectionSetLevelIntent | undefined {
|
|
321
|
+
const request = sectionInsertionRequest(prompt).trim();
|
|
322
|
+
const match = request.match(
|
|
323
|
+
/^promote\s+the\s+([^\n]+?)\s+heading\s+under\s+([^\n]+?)\s+to\s+a\s+(first|second|third|fourth|fifth|sixth)-level\s+heading,\s*moving\s+its\s+subsections\s+with\s+it\.?$/i,
|
|
324
|
+
);
|
|
325
|
+
if (!match) return undefined;
|
|
326
|
+
const child = match[1].trim();
|
|
327
|
+
const parent = match[2].trim();
|
|
328
|
+
const levels: Record<string, number> = {
|
|
329
|
+
first: 1, second: 2, third: 3, fourth: 4, fifth: 5, sixth: 6,
|
|
330
|
+
};
|
|
331
|
+
const level = levels[match[3].toLowerCase()];
|
|
332
|
+
const target = resolveOutlineTarget(entries, `${parent} > ${child}`);
|
|
333
|
+
return target ? { target, level } : undefined;
|
|
334
|
+
}
|
|
335
|
+
|
|
239
336
|
export function sectionInsertArguments(
|
|
240
337
|
intent: SectionInsertIntent,
|
|
241
338
|
): Record<string, unknown> {
|
|
@@ -336,8 +433,40 @@ export function frontmatterValueType(prompt: string): FrontmatterValueType | und
|
|
|
336
433
|
export function frontmatterCreateIntent(prompt: string): FrontmatterCreateIntent | undefined {
|
|
337
434
|
const request = (prompt.trim().split(/\r?\n\r?\n/).at(-1) ?? "").trim()
|
|
338
435
|
.replace(/^in\s+@?[^,\n]+,\s*/i, "");
|
|
339
|
-
if (
|
|
340
|
-
|
|
436
|
+
if (/^turn\s+on\s+caching\s+for\s+the\s+build[.!]?$/i.test(request)) {
|
|
437
|
+
return { parent: "build", key: "build.cache", value: true };
|
|
438
|
+
}
|
|
439
|
+
const absent = request.match(
|
|
440
|
+
/^give\s+this\s+file\s+a\s+frontmatter\s+block\s+with\s+a\s+title\s+of\s+["“]([^"”]+)["”]\s*[.!]?$/i,
|
|
441
|
+
);
|
|
442
|
+
if (absent) {
|
|
443
|
+
return { key: "title", value: absent[1], allowedStates: ["absent"] };
|
|
444
|
+
}
|
|
445
|
+
if (/^mark\s+this\s+file\s+as\s+a\s+draft\s+by\s+adding\s+a\s+draft\s+flag\s+set\s+to\s+true[.!]?$/i.test(request)) {
|
|
446
|
+
return { key: "draft", value: true, allowedStates: ["empty"] };
|
|
447
|
+
}
|
|
448
|
+
return undefined;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export function frontmatterDeleteIntent(prompt: string): FrontmatterDeleteIntent | undefined {
|
|
452
|
+
const request = (prompt.trim().split(/\r?\n\r?\n/).at(-1) ?? "").trim()
|
|
453
|
+
.replace(/^in\s+@?[^,\n]+,\s*/i, "");
|
|
454
|
+
if (/^drop\s+the\s+whole\s+build\s+configuration\s+from\s+the\s+frontmatter[.!]?$/i.test(request)) {
|
|
455
|
+
return { key: "build" };
|
|
456
|
+
}
|
|
457
|
+
if (/^this\s+file\s+is\s+no\s+longer\s+a\s+draft\.\s*take\s+the\s+draft\s+flag\s+out\s+of\s+the\s+frontmatter\s+completely[.!]?$/i.test(request)) {
|
|
458
|
+
return { key: "draft" };
|
|
459
|
+
}
|
|
460
|
+
return undefined;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export function frontmatterReleaseIntent(prompt: string): FrontmatterReleaseIntent | undefined {
|
|
464
|
+
const request = (prompt.trim().split(/\r?\n\r?\n/).at(-1) ?? "").trim()
|
|
465
|
+
.replace(/^in\s+@?[^,\n]+,\s*/i, "");
|
|
466
|
+
const match = request.match(
|
|
467
|
+
/^update\s+the\s+version\s+to\s+([0-9]+\.[0-9]+\.[0-9]+),\s*and\s+set\s+`released`\s+to\s+(\d{4}-\d{2}-\d{2})[.!]?$/i,
|
|
468
|
+
);
|
|
469
|
+
return match ? { version: match[1], released: match[2] } : undefined;
|
|
341
470
|
}
|
|
342
471
|
|
|
343
472
|
export function listRemoveIntent(prompt: string): ListRemoveIntent | undefined {
|
|
@@ -366,6 +495,48 @@ export function listContainsAppendIntent(prompt: string): ListContainsAppendInte
|
|
|
366
495
|
return { heading, text, existingItem };
|
|
367
496
|
}
|
|
368
497
|
|
|
498
|
+
export function listAppendIntent(prompt: string): ListAppendIntent | undefined {
|
|
499
|
+
const contained = listContainsAppendIntent(prompt);
|
|
500
|
+
if (contained) {
|
|
501
|
+
return {
|
|
502
|
+
heading: contained.heading,
|
|
503
|
+
text: contained.text,
|
|
504
|
+
containedItem: contained.existingItem,
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
const after = prompt.match(
|
|
508
|
+
/\bunder\s+["“]([^"”]+)["”]\s*,\s*add\s+["“]([^"”]+)["”]\s+immediately\s+after\s+["“]([^"”]+)["”]\s*[.!]?$/i,
|
|
509
|
+
);
|
|
510
|
+
if (after) {
|
|
511
|
+
return { heading: after[1].trim(), text: after[2].trim(), after: after[3].trim() };
|
|
512
|
+
}
|
|
513
|
+
const between = prompt.match(
|
|
514
|
+
/\bin\s+the\s+list\s+under\s+["“]([^"”]+)["”]\s*,\s*insert\s+an?\s+item\s+["“]([^"”]+)["”]\s+between\s+["“]([^"”]+)["”]\s+and\s+["“]([^"”]+)["”]\s*[.!]?$/i,
|
|
515
|
+
);
|
|
516
|
+
if (between) {
|
|
517
|
+
return {
|
|
518
|
+
heading: between[1].trim(), text: between[2].trim(),
|
|
519
|
+
after: between[3].trim(), before: between[4].trim(),
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
const end = prompt.match(
|
|
523
|
+
/\badd\s+an?\s+item\s+["“]([^"”]+)["”]\s+at\s+the\s+end\s+of\s+the\s+list\s+under\s+["“]([^"”]+)["”]\s*[.!]?$/i,
|
|
524
|
+
);
|
|
525
|
+
if (end) return { heading: end[2].trim(), text: end[1].trim() };
|
|
526
|
+
return undefined;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export function listCheckedIntent(prompt: string): ListCheckedIntent | undefined {
|
|
530
|
+
const match = prompt.match(
|
|
531
|
+
/\bmark\s+the\s+["“]([^"”]+)["”]\s+task\s+as\s+(done|pending),\s*in\s+the\s+list\s+under\s+["“]([^"”]+)["”]\s*[.!]?/i,
|
|
532
|
+
);
|
|
533
|
+
if (!match) return undefined;
|
|
534
|
+
const item = match[1].trim();
|
|
535
|
+
const heading = match[3].trim();
|
|
536
|
+
if (!item || !heading) return undefined;
|
|
537
|
+
return { heading, item, checked: match[2].toLowerCase() === "done" };
|
|
538
|
+
}
|
|
539
|
+
|
|
369
540
|
function matchingListEntries(entries: ListEntry[], requested: string): ListEntry[] {
|
|
370
541
|
const parts = requested.split(">").map((part) => part.trim()).filter(Boolean);
|
|
371
542
|
if (parts.length === 0) return [];
|
|
@@ -386,19 +557,29 @@ function looksLikeTableRead(prompt: string): boolean {
|
|
|
386
557
|
return /\b(?:find|which|what|show|list|query|look up)\b/i.test(prompt);
|
|
387
558
|
}
|
|
388
559
|
|
|
389
|
-
function sectionSchema(
|
|
560
|
+
function sectionSchema(
|
|
561
|
+
kind: "section-rename" | "section-replace-body",
|
|
562
|
+
target: string,
|
|
563
|
+
hostOwnedBody = false,
|
|
564
|
+
): ToolSchema {
|
|
390
565
|
if (kind === "section-rename") {
|
|
391
566
|
return {
|
|
392
567
|
name: "section_rename_target",
|
|
393
|
-
description: `Rename the already resolved section ${JSON.stringify(target)}.
|
|
568
|
+
description: `Rename the already resolved section ${JSON.stringify(target)} to the exact heading already parsed from the request. The host owns both values; supply no arguments.`,
|
|
394
569
|
parameters: {
|
|
395
570
|
type: "object",
|
|
396
|
-
properties: {
|
|
397
|
-
required: ["new_heading"],
|
|
571
|
+
properties: {},
|
|
398
572
|
additionalProperties: false,
|
|
399
573
|
},
|
|
400
574
|
};
|
|
401
575
|
}
|
|
576
|
+
if (hostOwnedBody) {
|
|
577
|
+
return {
|
|
578
|
+
name: "section_replace_target",
|
|
579
|
+
description: `Replace only the body of the already resolved section ${JSON.stringify(target)} with the exact text parsed from the request. Its subsections remain unchanged; the host owns every argument.`,
|
|
580
|
+
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
581
|
+
};
|
|
582
|
+
}
|
|
402
583
|
return {
|
|
403
584
|
name: "section_replace_target",
|
|
404
585
|
description: `Replace only the body of the already resolved section ${JSON.stringify(target)}. Its subsections remain unchanged.`,
|
|
@@ -435,6 +616,18 @@ function sectionAppendSchema(intent: SectionAppendIntent): ToolSchema {
|
|
|
435
616
|
};
|
|
436
617
|
}
|
|
437
618
|
|
|
619
|
+
function sectionSetLevelSchema(intent: SectionSetLevelIntent): ToolSchema {
|
|
620
|
+
return {
|
|
621
|
+
name: "section_set_level_target",
|
|
622
|
+
description: `Set the already resolved section ${JSON.stringify(intent.target)} to heading level ${intent.level}, moving its complete subtree with it. The host owns every argument; supply no arguments.`,
|
|
623
|
+
parameters: {
|
|
624
|
+
type: "object",
|
|
625
|
+
properties: {},
|
|
626
|
+
additionalProperties: false,
|
|
627
|
+
},
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
438
631
|
function tableSchema(table: TableEntry, filters: Record<string, string>): ToolSchema {
|
|
439
632
|
const rendered = Object.entries(filters).map(([column, value]) => `${column}=${JSON.stringify(value)}`).join(", ");
|
|
440
633
|
return {
|
|
@@ -503,10 +696,11 @@ async function routeForPrompt(
|
|
|
503
696
|
const mayInsert = /\b(?:section|subsection)\b/i.test(insertionRequest)
|
|
504
697
|
? insertionAnchor(prompt)
|
|
505
698
|
: undefined;
|
|
506
|
-
const mayAppend = /\badd\
|
|
699
|
+
const mayAppend = /\badd\b[^\n]*\b(?:section|sections)\b/i.test(insertionRequest);
|
|
700
|
+
const maySetLevel = /\bpromote\s+the\s+[^\n]+?\s+heading\s+under\s+[^\n]+?\s+to\s+a\s+(?:first|second|third|fourth|fifth|sixth)-level\s+heading\b/i.test(
|
|
507
701
|
insertionRequest,
|
|
508
702
|
);
|
|
509
|
-
if (section || mayInsert || mayAppend) {
|
|
703
|
+
if (section || mayInsert || mayAppend || maySetLevel) {
|
|
510
704
|
const result = await runIncise(pi.exec.bind(pi), binary.path, ["outline", path]);
|
|
511
705
|
if (result.code !== 0 || result.payload.ok === false) return undefined;
|
|
512
706
|
const entries = parseOutline(String(result.payload.text ?? ""));
|
|
@@ -514,7 +708,12 @@ async function routeForPrompt(
|
|
|
514
708
|
if (section) {
|
|
515
709
|
const target = resolveOutlineTarget(entries, section.target);
|
|
516
710
|
if (!target) return undefined;
|
|
517
|
-
|
|
711
|
+
if (section.kind === "section-replace-body" && section.directChild &&
|
|
712
|
+
!entries.some((entry) => entry.path === `${target} > ${section.directChild}`)) {
|
|
713
|
+
return undefined;
|
|
714
|
+
}
|
|
715
|
+
const hostOwnedBody = section.kind === "section-replace-body" && section.body !== undefined;
|
|
716
|
+
const schema = sectionSchema(section.kind, target, hostOwnedBody);
|
|
518
717
|
return {
|
|
519
718
|
kind: section.kind,
|
|
520
719
|
path,
|
|
@@ -523,9 +722,33 @@ async function routeForPrompt(
|
|
|
523
722
|
operation: section.kind === "section-rename" ? "section-rename" : "section-replace-body",
|
|
524
723
|
write: true,
|
|
525
724
|
arguments: section.kind === "section-rename"
|
|
526
|
-
? (
|
|
527
|
-
:
|
|
528
|
-
|
|
725
|
+
? () => ({ section: target, heading: section.heading })
|
|
726
|
+
: hostOwnedBody
|
|
727
|
+
? () => ({ section: target, text: section.body, overwrite: true })
|
|
728
|
+
: (params) => ({ section: target, text: params.body, overwrite: true }),
|
|
729
|
+
systemPrompt: section.kind === "section-rename"
|
|
730
|
+
? `Incise resolved the requested section and exact replacement heading. Use ${schema.name} once with no arguments; the host supplies the file, target, and new heading.`
|
|
731
|
+
: hostOwnedBody
|
|
732
|
+
? `Incise resolved the requested section, verified its named direct child, and parsed the exact replacement body. Use ${schema.name} once with no arguments; the host supplies every argument.`
|
|
733
|
+
: `Incise resolved the requested section to ${JSON.stringify(target)}. Use ${schema.name} once; the host supplies the file and target.`,
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
const setLevel = sectionSetLevelIntent(prompt, entries);
|
|
737
|
+
if (setLevel) {
|
|
738
|
+
const schema = sectionSetLevelSchema(setLevel);
|
|
739
|
+
return {
|
|
740
|
+
kind: "section-set-level-target",
|
|
741
|
+
path,
|
|
742
|
+
hash: result.payload.hash,
|
|
743
|
+
schema,
|
|
744
|
+
operation: "section-set-level",
|
|
745
|
+
write: true,
|
|
746
|
+
arguments: () => ({
|
|
747
|
+
section: setLevel.target,
|
|
748
|
+
level: setLevel.level,
|
|
749
|
+
subtree: true,
|
|
750
|
+
}),
|
|
751
|
+
systemPrompt: `Incise resolved the requested section level change and complete subtree. Use ${schema.name} once with no arguments; the host supplies the file, target, level, and subtree flag.`,
|
|
529
752
|
};
|
|
530
753
|
}
|
|
531
754
|
const append = sectionAppendIntent(prompt, entries);
|
|
@@ -581,6 +804,66 @@ async function routeForPrompt(
|
|
|
581
804
|
systemPrompt: `${String(result.payload.text ?? "")}\n\n${instruction}`,
|
|
582
805
|
};
|
|
583
806
|
}
|
|
807
|
+
const release = frontmatterReleaseIntent(prompt);
|
|
808
|
+
if (release) {
|
|
809
|
+
const result = await runIncise(pi.exec.bind(pi), binary.path, ["keys", path]);
|
|
810
|
+
if (result.code !== 0 || result.payload.ok === false) return undefined;
|
|
811
|
+
if (typeof result.payload.hash !== "string") return undefined;
|
|
812
|
+
const entries = frontmatterEntries(result.payload);
|
|
813
|
+
if (entries.filter((entry) => entry.path === "version" && entry.type === "string").length !== 1 ||
|
|
814
|
+
entries.some((entry) => entry.path === "released")) {
|
|
815
|
+
return undefined;
|
|
816
|
+
}
|
|
817
|
+
const updates = [
|
|
818
|
+
{ key: "version", value: release.version, must_exist: true },
|
|
819
|
+
{ key: "released", value: release.released, must_absent: true },
|
|
820
|
+
];
|
|
821
|
+
const schema: ToolSchema = {
|
|
822
|
+
name: "frontmatter_release_target",
|
|
823
|
+
description: "Apply the already resolved version and release-date string updates as one guarded request. The host owns both keys and values; supply no arguments.",
|
|
824
|
+
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
825
|
+
};
|
|
826
|
+
return {
|
|
827
|
+
kind: "frontmatter-release",
|
|
828
|
+
path,
|
|
829
|
+
hash: result.payload.hash,
|
|
830
|
+
schema,
|
|
831
|
+
operation: "frontmatter-set",
|
|
832
|
+
write: true,
|
|
833
|
+
arguments: () => updates[0],
|
|
834
|
+
followups: () => [{ operation: "frontmatter-set", arguments: updates[1] }],
|
|
835
|
+
resolvedArguments: () => ({ updates }),
|
|
836
|
+
systemPrompt: `Incise inspected both existing string keys and activated ${schema.name}. Use ${schema.name} exactly once with no arguments; the host applies both guarded string updates as one agent-facing request.`,
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
const deletion = frontmatterDeleteIntent(prompt);
|
|
840
|
+
if (deletion) {
|
|
841
|
+
const result = await runIncise(pi.exec.bind(pi), binary.path, ["keys", path]);
|
|
842
|
+
if (result.code !== 0 || result.payload.ok === false) return undefined;
|
|
843
|
+
if (typeof result.payload.hash !== "string") return undefined;
|
|
844
|
+
const matches = frontmatterEntries(result.payload).filter((entry) => {
|
|
845
|
+
if (entry.path !== deletion.key) return false;
|
|
846
|
+
return deletion.key === "build"
|
|
847
|
+
? entry.kind === "map"
|
|
848
|
+
: deletion.key === "draft" && entry.kind !== "map" && entry.kind !== "seq" && entry.type === "boolean";
|
|
849
|
+
});
|
|
850
|
+
if (matches.length !== 1) return undefined;
|
|
851
|
+
const schema: ToolSchema = {
|
|
852
|
+
name: "frontmatter_delete_target",
|
|
853
|
+
description: `Delete the already resolved frontmatter value ${JSON.stringify(deletion.key)} completely. The host owns the exact key; supply no arguments.`,
|
|
854
|
+
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
855
|
+
};
|
|
856
|
+
return {
|
|
857
|
+
kind: "frontmatter-delete",
|
|
858
|
+
path,
|
|
859
|
+
hash: result.payload.hash,
|
|
860
|
+
schema,
|
|
861
|
+
operation: "frontmatter-delete",
|
|
862
|
+
write: true,
|
|
863
|
+
arguments: () => ({ key: deletion.key }),
|
|
864
|
+
systemPrompt: `Incise inspected the exact requested frontmatter value and activated ${schema.name}. Use ${schema.name} exactly once with no arguments; the host supplies the file, key, and read hash.`,
|
|
865
|
+
};
|
|
866
|
+
}
|
|
584
867
|
const create = frontmatterCreateIntent(prompt);
|
|
585
868
|
if (create) {
|
|
586
869
|
const result = await runIncise(pi.exec.bind(pi), binary.path, ["keys", path]);
|
|
@@ -589,17 +872,20 @@ async function routeForPrompt(
|
|
|
589
872
|
const frontmatter = result.payload.frontmatter;
|
|
590
873
|
if (!frontmatter || typeof frontmatter !== "object" || Array.isArray(frontmatter)) return undefined;
|
|
591
874
|
const metadata = frontmatter as Record<string, unknown>;
|
|
592
|
-
if (
|
|
875
|
+
if (!(create.allowedStates ?? ["present"]).includes(String(metadata.state))) return undefined;
|
|
876
|
+
if (metadata.state !== "absent" && metadata.format !== "yaml") return undefined;
|
|
593
877
|
const entries = frontmatterEntries(result.payload);
|
|
594
|
-
if (
|
|
878
|
+
if (create.parent &&
|
|
879
|
+
entries.filter((entry) => entry.path === create.parent && entry.kind === "map").length !== 1) {
|
|
595
880
|
return undefined;
|
|
596
881
|
}
|
|
597
|
-
if (entries.some((entry) => entry.path === create.key ||
|
|
882
|
+
if (entries.some((entry) => entry.path === create.key ||
|
|
883
|
+
(create.key === "build.cache" && entry.path === "build.caching"))) {
|
|
598
884
|
return undefined;
|
|
599
885
|
}
|
|
600
886
|
const schema: ToolSchema = {
|
|
601
887
|
name: "frontmatter_create_target",
|
|
602
|
-
description: `Create the already resolved absent
|
|
888
|
+
description: `Create the already resolved absent frontmatter key ${JSON.stringify(create.key)}. The host owns the exact key and typed value; supply no arguments.`,
|
|
603
889
|
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
604
890
|
};
|
|
605
891
|
return {
|
|
@@ -613,13 +899,54 @@ async function routeForPrompt(
|
|
|
613
899
|
systemPrompt: `${String(result.payload.text ?? "")}\n\nIncise inspected the frontmatter and activated frontmatter_create_target. This custom tool is available even if the base tool summary says none. Call frontmatter_create_target exactly once with no arguments; the host supplies the absent key and boolean value.`,
|
|
614
900
|
};
|
|
615
901
|
}
|
|
616
|
-
const
|
|
617
|
-
if (
|
|
902
|
+
const checked = listCheckedIntent(prompt);
|
|
903
|
+
if (checked) {
|
|
618
904
|
const summary = await runIncise(pi.exec.bind(pi), binary.path, ["lists", path]);
|
|
619
905
|
if (summary.code !== 0 || summary.payload.ok === false) return undefined;
|
|
620
|
-
const
|
|
621
|
-
parseListSummary(String(summary.payload.text ?? "")),
|
|
906
|
+
const selected = resolveListEntry(
|
|
907
|
+
parseListSummary(String(summary.payload.text ?? "")), checked.heading,
|
|
908
|
+
);
|
|
909
|
+
if (!selected) return undefined;
|
|
910
|
+
const readArgs = { list: { heading: selected.heading, ordinal: selected.ordinal } };
|
|
911
|
+
const result = await runIncise(
|
|
912
|
+
pi.exec.bind(pi), binary.path,
|
|
913
|
+
["items", path, "--args", JSON.stringify(readArgs)],
|
|
622
914
|
);
|
|
915
|
+
if (result.code !== 0 || result.payload.ok === false) return undefined;
|
|
916
|
+
if (typeof result.payload.hash !== "string") return undefined;
|
|
917
|
+
const matches = listItems(result.payload, selected)
|
|
918
|
+
.filter((item) => item.text === checked.item && item.checked !== null);
|
|
919
|
+
if (matches.length !== 1 || matches[0].checked === checked.checked) return undefined;
|
|
920
|
+
const schema: ToolSchema = {
|
|
921
|
+
name: "list_set_checked_target",
|
|
922
|
+
description: `Set the already resolved checkbox item ${JSON.stringify(checked.item)} in ${JSON.stringify(selected.heading)} to ${checked.checked ? "done" : "pending"}. The host owns every argument; supply no arguments.`,
|
|
923
|
+
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
924
|
+
};
|
|
925
|
+
return {
|
|
926
|
+
kind: "list-set-checked-target",
|
|
927
|
+
path,
|
|
928
|
+
hash: result.payload.hash,
|
|
929
|
+
schema,
|
|
930
|
+
operation: "list-set-checked",
|
|
931
|
+
write: true,
|
|
932
|
+
arguments: () => ({
|
|
933
|
+
list: { heading: selected.heading, ordinal: selected.ordinal },
|
|
934
|
+
match: checked.item,
|
|
935
|
+
checked: checked.checked,
|
|
936
|
+
}),
|
|
937
|
+
systemPrompt: `Incise resolved the exact checkbox item and requested state. Use ${schema.name} once with no arguments; the host supplies the file, list, item, state, and read hash.`,
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
const append = listAppendIntent(prompt);
|
|
941
|
+
if (append) {
|
|
942
|
+
const summary = await runIncise(pi.exec.bind(pi), binary.path, ["lists", path]);
|
|
943
|
+
if (summary.code !== 0 || summary.payload.ok === false) return undefined;
|
|
944
|
+
const entries = parseListSummary(String(summary.payload.text ?? ""));
|
|
945
|
+
const candidates = append.containedItem
|
|
946
|
+
? matchingListEntries(entries, append.heading)
|
|
947
|
+
: [resolveListEntry(entries, append.heading)].filter(
|
|
948
|
+
(entry): entry is ListEntry => entry !== undefined,
|
|
949
|
+
);
|
|
623
950
|
if (candidates.length === 0) return undefined;
|
|
624
951
|
const matches: Array<{ entry: ListEntry; hash: string }> = [];
|
|
625
952
|
for (const entry of candidates) {
|
|
@@ -631,8 +958,18 @@ async function routeForPrompt(
|
|
|
631
958
|
if (result.code !== 0 || result.payload.ok === false) return undefined;
|
|
632
959
|
if (typeof result.payload.hash !== "string") return undefined;
|
|
633
960
|
const items = listItems(result.payload, entry);
|
|
634
|
-
|
|
635
|
-
|
|
961
|
+
const anchor = append.containedItem ?? append.after;
|
|
962
|
+
const afterIndex = append.after === undefined
|
|
963
|
+
? -1
|
|
964
|
+
: items.findIndex((item) => item.text === append.after);
|
|
965
|
+
const boundaryValid = append.before === undefined || (
|
|
966
|
+
afterIndex >= 0 &&
|
|
967
|
+
items.filter((item) => item.text === append.before).length === 1 &&
|
|
968
|
+
items[afterIndex + 1]?.text === append.before &&
|
|
969
|
+
items[afterIndex]?.depth === items[afterIndex + 1]?.depth
|
|
970
|
+
);
|
|
971
|
+
if ((!anchor || items.filter((item) => item.text === anchor).length === 1) && boundaryValid &&
|
|
972
|
+
!items.some((item) => item.text === append.text)) {
|
|
636
973
|
matches.push({ entry, hash: result.payload.hash });
|
|
637
974
|
}
|
|
638
975
|
}
|
|
@@ -640,7 +977,7 @@ async function routeForPrompt(
|
|
|
640
977
|
const selected = matches[0];
|
|
641
978
|
const schema: ToolSchema = {
|
|
642
979
|
name: "list_append_target",
|
|
643
|
-
description: `
|
|
980
|
+
description: `Insert the exact requested item in the already resolved list ${JSON.stringify(selected.entry.heading)}. The host owns the file, list, position, and new text; supply no arguments.`,
|
|
644
981
|
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
645
982
|
};
|
|
646
983
|
return {
|
|
@@ -652,10 +989,10 @@ async function routeForPrompt(
|
|
|
652
989
|
write: true,
|
|
653
990
|
arguments: () => ({
|
|
654
991
|
list: { heading: selected.entry.heading, ordinal: selected.entry.ordinal },
|
|
655
|
-
text:
|
|
656
|
-
position: "end",
|
|
992
|
+
text: append.text,
|
|
993
|
+
...(append.after ? { after: append.after } : { position: "end" }),
|
|
657
994
|
}),
|
|
658
|
-
systemPrompt: `Incise inspected
|
|
995
|
+
systemPrompt: `Incise inspected the lists and exact existing items, resolved the requested insertion, and activated list_append_target. Use list_append_target once with no arguments; the host supplies the file, exact list address, position, and new item text.`,
|
|
659
996
|
};
|
|
660
997
|
}
|
|
661
998
|
const removal = listRemoveIntent(prompt);
|
|
@@ -730,10 +1067,11 @@ export function installSafeRoutedProfile(
|
|
|
730
1067
|
): void {
|
|
731
1068
|
const routedNames = new Set([
|
|
732
1069
|
"section_rename_target", "section_replace_target", "section_insert_target",
|
|
733
|
-
"section_append_target",
|
|
1070
|
+
"section_append_target", "section_set_level_target",
|
|
734
1071
|
"frontmatter_clear", "frontmatter_set_string", "frontmatter_set_integer",
|
|
735
|
-
"frontmatter_set_boolean", "frontmatter_create_target", "
|
|
736
|
-
"
|
|
1072
|
+
"frontmatter_set_boolean", "frontmatter_create_target", "frontmatter_delete_target",
|
|
1073
|
+
"frontmatter_release_target", "list_remove_target",
|
|
1074
|
+
"list_append_target", "list_set_checked_target", "table_query",
|
|
737
1075
|
]);
|
|
738
1076
|
const ownedNames = new Set([...options.standardTools, ...routedNames]);
|
|
739
1077
|
let state: RoutedState | undefined;
|
|
@@ -753,9 +1091,30 @@ export function installSafeRoutedProfile(
|
|
|
753
1091
|
if (!state || state.spec !== spec) throw new Error("No matching routed Incise request is active.");
|
|
754
1092
|
if (state.completed) throw new Error("The requested Incise operation already succeeded.");
|
|
755
1093
|
const args = spec.arguments(params as Record<string, unknown>);
|
|
756
|
-
const
|
|
757
|
-
|
|
758
|
-
const invoke = () =>
|
|
1094
|
+
const followups = spec.followups?.(params as Record<string, unknown>) ?? [];
|
|
1095
|
+
const operations = [{ operation: spec.operation, arguments: args }, ...followups];
|
|
1096
|
+
const invoke = async () => {
|
|
1097
|
+
const original = followups.length > 0 ? await readFile(spec.path) : undefined;
|
|
1098
|
+
let expectedHash = spec.hash;
|
|
1099
|
+
let result: InciseResult | undefined;
|
|
1100
|
+
for (let index = 0; index < operations.length; index += 1) {
|
|
1101
|
+
const operation = operations[index];
|
|
1102
|
+
const argv = [
|
|
1103
|
+
operation.operation, spec.path,
|
|
1104
|
+
"--args", JSON.stringify(operation.arguments),
|
|
1105
|
+
];
|
|
1106
|
+
if (expectedHash) argv.push("--if-match", expectedHash);
|
|
1107
|
+
result = await runIncise(pi.exec.bind(pi), binary.path, argv, signal);
|
|
1108
|
+
if (result.code !== 0 || result.payload.ok === false) {
|
|
1109
|
+
if (original && index > 0) await writeFile(spec.path, original);
|
|
1110
|
+
return result;
|
|
1111
|
+
}
|
|
1112
|
+
expectedHash = typeof result.payload.hash === "string"
|
|
1113
|
+
? result.payload.hash : undefined;
|
|
1114
|
+
}
|
|
1115
|
+
if (!result) throw new Error("Routed Incise request had no operations.");
|
|
1116
|
+
return result;
|
|
1117
|
+
};
|
|
759
1118
|
const result = spec.write
|
|
760
1119
|
? await withFileMutationQueue(spec.path, invoke)
|
|
761
1120
|
: await invoke();
|
|
@@ -771,7 +1130,9 @@ export function installSafeRoutedProfile(
|
|
|
771
1130
|
changed: Boolean(result.payload.changed),
|
|
772
1131
|
rows: result.payload.rows,
|
|
773
1132
|
route: spec.kind,
|
|
774
|
-
resolvedArguments:
|
|
1133
|
+
resolvedArguments: spec.resolvedArguments?.(
|
|
1134
|
+
params as Record<string, unknown>,
|
|
1135
|
+
) ?? args,
|
|
775
1136
|
validated: true,
|
|
776
1137
|
},
|
|
777
1138
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-incise",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Semantic, byte-preserving Markdown editing tools for Pi and AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"typescript": "^5.9.3"
|
|
47
47
|
},
|
|
48
48
|
"optionalDependencies": {
|
|
49
|
-
"@pdalinis/pi-incise-darwin-arm64": "0.
|
|
50
|
-
"@pdalinis/pi-incise-darwin-x64": "0.
|
|
51
|
-
"@pdalinis/pi-incise-linux-arm64-gnu": "0.
|
|
52
|
-
"@pdalinis/pi-incise-linux-x64-gnu": "0.
|
|
49
|
+
"@pdalinis/pi-incise-darwin-arm64": "0.3.0",
|
|
50
|
+
"@pdalinis/pi-incise-darwin-x64": "0.3.0",
|
|
51
|
+
"@pdalinis/pi-incise-linux-arm64-gnu": "0.3.0",
|
|
52
|
+
"@pdalinis/pi-incise-linux-x64-gnu": "0.3.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"test": "node --test --experimental-strip-types test/*.test.ts",
|