@juicesharp/rpiv-pi 2.8.0 → 2.10.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/extensions/rpiv-core/agent-enablement.ts +164 -0
- package/extensions/rpiv-core/agents.ts +98 -12
- package/extensions/rpiv-core/artifact-collector.ts +30 -7
- package/extensions/rpiv-core/built-in-workflows.ts +370 -96
- package/extensions/rpiv-core/built-ins/citations.ts +9 -0
- package/extensions/rpiv-core/built-ins/design.ts +64 -0
- package/extensions/rpiv-core/built-ins/elaboration.ts +53 -0
- package/extensions/rpiv-core/built-ins/gates.ts +282 -12
- package/extensions/rpiv-core/built-ins/grade-panel.ts +54 -26
- package/extensions/rpiv-core/built-ins/index.ts +20 -1
- package/extensions/rpiv-core/built-ins/markdown-fence.ts +26 -1
- package/extensions/rpiv-core/built-ins/plan-phases.ts +8 -0
- package/extensions/rpiv-core/built-ins/priors.ts +9 -2
- package/extensions/rpiv-core/built-ins/reconcile-directives.d.mts +29 -0
- package/extensions/rpiv-core/built-ins/reconcile-directives.mjs +338 -0
- package/extensions/rpiv-core/built-ins/reconcile.ts +88 -130
- package/extensions/rpiv-core/built-ins/remediation.ts +60 -7
- package/extensions/rpiv-core/built-ins/scope-checks.ts +74 -11
- package/extensions/rpiv-core/built-ins/shared.ts +5 -3
- package/extensions/rpiv-core/built-ins/slice-checks.ts +164 -28
- package/extensions/rpiv-core/built-ins/slices.ts +44 -13
- package/extensions/rpiv-core/built-ins/verdict-collector.ts +207 -0
- package/extensions/rpiv-core/built-ins/verdict-outcome.ts +36 -0
- package/extensions/rpiv-core/frontmatter.ts +22 -0
- package/extensions/rpiv-core/lane-list.ts +10 -1
- package/extensions/rpiv-core/lane-progress.ts +1 -1
- package/extensions/rpiv-core/lane-usage.ts +1 -1
- package/extensions/rpiv-core/models-config.ts +86 -6
- package/extensions/rpiv-core/models-picker.ts +4 -3
- package/extensions/rpiv-core/package-checks.ts +13 -0
- package/extensions/rpiv-core/run-lane-registry.ts +1 -2
- package/extensions/rpiv-core/sdk-workflow-host.ts +20 -4
- package/extensions/rpiv-core/session-hooks.ts +1 -1
- package/extensions/rpiv-core/workflow-execution-host.ts +3 -2
- package/package.json +4 -3
- package/skills/_shared/reconcile-lint.mjs +125 -0
- package/skills/_shared/stitch-elaborations.mjs +282 -21
- package/skills/acceptance/SKILL.md +3 -2
- package/skills/amend/SKILL.md +5 -5
- package/skills/design-slice/SKILL.md +5 -0
- package/skills/elaborate/SKILL.md +13 -6
- package/skills/grade/SKILL.md +15 -12
- package/skills/implement/SKILL.md +17 -2
- package/skills/research/SKILL.md +1 -1
- package/skills/slice/SKILL.md +2 -2
- package/skills/synthesize/SKILL.md +1 -1
- package/skills/validate/SKILL.md +14 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent enablement — declarative knowledge of which bundled agents gain
|
|
3
|
+
* sibling-provided `ext:` tools when the providing sibling is installed,
|
|
4
|
+
* plus the pure gate/merge primitives that drive the conditional
|
|
5
|
+
* frontmatter injection in agents.ts.
|
|
6
|
+
*
|
|
7
|
+
* Pure utility: no ExtensionAPI, no filesystem reads, never throws. The
|
|
8
|
+
* enablement map names sibling extensions and tool selectors as plain
|
|
9
|
+
* strings — presence detection stays in package-checks.ts (the SIBLINGS
|
|
10
|
+
* registry is the single detection source; zero runtime imports of
|
|
11
|
+
* sibling packages).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** What an agent gains when its enablement is active. */
|
|
15
|
+
export interface AgentEnablement {
|
|
16
|
+
/** Sibling extension names the agent must be allowed to load. */
|
|
17
|
+
readonly extensions: readonly string[];
|
|
18
|
+
/** Tool selectors appended to the agent's `tools` frontmatter. */
|
|
19
|
+
readonly tools: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Configurable per-agent override fields — a structural subset of the
|
|
24
|
+
* resolved models.json agent entry, kept local so this module stays
|
|
25
|
+
* dependency-free.
|
|
26
|
+
*/
|
|
27
|
+
export interface AgentEnablementOverride {
|
|
28
|
+
readonly extensions?: readonly string[];
|
|
29
|
+
readonly tools?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Bundled-agent tool/extension grants, keyed by agent basename (sans .md).
|
|
34
|
+
* A grant activates only while every named sibling is installed (the
|
|
35
|
+
* install gate) — tool selectors byte-match the granting sibling's
|
|
36
|
+
* registered tool names and its registry `provides` line.
|
|
37
|
+
*
|
|
38
|
+
* Currently EMPTY: the machinery ships dormant. The rpiv-lsp experiment
|
|
39
|
+
* (preserved on the backup/lsp-experiment branch) is the reference
|
|
40
|
+
* implementation for populating it when a sibling next ships agent-facing
|
|
41
|
+
* tools; per-agent grants also remain fully reachable through models.json
|
|
42
|
+
* `agents.<name>.tools/extensions` config with no map entry at all.
|
|
43
|
+
*/
|
|
44
|
+
export const AGENT_ENABLEMENT_GRANTS: Readonly<Record<string, AgentEnablement>> = {};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Resolve the effective enablement for one agent, or undefined when
|
|
48
|
+
* inactive. Configured arrays replace the map's field wholesale (an
|
|
49
|
+
* explicit `[]` suppresses that field). Inactive when there is no
|
|
50
|
+
* effective content, when no installed-extensions set was supplied (gate
|
|
51
|
+
* closed), or when any named provider — the extensions list plus the
|
|
52
|
+
* sibling prefix of each `ext:` tool selector — is not installed.
|
|
53
|
+
* `grants` is injectable for tests; production call sites use the module
|
|
54
|
+
* map default.
|
|
55
|
+
*/
|
|
56
|
+
export function resolveAgentEnablement(
|
|
57
|
+
agentKey: string,
|
|
58
|
+
config: AgentEnablementOverride | undefined,
|
|
59
|
+
installedExtensions: ReadonlySet<string> | undefined,
|
|
60
|
+
grants: Readonly<Record<string, AgentEnablement>> = AGENT_ENABLEMENT_GRANTS,
|
|
61
|
+
): AgentEnablement | undefined {
|
|
62
|
+
const base = grants[agentKey];
|
|
63
|
+
const extensions = config?.extensions !== undefined ? config.extensions : (base?.extensions ?? []);
|
|
64
|
+
const tools = config?.tools !== undefined ? config.tools : (base?.tools ?? []);
|
|
65
|
+
if (extensions.length === 0 && tools.length === 0) return undefined;
|
|
66
|
+
if (installedExtensions === undefined) return undefined;
|
|
67
|
+
for (const name of extensions) {
|
|
68
|
+
if (!installedExtensions.has(name)) return undefined;
|
|
69
|
+
}
|
|
70
|
+
for (const selector of tools) {
|
|
71
|
+
if (!selector.startsWith("ext:")) continue;
|
|
72
|
+
const provider = selector.slice("ext:".length).split("/")[0];
|
|
73
|
+
if (provider !== "" && !installedExtensions.has(provider)) return undefined;
|
|
74
|
+
}
|
|
75
|
+
return { extensions, tools };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Split a comma-separated scalar into trimmed, non-empty items. */
|
|
79
|
+
function csvItems(value: string): string[] {
|
|
80
|
+
return value
|
|
81
|
+
.split(",")
|
|
82
|
+
.map((item) => item.trim())
|
|
83
|
+
.filter((item) => item !== "");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Trim additions the same way existing items are parsed. */
|
|
87
|
+
function trimmedAdditions(additions: readonly string[]): string[] {
|
|
88
|
+
return additions.map((item) => item.trim()).filter((item) => item !== "");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Boolean/null-like scalars — merging into them would silently flip semantics. */
|
|
92
|
+
function isSentinelScalar(value: string): boolean {
|
|
93
|
+
const lowered = value.toLowerCase();
|
|
94
|
+
return lowered === "true" || lowered === "false" || lowered === "none";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Deduplicate preserving first-occurrence order. */
|
|
98
|
+
function dedupePreservingOrder(items: readonly string[]): string[] {
|
|
99
|
+
return [...new Set(items)];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Merge `additions` into an existing CSV scalar (the `tools:` form).
|
|
104
|
+
* Parses the existing value as a comma-separated list (a bare scalar is a
|
|
105
|
+
* one-item list), dedupes preserving first-occurrence order, appends absent
|
|
106
|
+
* additions in given order, and joins with `", "`. An `undefined` existing
|
|
107
|
+
* value yields the additions alone. Boolean-ish sentinels (`true`/`false`/
|
|
108
|
+
* `none`), empty scalars (a block-sequence head), and flow-sequence forms
|
|
109
|
+
* return undefined — the caller skips the key (fail-soft, nothing emitted).
|
|
110
|
+
*/
|
|
111
|
+
export function mergeCsvAdditions(existing: string | undefined, additions: readonly string[]): string | undefined {
|
|
112
|
+
if (existing === undefined) {
|
|
113
|
+
const adds = trimmedAdditions(additions);
|
|
114
|
+
return adds.length > 0 ? adds.join(", ") : undefined;
|
|
115
|
+
}
|
|
116
|
+
const trimmed = existing.trim();
|
|
117
|
+
if (trimmed === "" || isSentinelScalar(trimmed)) return undefined;
|
|
118
|
+
if (trimmed.startsWith("[")) return undefined;
|
|
119
|
+
const items = dedupePreservingOrder([...csvItems(trimmed), ...trimmedAdditions(additions)]);
|
|
120
|
+
return items.length > 0 ? items.join(", ") : undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Merge `additions` into an existing YAML flow sequence (the `extensions:`
|
|
125
|
+
* form). Accepts `[a, b]` or a bare scalar as the base, dedupes preserving
|
|
126
|
+
* first-occurrence order, appends absent additions, and renders `[a, b]`.
|
|
127
|
+
* An `undefined` existing value yields the additions alone. Sentinels,
|
|
128
|
+
* empty scalars, CSV forms, and unclosed brackets return undefined — the
|
|
129
|
+
* caller skips the key.
|
|
130
|
+
*/
|
|
131
|
+
export function mergeFlowSeqAdditions(existing: string | undefined, additions: readonly string[]): string | undefined {
|
|
132
|
+
if (existing === undefined) {
|
|
133
|
+
const adds = trimmedAdditions(additions);
|
|
134
|
+
return adds.length > 0 ? `[${adds.join(", ")}]` : undefined;
|
|
135
|
+
}
|
|
136
|
+
const trimmed = existing.trim();
|
|
137
|
+
if (trimmed === "" || isSentinelScalar(trimmed)) return undefined;
|
|
138
|
+
let inner: string;
|
|
139
|
+
if (trimmed.startsWith("[")) {
|
|
140
|
+
if (!trimmed.endsWith("]")) return undefined;
|
|
141
|
+
inner = trimmed.slice(1, -1);
|
|
142
|
+
} else {
|
|
143
|
+
if (trimmed.includes(",")) return undefined;
|
|
144
|
+
inner = trimmed;
|
|
145
|
+
}
|
|
146
|
+
const items = dedupePreservingOrder([...csvItems(inner), ...trimmedAdditions(additions)]);
|
|
147
|
+
return items.length > 0 ? `[${items.join(", ")}]` : undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Derive installed extension names from package spec strings:
|
|
152
|
+
* `npm:@juicesharp/rpiv-warp` → `rpiv-warp` — the last path segment after
|
|
153
|
+
* any protocol prefix, lowercased (the directory ↔ npm ↔ extension-name
|
|
154
|
+
* family convention). Non-string entries are the caller's to filter.
|
|
155
|
+
*/
|
|
156
|
+
export function installedExtensionNames(pkgs: readonly string[]): ReadonlySet<string> {
|
|
157
|
+
const names = new Set<string>();
|
|
158
|
+
for (const entry of pkgs) {
|
|
159
|
+
const noProto = entry.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:/, "");
|
|
160
|
+
const base = noProto.split("/").filter(Boolean).pop();
|
|
161
|
+
if (base !== undefined) names.add(base.toLowerCase());
|
|
162
|
+
}
|
|
163
|
+
return names;
|
|
164
|
+
}
|
|
@@ -27,8 +27,15 @@ import {
|
|
|
27
27
|
} from "node:fs";
|
|
28
28
|
import { isAbsolute, join, resolve, sep } from "node:path";
|
|
29
29
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
installedExtensionNames,
|
|
32
|
+
mergeCsvAdditions,
|
|
33
|
+
mergeFlowSeqAdditions,
|
|
34
|
+
resolveAgentEnablement,
|
|
35
|
+
} from "./agent-enablement.js";
|
|
36
|
+
import { parseFrontmatterBounds, readFrontmatterKey } from "./frontmatter.js";
|
|
31
37
|
import { getAgentModelConfig, loadModelsConfig, type ModelsConfig } from "./models-config.js";
|
|
38
|
+
import { findInstalledSiblings } from "./package-checks.js";
|
|
32
39
|
import { BUNDLED_AGENTS_DIR } from "./paths.js";
|
|
33
40
|
import { isPlainObject, toErrorMessage } from "./utils.js";
|
|
34
41
|
|
|
@@ -324,23 +331,48 @@ function applyKeyUpdates(
|
|
|
324
331
|
}
|
|
325
332
|
|
|
326
333
|
/**
|
|
327
|
-
*
|
|
334
|
+
* Install-gate context for conditional frontmatter injection.
|
|
335
|
+
*
|
|
336
|
+
* `installedExtensions` is the set of installed sibling extension names,
|
|
337
|
+
* derived from ONE settings read per sync pass. An absent context closes
|
|
338
|
+
* the enablement gate entirely — today's model/thinking-only behavior,
|
|
339
|
+
* byte-for-byte.
|
|
340
|
+
*/
|
|
341
|
+
export interface AgentInjectionContext {
|
|
342
|
+
readonly installedExtensions: ReadonlySet<string>;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Inject model/thinking + conditional enablement frontmatter into agent .md content.
|
|
328
347
|
*
|
|
329
|
-
* Idempotent: re-injecting produces identical bytes
|
|
330
|
-
* the closing `---` of the YAML frontmatter
|
|
331
|
-
*
|
|
348
|
+
* Idempotent: re-injecting produces identical bytes, with the gate open or
|
|
349
|
+
* closed. The function finds the closing `---` of the YAML frontmatter
|
|
350
|
+
* block and deterministically inserts or replaces keys.
|
|
332
351
|
*
|
|
333
|
-
*
|
|
352
|
+
* Enablement (fourth arg): when the context names every sibling provider an
|
|
353
|
+
* agent's enablement requires as installed, the agent additionally gains
|
|
354
|
+
* the merged `tools` CSV, an `extensions: [...]` flow sequence, and — only
|
|
355
|
+
* when the shipped file carries `isolated: true` — the `isolated: false` +
|
|
356
|
+
* `skills: false` pair. No override and no active enablement ⇒ content
|
|
357
|
+
* unchanged.
|
|
334
358
|
*
|
|
335
359
|
* Exported so the idempotency invariant can be unit-tested directly:
|
|
336
360
|
* `inject(inject(x)) === inject(x)` (see Verification Notes).
|
|
337
361
|
*/
|
|
338
|
-
export function injectModelFrontmatter(
|
|
362
|
+
export function injectModelFrontmatter(
|
|
363
|
+
content: string,
|
|
364
|
+
agentFile: string,
|
|
365
|
+
config: ModelsConfig,
|
|
366
|
+
injection?: AgentInjectionContext,
|
|
367
|
+
): string {
|
|
339
368
|
// Strip .md extension — source entries are filenames like "codebase-analyzer.md"
|
|
340
369
|
// but models.json keys are agent names like "codebase-analyzer".
|
|
341
370
|
const agentKey = agentFile.replace(/\.md$/, "");
|
|
342
371
|
const override = getAgentModelConfig(config, agentKey);
|
|
343
|
-
|
|
372
|
+
const enablement = resolveAgentEnablement(agentKey, override, injection?.installedExtensions);
|
|
373
|
+
// Tools-only entries must not be skipped: enablement alone proceeds.
|
|
374
|
+
const hasModelKeys = override?.model !== undefined || override?.thinking !== undefined;
|
|
375
|
+
if (!hasModelKeys && enablement === undefined) {
|
|
344
376
|
return content;
|
|
345
377
|
}
|
|
346
378
|
|
|
@@ -354,8 +386,43 @@ export function injectModelFrontmatter(content: string, agentFile: string, confi
|
|
|
354
386
|
// — re-injecting produces identical bytes by construction; the idempotency
|
|
355
387
|
// invariant at injectModelFrontmatter's JSDoc strengthens from "deterministic
|
|
356
388
|
// translation" to "byte pass-through".
|
|
357
|
-
if (override
|
|
358
|
-
if (override
|
|
389
|
+
if (override?.model !== undefined) keysToSet.push({ key: "model", value: override.model });
|
|
390
|
+
if (override?.thinking !== undefined) keysToSet.push({ key: "thinking", value: override.thinking });
|
|
391
|
+
|
|
392
|
+
if (enablement !== undefined) {
|
|
393
|
+
// Fixed order [model?, thinking?, tools, extensions, isolated?, skills?]:
|
|
394
|
+
// in-place replacements keep their shipped position; absent keys append
|
|
395
|
+
// before the closing fence in this order.
|
|
396
|
+
const mergedTools = mergeCsvAdditions(readFrontmatterKey(lines, bounds, "tools"), enablement.tools);
|
|
397
|
+
const mergedExtensions = mergeFlowSeqAdditions(
|
|
398
|
+
readFrontmatterKey(lines, bounds, "extensions"),
|
|
399
|
+
enablement.extensions,
|
|
400
|
+
);
|
|
401
|
+
// ATOMIC transform (review 2026-08-31 I2): a merge that fail-soft-skips
|
|
402
|
+
// an unmergeable frontmatter form (block-sequence, sentinel) while its
|
|
403
|
+
// additions are non-empty means the grant CANNOT land — applying the
|
|
404
|
+
// remaining keys anyway would flip `isolated`/`skills` off while
|
|
405
|
+
// granting nothing, silently un-scoping the agent on every sync. Skip
|
|
406
|
+
// the whole enablement key set and warn loudly instead.
|
|
407
|
+
const toolsMergeFailed = enablement.tools.length > 0 && mergedTools === undefined;
|
|
408
|
+
const extensionsMergeFailed = enablement.extensions.length > 0 && mergedExtensions === undefined;
|
|
409
|
+
if (toolsMergeFailed || extensionsMergeFailed) {
|
|
410
|
+
console.warn(
|
|
411
|
+
`[rpiv-pi] agent enablement skipped for ${agentFile}: the ${toolsMergeFailed ? "tools" : "extensions"} frontmatter form is not mergeable (block sequence or sentinel value) — rewrite it as a ${toolsMergeFailed ? "single-line CSV scalar" : "flow sequence"} to receive the grant`,
|
|
412
|
+
);
|
|
413
|
+
} else {
|
|
414
|
+
if (mergedTools !== undefined) keysToSet.push({ key: "tools", value: mergedTools });
|
|
415
|
+
if (mergedExtensions !== undefined) keysToSet.push({ key: "extensions", value: mergedExtensions });
|
|
416
|
+
// Flipping isolation is the point of enablement (`ext:` selectors are
|
|
417
|
+
// dropped while isolated) — but derive the pair only when the source
|
|
418
|
+
// declares `isolated: true`: re-injecting an already-injected form pushes
|
|
419
|
+
// neither key (idempotency), and non-isolated agents stay untouched.
|
|
420
|
+
if (readFrontmatterKey(lines, bounds, "isolated")?.toLowerCase() === "true") {
|
|
421
|
+
keysToSet.push({ key: "isolated", value: "false" });
|
|
422
|
+
keysToSet.push({ key: "skills", value: "false" });
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
359
426
|
|
|
360
427
|
const updated = applyKeyUpdates(lines, bounds, keysToSet);
|
|
361
428
|
return updated.join("\n");
|
|
@@ -377,6 +444,14 @@ function processSourceEntries(
|
|
|
377
444
|
// Hoisted above the loop: loadModelsConfig() reads+parses JSON, so calling it
|
|
378
445
|
// per-entry would re-read the file once per agent (~15×) every session_start.
|
|
379
446
|
const config = loadModelsConfig();
|
|
447
|
+
// One settings read per sync pass for the enablement gate. The SAME
|
|
448
|
+
// context must flow into every injectModelFrontmatter call in this pass —
|
|
449
|
+
// the manifest records hash-after-transform, so a gate that flipped
|
|
450
|
+
// mid-pass would tear the recorded hashes and falsely flag agents
|
|
451
|
+
// diverged.
|
|
452
|
+
const injection: AgentInjectionContext = {
|
|
453
|
+
installedExtensions: installedExtensionNames(findInstalledSiblings().map((s) => s.pkg)),
|
|
454
|
+
};
|
|
380
455
|
|
|
381
456
|
for (const entry of sourceEntries) {
|
|
382
457
|
const src = join(BUNDLED_AGENTS_DIR, entry);
|
|
@@ -400,7 +475,7 @@ function processSourceEntries(
|
|
|
400
475
|
// manifest hash matches what actually lands on disk (hash-after-transform).
|
|
401
476
|
// injectModelFrontmatter strips .md from entry for config lookup and is a
|
|
402
477
|
// no-op when no override is configured.
|
|
403
|
-
const injected = injectModelFrontmatter(srcContent.toString("utf-8"), entry, config);
|
|
478
|
+
const injected = injectModelFrontmatter(srcContent.toString("utf-8"), entry, config, injection);
|
|
404
479
|
const srcHash = sha256(injected);
|
|
405
480
|
|
|
406
481
|
if (!existsSync(dest)) {
|
|
@@ -614,6 +689,12 @@ export function cleanupPerCwdAgents(cwd: string): CleanupResult {
|
|
|
614
689
|
// Hoisted config read (same reasoning as processSourceEntries): one JSON
|
|
615
690
|
// read for the whole cleanup pass, not one per managed file.
|
|
616
691
|
const cleanupConfig = loadModelsConfig();
|
|
692
|
+
// Same shared-gate rule as processSourceEntries: the legacy-dir comparison
|
|
693
|
+
// must use one settings read for the whole pass — the identical gate a
|
|
694
|
+
// sync pass with the same settings would have used.
|
|
695
|
+
const cleanupInjection: AgentInjectionContext = {
|
|
696
|
+
installedExtensions: installedExtensionNames(findInstalledSiblings().map((s) => s.pkg)),
|
|
697
|
+
};
|
|
617
698
|
for (const [name] of Object.entries(manifest)) {
|
|
618
699
|
const srcPath = safeJoin(BUNDLED_AGENTS_DIR, name);
|
|
619
700
|
const destPath = safeJoin(perCwdDir, name);
|
|
@@ -650,7 +731,12 @@ export function cleanupPerCwdAgents(cwd: string): CleanupResult {
|
|
|
650
731
|
// Compare against the injected form — the dest holds injected content,
|
|
651
732
|
// so comparing raw source would falsely flag every configured agent
|
|
652
733
|
// as diverged. injectModelFrontmatter strips .md from name for lookup.
|
|
653
|
-
const cleanupInjected = injectModelFrontmatter(
|
|
734
|
+
const cleanupInjected = injectModelFrontmatter(
|
|
735
|
+
srcContent.toString("utf-8"),
|
|
736
|
+
name,
|
|
737
|
+
cleanupConfig,
|
|
738
|
+
cleanupInjection,
|
|
739
|
+
);
|
|
654
740
|
if (sha256(destContent) !== sha256(cleanupInjected)) {
|
|
655
741
|
// User edited this file — conservative gate.
|
|
656
742
|
result.skipped.push({ dir: perCwdDir, reason: CLEANUP_SKIP_REASON.DIVERGED });
|
|
@@ -14,11 +14,14 @@
|
|
|
14
14
|
* (`research`, `plans`, etc.) — the collector halts the chain if the
|
|
15
15
|
* agent strayed.
|
|
16
16
|
*
|
|
17
|
-
* Both collectors carry
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* fallback
|
|
17
|
+
* Both collectors carry two fallbacks behind the spoken-text scan, tried in
|
|
18
|
+
* order: (1) the tool-argument surface — the `path` argument of a `write`/`edit`
|
|
19
|
+
* call (the recorded action, for an agent that wrote the file but never
|
|
20
|
+
* announced it; see the fallback-surface section below); (2) the
|
|
21
|
+
* disk-corroborated basename fallback — when both scans miss (agent mangled
|
|
22
|
+
* the directory prefix in prose), a bare `<file>.md` token from the transcript
|
|
23
|
+
* is accepted iff it resolves to exactly one existing file under
|
|
24
|
+
* `.rpiv/artifacts/` — see that section below.
|
|
22
25
|
*
|
|
23
26
|
* One parser: `frontmatterParser` parses YAML frontmatter from the
|
|
24
27
|
* primary fs artifact into `Record<string, unknown>` — what
|
|
@@ -144,9 +147,29 @@ function withDiskFallback(primary: ArtifactCollector, bucket?: string): Artifact
|
|
|
144
147
|
});
|
|
145
148
|
}
|
|
146
149
|
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
// Tool-argument fallback surface
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
//
|
|
154
|
+
// When the spoken announcement misses, the text-scan primitive consults the
|
|
155
|
+
// agent's recorded tool calls. That surface is narrowed HARD here, because a
|
|
156
|
+
// stage's transcript is full of other artifacts' paths in tool arguments: an
|
|
157
|
+
// elaborate lane `read`s sibling elaborations, a grader `bash`-greps the plan,
|
|
158
|
+
// `ls .rpiv/artifacts/<bucket>/` lists every neighbour. Only a FILE-WRITING
|
|
159
|
+
// tool proves the agent produced the path, and only its `path` argument names
|
|
160
|
+
// what it wrote — a `write` call's `content` may quote a sibling's path (a
|
|
161
|
+
// `source:` line, a cross-reference) and must never outrank the destination.
|
|
162
|
+
// Pi's file-writing tools are `write` (`{ path, content }`) and `edit`
|
|
163
|
+
// (`{ path, edits }`); `bash` heredoc writes are deliberately NOT accepted (a
|
|
164
|
+
// `command` string carries arbitrary paths) — for those the disk-corroborated
|
|
165
|
+
// basename fallback below still applies.
|
|
166
|
+
const FILE_WRITING_TOOLS: ReadonlySet<string> = new Set(["write", "edit"]);
|
|
167
|
+
const isFileWrite = (tc: { name: string }): boolean => FILE_WRITING_TOOLS.has(tc.name);
|
|
168
|
+
const TOOL_ARG_FALLBACK = { match: isFileWrite, argKeys: ["path"] as const };
|
|
169
|
+
|
|
147
170
|
/** Bucket-agnostic — accepts any `.rpiv/artifacts/<bucket>/...md`. */
|
|
148
171
|
export const rpivArtifactCollector: ArtifactCollector = withDiskFallback(
|
|
149
|
-
transcriptPathCollector({ pattern: RPIV_ARTIFACT_PATTERN }),
|
|
172
|
+
transcriptPathCollector({ pattern: RPIV_ARTIFACT_PATTERN, ...TOOL_ARG_FALLBACK }),
|
|
150
173
|
);
|
|
151
174
|
|
|
152
175
|
/** Bucket-narrowed — accepts only `.rpiv/artifacts/<bucket>/...md`. The filename
|
|
@@ -155,7 +178,7 @@ export const rpivArtifactCollector: ArtifactCollector = withDiskFallback(
|
|
|
155
178
|
export function rpivBucketCollector(bucket: string): ArtifactCollector {
|
|
156
179
|
const escaped = bucket.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
157
180
|
const pattern = new RegExp(String.raw`\.rpiv/artifacts/${escaped}/${TEMPERED_SEGMENT}\.md`, "g");
|
|
158
|
-
return withDiskFallback(transcriptPathCollector({ pattern }), bucket);
|
|
181
|
+
return withDiskFallback(transcriptPathCollector({ pattern, ...TOOL_ARG_FALLBACK }), bucket);
|
|
159
182
|
}
|
|
160
183
|
|
|
161
184
|
// ---------------------------------------------------------------------------
|