@juicesharp/rpiv-pi 1.20.0 → 2.0.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.
Files changed (95) hide show
  1. package/agents/integration-scanner.md +1 -1
  2. package/extensions/rpiv-core/agents.ts +4 -4
  3. package/extensions/rpiv-core/artifact-collector.ts +20 -3
  4. package/extensions/rpiv-core/bash-timeout.ts +110 -0
  5. package/extensions/rpiv-core/built-in-workflows.ts +1484 -81
  6. package/extensions/rpiv-core/constants.ts +1 -0
  7. package/extensions/rpiv-core/index.ts +50 -18
  8. package/extensions/rpiv-core/lane-console.ts +566 -0
  9. package/extensions/rpiv-core/lane-dock-editor.ts +184 -0
  10. package/extensions/rpiv-core/lane-dock.ts +197 -0
  11. package/extensions/rpiv-core/lane-failure.ts +28 -0
  12. package/extensions/rpiv-core/lane-list.ts +414 -0
  13. package/extensions/rpiv-core/lane-progress.ts +330 -0
  14. package/extensions/rpiv-core/lane-relay-ui.ts +101 -0
  15. package/extensions/rpiv-core/lane-streaming.ts +68 -0
  16. package/extensions/rpiv-core/lane-switcher.ts +176 -0
  17. package/extensions/rpiv-core/lane-tool-defs.ts +73 -0
  18. package/extensions/rpiv-core/lane-transcript-disk.ts +91 -0
  19. package/extensions/rpiv-core/lane-transcript-view.ts +172 -0
  20. package/extensions/rpiv-core/lane-transcript.ts +277 -0
  21. package/extensions/rpiv-core/lane-usage.ts +96 -0
  22. package/extensions/rpiv-core/models-config.ts +7 -7
  23. package/extensions/rpiv-core/outcome-derivation.ts +2 -0
  24. package/extensions/rpiv-core/pipeline-pointer.ts +47 -0
  25. package/extensions/rpiv-core/question-lifecycle.ts +157 -0
  26. package/extensions/rpiv-core/register-built-in-workflows.ts +2 -2
  27. package/extensions/rpiv-core/rpiv-models/command.ts +3 -3
  28. package/extensions/rpiv-core/rpiv-models/items.ts +3 -8
  29. package/extensions/rpiv-core/run-lane-registry.ts +839 -0
  30. package/extensions/rpiv-core/sdk-workflow-host.ts +481 -0
  31. package/extensions/rpiv-core/session-capture.ts +261 -0
  32. package/extensions/rpiv-core/session-hooks.ts +8 -66
  33. package/extensions/rpiv-core/skill-bracket.ts +9 -19
  34. package/extensions/rpiv-core/workflow-execution-host.ts +184 -0
  35. package/extensions/rpiv-core/workflow-question-warp-bridge.ts +161 -0
  36. package/package.json +7 -5
  37. package/skills/_shared/git-changes.mjs +52 -1
  38. package/skills/_shared/slice-overlap.mjs +6 -8
  39. package/skills/_shared/stitch-elaborations.mjs +160 -0
  40. package/skills/amend/SKILL.md +48 -0
  41. package/skills/architecture-review/SKILL.md +2 -1
  42. package/skills/architecture-review/templates/architecture-review.md +1 -1
  43. package/skills/blueprint/SKILL.md +2 -1
  44. package/skills/code-review/SKILL.md +47 -17
  45. package/skills/code-review/_helpers/review-range.mjs +160 -3
  46. package/skills/commit/SKILL.md +12 -4
  47. package/skills/design/SKILL.md +2 -1
  48. package/skills/design-review/SKILL.md +77 -0
  49. package/skills/design-slice/SKILL.md +114 -0
  50. package/skills/discover/SKILL.md +1 -0
  51. package/skills/elaborate/SKILL.md +112 -0
  52. package/skills/explore/SKILL.md +1 -0
  53. package/skills/frontend-design/SKILL.md +1 -0
  54. package/skills/grade/SKILL.md +142 -0
  55. package/skills/implement/SKILL.md +16 -8
  56. package/skills/plan/SKILL.md +1 -0
  57. package/skills/pr-triage/SKILL.md +6 -3
  58. package/skills/research/SKILL.md +3 -1
  59. package/skills/revise/SKILL.md +1 -0
  60. package/skills/slice/SKILL.md +160 -0
  61. package/skills/synthesize/SKILL.md +165 -0
  62. package/skills/validate/SKILL.md +28 -5
  63. package/extensions/rpiv-core/agents.test.ts +0 -782
  64. package/extensions/rpiv-core/banner.test.ts +0 -27
  65. package/extensions/rpiv-core/built-in-workflows.test.ts +0 -1301
  66. package/extensions/rpiv-core/constants.test.ts +0 -14
  67. package/extensions/rpiv-core/frontmatter.test.ts +0 -51
  68. package/extensions/rpiv-core/git-context.matcher.test.ts +0 -47
  69. package/extensions/rpiv-core/git-context.test.ts +0 -109
  70. package/extensions/rpiv-core/guidance.test.ts +0 -140
  71. package/extensions/rpiv-core/model-override.test.ts +0 -637
  72. package/extensions/rpiv-core/model-override.ts +0 -356
  73. package/extensions/rpiv-core/models-config-validate.test.ts +0 -131
  74. package/extensions/rpiv-core/models-config.test.ts +0 -461
  75. package/extensions/rpiv-core/models-picker.test.ts +0 -136
  76. package/extensions/rpiv-core/outcome-derivation.test.ts +0 -550
  77. package/extensions/rpiv-core/package-checks.test.ts +0 -68
  78. package/extensions/rpiv-core/paths.test.ts +0 -58
  79. package/extensions/rpiv-core/pi-installer.test.ts +0 -100
  80. package/extensions/rpiv-core/prune-legacy-siblings.test.ts +0 -183
  81. package/extensions/rpiv-core/register-built-in-workflows.test.ts +0 -69
  82. package/extensions/rpiv-core/rpiv-models/units.test.ts +0 -136
  83. package/extensions/rpiv-core/rpiv-models-command.test.ts +0 -797
  84. package/extensions/rpiv-core/session-hooks.test.ts +0 -645
  85. package/extensions/rpiv-core/setup-command.test.ts +0 -213
  86. package/extensions/rpiv-core/sibling-import-graph.test.ts +0 -115
  87. package/extensions/rpiv-core/siblings.test.ts +0 -96
  88. package/extensions/rpiv-core/skill-bracket.test.ts +0 -251
  89. package/extensions/rpiv-core/skill-contracts-source.test.ts +0 -660
  90. package/extensions/rpiv-core/update-agents-command.test.ts +0 -106
  91. package/extensions/rpiv-core/utils.test.ts +0 -214
  92. package/skills/_shared/git-changes.test.ts +0 -107
  93. package/skills/_shared/git-context.test.ts +0 -90
  94. package/skills/_shared/list-recent.test.ts +0 -77
  95. package/skills/_shared/now.test.ts +0 -48
@@ -50,7 +50,7 @@ You are a specialist at finding CONNECTIONS to and from a component or area. You
50
50
 
51
51
  ## Output Format
52
52
 
53
- CRITICAL: Use EXACTLY this format. Never use markdown tables. Use relative paths (strip the workspace root prefix).
53
+ CRITICAL: Use EXACTLY this format. Never use markdown tables. Use repo-root-relative paths — strip only the absolute prefix up to the repository root, never a package or subdirectory prefix (`packages/billing/src/invoice.ts:42`, not `src/invoice.ts:42`).
54
54
 
55
55
  ```
56
56
  ## Connections: {Component}
@@ -349,7 +349,7 @@ export function injectModelFrontmatter(content: string, agentFile: string, confi
349
349
  if (!bounds) return content;
350
350
 
351
351
  const keysToSet: { key: string; value: string }[] = [];
352
- // D9 (post-slash-canonical migration): models.json values are byte-equal to
352
+ // (post-slash-canonical migration): models.json values are byte-equal to
353
353
  // the agent frontmatter form (both `provider/modelId`). No translation step
354
354
  // — re-injecting produces identical bytes by construction; the idempotency
355
355
  // invariant at injectModelFrontmatter's JSDoc strengthens from "deterministic
@@ -397,7 +397,7 @@ function processSourceEntries(
397
397
  continue;
398
398
  }
399
399
  // Inject configured model/thinking frontmatter BEFORE hashing so the
400
- // manifest hash matches what actually lands on disk (D4: hash-after-transform).
400
+ // manifest hash matches what actually lands on disk (hash-after-transform).
401
401
  // injectModelFrontmatter strips .md from entry for config lookup and is a
402
402
  // no-op when no override is configured.
403
403
  const injected = injectModelFrontmatter(srcContent.toString("utf-8"), entry, config);
@@ -650,8 +650,8 @@ export function cleanupPerCwdAgents(cwd: string): CleanupResult {
650
650
  return result;
651
651
  }
652
652
 
653
- // Compare against the injected form — the dest holds injected content
654
- // (D4), so comparing raw source would falsely flag every configured agent
653
+ // Compare against the injected form — the dest holds injected content,
654
+ // so comparing raw source would falsely flag every configured agent
655
655
  // as diverged. injectModelFrontmatter strips .md from name for lookup.
656
656
  const cleanupInjected = injectModelFrontmatter(srcContent.toString("utf-8"), name, cleanupConfig);
657
657
  if (sha256(destContent) !== sha256(cleanupInjected)) {
@@ -59,8 +59,18 @@ export function rpivBucketCollector(bucket: string): ArtifactCollector {
59
59
 
60
60
  /**
61
61
  * Reads YAML frontmatter from the primary fs artifact. Files without
62
- * frontmatter produce `data: {}`. Fatals when the announced path
63
- * doesn't exist on disk (the agent claimed to write but didn't).
62
+ * frontmatter — or with frontmatter the YAML parser chokes on — produce
63
+ * `data: {}`. Fatals only when the announced path doesn't exist on disk
64
+ * (the agent claimed to write but didn't).
65
+ *
66
+ * Fail-soft on malformed YAML is deliberate: `parseFrontmatter` throws on
67
+ * an agent-authored scalar that smuggles in a bare `: ` (e.g.
68
+ * `target: foo (lane UI: L0–L2)` reads as a nested mapping). Letting that
69
+ * throw escape converts a single stray colon — in the LAST write of a
70
+ * multi-hour stage — into a fatal that halts the whole workflow. Degrading
71
+ * to `{}` keeps the artifact (the real work) and defers any missing-field
72
+ * judgement to the stage's `outputSchema` validation, exactly as a file
73
+ * with no frontmatter at all already does.
64
74
  */
65
75
  export const frontmatterParser: ArtifactParser<undefined, "artifact-md", Record<string, unknown>> = defineParser({
66
76
  parse(ctx: ParseCtx<undefined>) {
@@ -79,7 +89,14 @@ export const frontmatterParser: ArtifactParser<undefined, "artifact-md", Record<
79
89
  };
80
90
  }
81
91
  const content = readFileSync(abs, "utf-8");
82
- const { frontmatter } = parseFrontmatter(content);
92
+ let frontmatter: unknown;
93
+ try {
94
+ ({ frontmatter } = parseFrontmatter(content));
95
+ } catch {
96
+ // Malformed YAML (unquoted `: ` in a scalar, bad indentation, …) →
97
+ // degrade to no-frontmatter rather than killing the chain.
98
+ frontmatter = undefined;
99
+ }
83
100
  return {
84
101
  kind: "ok",
85
102
  payload: {
@@ -0,0 +1,110 @@
1
+ /**
2
+ * bash-timeout — a per-command wall-clock watchdog over a child AgentSession's bash
3
+ * tool calls, the host's defense against a runaway command stranding a fan-out gate.
4
+ *
5
+ * A workflow stage runs in a detached child session (sdk-workflow-host); the SDK's
6
+ * bash tool honours an AbortSignal but enforces NO timeout of its own, so a model that
7
+ * issues e.g. `find / ...` blocks the unit for as long as the scan runs. A fan-out
8
+ * gate finalizes only once EVERY unit settles, so one wedged bash freezes the whole
9
+ * run with nothing to break it.
10
+ *
11
+ * `armBashWatchdog` subscribes to the child's `tool_execution_start`/`_end` stream and,
12
+ * per bash call, arms a timer; the matching result disarms it. On expiry it records the
13
+ * reason and `session.abort()`s — which signals the in-flight subprocess AND resolves
14
+ * the turn with `stopReason:"aborted"`. The host exposes the recorded reason to the
15
+ * runner via `WorkflowSessionContext.toolTimeout`, where `postStage` routes it to the
16
+ * soft-halt gate (collect-all unit survives; non-fan-out stage fails terminally) rather
17
+ * than re-dispatching the same command on resume.
18
+ *
19
+ * Per-command, not per-unit: the clock is the time a SINGLE bash call has been running,
20
+ * so a stage may issue many quick commands without ever tripping it; only one that
21
+ * overruns on its own does.
22
+ */
23
+
24
+ import type { AgentSession } from "@earendil-works/pi-coding-agent";
25
+
26
+ /** The event the session's subscribe listener receives — derived from the SDK signature
27
+ * so this module imports no SDK event-type value (mirrors lane-streaming.ts). */
28
+ type AgentSessionEvent = Parameters<Parameters<AgentSession["subscribe"]>[0]>[0];
29
+
30
+ /** Only the slice of AgentSession the watchdog touches — keeps the unit test trivial to fake. */
31
+ type WatchableSession = Pick<AgentSession, "subscribe" | "abort">;
32
+
33
+ const DEFAULT_BASH_TOOL_TIMEOUT_MS = 180_000; // 3 min — tight enough to cut a wedged scan well before it strands a gate.
34
+ const MIN_BASH_TOOL_TIMEOUT_MS = 5_000; // a sub-5s ceiling would scythe ordinary commands.
35
+ const MAX_BASH_TOOL_TIMEOUT_MS = 30 * 60_000; // 30 min — the hard upper bound (mirrors the workflow validation-retry cap).
36
+
37
+ /**
38
+ * The resolved per-command ceiling: the 3-minute default, overridable via
39
+ * `RPIV_BASH_TIMEOUT_MS` and clamped to [5s, 30min]. A non-numeric / non-positive
40
+ * override falls back to the default. Resolved once at module load (env is fixed for a
41
+ * process); tests pass an explicit `timeoutMs` to `armBashWatchdog` instead of mutating env.
42
+ */
43
+ export const BASH_TOOL_TIMEOUT_MS = resolveBashTimeoutMs(process.env.RPIV_BASH_TIMEOUT_MS);
44
+
45
+ export function resolveBashTimeoutMs(raw: string | undefined): number {
46
+ const parsed = Number(raw);
47
+ if (!Number.isFinite(parsed) || parsed <= 0) return DEFAULT_BASH_TOOL_TIMEOUT_MS;
48
+ return Math.min(Math.max(parsed, MIN_BASH_TOOL_TIMEOUT_MS), MAX_BASH_TOOL_TIMEOUT_MS);
49
+ }
50
+
51
+ /** Operator-grade row text — names the ceiling and echoes the offending command (truncated). */
52
+ export function bashTimeoutReason(command: string, timeoutMs: number): string {
53
+ const secs = Math.round(timeoutMs / 1000);
54
+ const snippet = command.length > 120 ? `${command.slice(0, 117)}...` : command;
55
+ return `bash command exceeded the ${secs}s per-command timeout and was aborted${snippet ? `: \`${snippet}\`` : ""}`;
56
+ }
57
+
58
+ export interface BashWatchdog {
59
+ /** The recorded timeout reason once the watchdog has fired, else `undefined`. Wired to
60
+ * `WorkflowSessionContext.toolTimeout` so the runner can divert the abort to soft-halt. */
61
+ timedOut(): { reason: string } | undefined;
62
+ /** Unsubscribe + clear any pending timers. The host calls this in its per-stage `finally`. */
63
+ dispose(): void;
64
+ }
65
+
66
+ /**
67
+ * Arm the watchdog on `session`. Returns a handle whose `timedOut()` reports the reason
68
+ * (once) and whose `dispose()` tears the subscription + timers down. The FIRST overrun
69
+ * wins — concurrent bash calls (parallel tool execution) each get their own timer, but
70
+ * only one abort + reason is recorded.
71
+ */
72
+ export function armBashWatchdog(session: WatchableSession, timeoutMs: number = BASH_TOOL_TIMEOUT_MS): BashWatchdog {
73
+ let fired: { reason: string } | undefined;
74
+ const timers = new Map<string, ReturnType<typeof setTimeout>>();
75
+
76
+ const clear = (id: string): void => {
77
+ const timer = timers.get(id);
78
+ if (timer) {
79
+ clearTimeout(timer);
80
+ timers.delete(id);
81
+ }
82
+ };
83
+
84
+ const unsubscribe = session.subscribe((event: AgentSessionEvent) => {
85
+ if (event.type === "tool_execution_start" && event.toolName === "bash") {
86
+ const id = event.toolCallId;
87
+ const command = typeof event.args?.command === "string" ? event.args.command : "";
88
+ const timer = setTimeout(() => {
89
+ timers.delete(id);
90
+ if (fired) return; // first overrun wins — one abort, one reason.
91
+ fired = { reason: bashTimeoutReason(command, timeoutMs) };
92
+ void session.abort();
93
+ }, timeoutMs);
94
+ // Don't let a pending watchdog keep the event loop alive on its own.
95
+ timer.unref?.();
96
+ timers.set(id, timer);
97
+ } else if (event.type === "tool_execution_end") {
98
+ clear(event.toolCallId);
99
+ }
100
+ });
101
+
102
+ return {
103
+ timedOut: () => fired,
104
+ dispose: () => {
105
+ unsubscribe();
106
+ for (const timer of timers.values()) clearTimeout(timer);
107
+ timers.clear();
108
+ },
109
+ };
110
+ }