@webpresso/agent-kit 3.3.1 → 3.3.2

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 (46) hide show
  1. package/catalog/agent/rules/pre-implementation.md +15 -8
  2. package/catalog/agent/skills/ultragoal/SKILL.md +5 -18
  3. package/dist/esm/blueprint/core/validation/task-blocks.js +7 -1
  4. package/dist/esm/blueprint/markdown/task-heading.d.ts +21 -0
  5. package/dist/esm/blueprint/markdown/task-heading.js +25 -0
  6. package/dist/esm/blueprint/trust/command-runner.d.ts +40 -0
  7. package/dist/esm/blueprint/trust/command-runner.js +265 -41
  8. package/dist/esm/build/cli-mcp-parity.js +5 -0
  9. package/dist/esm/ci/native-session-memory-cache.d.ts +2 -1
  10. package/dist/esm/ci/native-session-memory-cache.js +2 -1
  11. package/dist/esm/ci/release-progress.d.ts +37 -0
  12. package/dist/esm/ci/release-progress.js +139 -0
  13. package/dist/esm/cli/cli.d.ts +1 -1
  14. package/dist/esm/cli/cli.js +9 -0
  15. package/dist/esm/cli/commands/blueprint/mutations.js +2 -3
  16. package/dist/esm/cli/commands/release-progress.d.ts +53 -0
  17. package/dist/esm/cli/commands/release-progress.js +155 -0
  18. package/dist/esm/cli/commands/review.js +74 -11
  19. package/dist/esm/cli/utils.d.ts +8 -1
  20. package/dist/esm/cli/utils.js +12 -2
  21. package/dist/esm/hooks/pretool-guard/validators/plan-frontmatter.js +3 -2
  22. package/dist/esm/mcp/blueprint/handlers/document-mutations.js +2 -1
  23. package/dist/esm/mcp/blueprint/handlers/task-advance.js +2 -12
  24. package/dist/esm/review/delivery-verifier.d.ts +33 -2
  25. package/dist/esm/review/delivery-verifier.js +130 -24
  26. package/dist/esm/review/execution/review-checkout.d.ts +1 -0
  27. package/dist/esm/review/execution/review-checkout.js +386 -23
  28. package/dist/esm/review/execution/sandbox/adapter.d.ts +37 -0
  29. package/dist/esm/review/execution/sandbox/adapter.js +39 -0
  30. package/dist/esm/review/execution/sandbox/env.d.ts +12 -0
  31. package/dist/esm/review/execution/sandbox/env.js +37 -0
  32. package/dist/esm/review/execution/sandbox/index.d.ts +5 -0
  33. package/dist/esm/review/execution/sandbox/index.js +4 -0
  34. package/dist/esm/review/execution/sandbox/policy.d.ts +19 -0
  35. package/dist/esm/review/execution/sandbox/policy.js +95 -0
  36. package/dist/esm/review/execution/sandbox/probe.d.ts +20 -0
  37. package/dist/esm/review/execution/sandbox/probe.js +97 -0
  38. package/dist/esm/review/execution/sandbox/shell-quote.d.ts +14 -0
  39. package/dist/esm/review/execution/sandbox/shell-quote.js +18 -0
  40. package/dist/esm/review/execution/sandbox/tmpdir.d.ts +9 -0
  41. package/dist/esm/review/execution/sandbox/tmpdir.js +36 -0
  42. package/dist/esm/review/execution/sandbox/types.d.ts +31 -0
  43. package/dist/esm/review/execution/sandbox/types.js +6 -0
  44. package/dist/esm/review/execution/supervisor.js +44 -5
  45. package/dist/esm/review/execution/types.d.ts +2 -0
  46. package/package.json +13 -12
@@ -4,6 +4,7 @@ import { z } from "zod";
4
4
  import matter from "gray-matter";
5
5
  import { parseBlueprint } from "#core/parser";
6
6
  import { taskIdSchema } from "#core/schema";
7
+ import { formatTaskHeading } from "#markdown/task-heading";
7
8
  import { evaluateApprovalGate, formatApprovalGateRequirement } from "#lifecycle/audit";
8
9
  import { canonicalizeBlueprint } from "#lifecycle/canonicalize.js";
9
10
  import { BlueprintCreationService } from "#service/BlueprintCreationService";
@@ -290,7 +291,7 @@ function renderBlueprintMarkdownFromDocument(slug, document) {
290
291
  "",
291
292
  ];
292
293
  const taskBlocks = document.tasks.flatMap((task) => [
293
- `#### Task ${task.id}: ${task.title}`,
294
+ formatTaskHeading(task.id, task.title),
294
295
  "",
295
296
  `**Status:** ${task.status}`,
296
297
  ...(task.wave ? [`**Wave:** ${task.wave}`] : []),
@@ -11,23 +11,13 @@ import { toStr } from "#mcp/blueprint/_shared/payload";
11
11
  import { findBlueprintDir, resolveToolProject } from "#mcp/blueprint/_shared/project";
12
12
  import { resolveSyncAdapter, runPlatformMutationSync } from "#mcp/blueprint/_shared/sync";
13
13
  import { writeFileAtomic } from "#shared-utils/write-json-file.js";
14
- import { escapeRegex } from "#utils/string";
14
+ import { buildTaskHeaderRegexForId } from "#markdown/task-heading";
15
15
  import { withMarkdownWriteLock } from "#db/paths.js";
16
16
  import { resolveBlueprintRoot } from "#utils/blueprint-root.js";
17
17
  const ALL_STATES = ["draft", "planned", "in-progress", "parked", "archived", "completed"];
18
- /**
19
- * Matches the canonical task-heading grammar `parser.ts`'s `extractTasks`
20
- * uses (`^####\s+(?:\[lane\]\s+)?Task\s+<id>:`), not a looser ad hoc pattern.
21
- * The id is anchored on a trailing colon so "1.1" cannot match "1.10", and
22
- * an optional `[lane]` prefix is accepted the same way the canonical parser
23
- * does.
24
- */
25
- function buildTaskHeadingPattern(taskId) {
26
- return new RegExp(`^####\\s+(?:\\[[^\\]]+\\]\\s+)?Task\\s+${escapeRegex(taskId)}:`, "u");
27
- }
28
18
  function findTaskStatusLine(markdown, taskId) {
29
19
  const lines = markdown.split("\n");
30
- const headingPattern = buildTaskHeadingPattern(taskId);
20
+ const headingPattern = buildTaskHeaderRegexForId(taskId);
31
21
  let inBlock = false;
32
22
  for (let i = 0; i < lines.length; i++) {
33
23
  const line = lines[i] ?? "";
@@ -1,5 +1,6 @@
1
- import { executeAllowedWpCommand } from "#trust/command-runner.js";
1
+ import { executeAllowedWpCommand, type AllowedWpCommandResult } from "#trust/command-runner.js";
2
2
  import type { ReviewTargetCheckout } from "#review/execution/review-checkout.js";
3
+ import type { SandboxAvailability } from "#review/execution/sandbox/types.js";
3
4
  export interface ReviewGateVerificationCommand {
4
5
  readonly command: string;
5
6
  readonly outcome: "passed" | "failed" | "timed-out" | "deferred";
@@ -7,12 +8,29 @@ export interface ReviewGateVerificationCommand {
7
8
  readonly exitCode: number | null;
8
9
  readonly signal?: string;
9
10
  }
11
+ /**
12
+ * How the gate commands were isolated. `srt` = OS-sandboxed; `disabled-by-operator`
13
+ * = an explicit `WP_REVIEW_UNSANDBOXED_GATES=1` override ran them unsandboxed;
14
+ * `unavailable` = no backend and no override, so no gate ran (fail-closed).
15
+ */
16
+ export type ReviewSandboxMode = "srt" | "disabled-by-operator" | "unavailable";
10
17
  export interface ReviewGateVerification {
11
18
  readonly status: "passed" | "failed";
12
19
  readonly commands: readonly ReviewGateVerificationCommand[];
13
20
  readonly failureCode?: string;
14
21
  readonly logPath?: string;
22
+ readonly sandbox?: ReviewSandboxMode;
23
+ readonly sandboxReason?: string;
15
24
  }
25
+ /** Runs one gate command in the review checkout and returns its raw result. */
26
+ export type RunSandboxedGate = (args: {
27
+ readonly command: string;
28
+ readonly executionRoot: string;
29
+ readonly logRoot: string;
30
+ readonly runTmpDir: string;
31
+ readonly projectRoot: string;
32
+ readonly signal?: AbortSignal;
33
+ }) => Promise<AllowedWpCommandResult>;
16
34
  export interface VerifyDeliveryGatesInput {
17
35
  readonly purpose: "plan" | "delivery";
18
36
  readonly blueprintContent: string;
@@ -20,8 +38,21 @@ export interface VerifyDeliveryGatesInput {
20
38
  readonly gateId: string;
21
39
  readonly checkout: ReviewTargetCheckout;
22
40
  readonly signal?: AbortSignal;
41
+ /** Legacy/override execution path (unsandboxed). */
23
42
  readonly executeCommand?: typeof executeAllowedWpCommand;
43
+ /** Test seam: resolve the sandbox backend. */
44
+ readonly resolveAvailability?: () => Promise<SandboxAvailability>;
45
+ /** Test seam: run a single sandboxed gate. */
46
+ readonly runSandboxedGate?: RunSandboxedGate;
24
47
  }
25
- export declare function verifyDeliveryPromotionGates(input: VerifyDeliveryGatesInput): ReviewGateVerification | undefined;
48
+ export declare function verifyDeliveryPromotionGates(input: VerifyDeliveryGatesInput): Promise<ReviewGateVerification | undefined>;
49
+ /**
50
+ * Builds the real {@link RunSandboxedGate}. `cleanupSandbox` is a test-only
51
+ * seam (defaults to the real {@link cleanupSandboxCommand}) so unit tests can
52
+ * force the fail-closed "passing gate, leaky sandbox" path without a real srt
53
+ * backend; every non-test caller gets the real cleanup and byte-identical
54
+ * behavior to before this seam existed.
55
+ */
56
+ export declare function createRunSandboxedGate(cleanupSandbox?: () => Promise<void>): RunSandboxedGate;
26
57
  export declare function verificationPromptSummary(verification: ReviewGateVerification | undefined): string | undefined;
27
58
  export declare function verificationArtifactSection(verification: ReviewGateVerification | undefined): string;
@@ -1,8 +1,14 @@
1
+ import { mkdtempSync, realpathSync, rmSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
1
3
  import path from "node:path";
2
- import { executeAllowedWpCommand, relativeCommandLogPath, } from "#trust/command-runner.js";
4
+ import { executeAllowedWpCommand, rejectedInvocationResult, relativeCommandLogPath, resolveInvocationFromCommand, runResolvedInvocationAsync, } from "#trust/command-runner.js";
3
5
  import { parseTrustDossier } from "#trust/dossier.js";
4
6
  import { parseAllowedWpCommand } from "#trust/gates.js";
5
- export function verifyDeliveryPromotionGates(input) {
7
+ import { buildSandboxedGateEnv } from "#review/execution/sandbox/env.js";
8
+ import { cleanupSandboxCommand, wrapGateForSandbox } from "#review/execution/sandbox/adapter.js";
9
+ import { resolveSandboxAvailability } from "#review/execution/sandbox/probe.js";
10
+ const UNSANDBOXED_OVERRIDE_ENV = "WP_REVIEW_UNSANDBOXED_GATES";
11
+ export async function verifyDeliveryPromotionGates(input) {
6
12
  if (input.purpose !== "delivery")
7
13
  return undefined;
8
14
  const parsed = parseTrustDossier(input.blueprintContent);
@@ -12,48 +18,82 @@ export function verifyDeliveryPromotionGates(input) {
12
18
  parsed.violations[0]?.message === "missing Trust Dossier section") {
13
19
  return undefined;
14
20
  }
21
+ return { status: "failed", commands: [], failureCode: "malformed-trust-dossier" };
22
+ }
23
+ const gates = parsed.dossier?.gates ?? [];
24
+ if (gates.length === 0)
25
+ return undefined;
26
+ const overrideUnsandboxed = process.env[UNSANDBOXED_OVERRIDE_ENV] === "1";
27
+ const availability = await (input.resolveAvailability?.() ?? resolveSandboxAvailability());
28
+ if (availability.kind === "none" && !overrideUnsandboxed) {
15
29
  return {
16
30
  status: "failed",
17
31
  commands: [],
18
- failureCode: "malformed-trust-dossier",
32
+ failureCode: "sandbox-unavailable",
33
+ sandbox: "unavailable",
34
+ sandboxReason: availability.reason,
19
35
  };
20
36
  }
21
- const gates = parsed.dossier?.gates ?? [];
22
- if (gates.length === 0)
23
- return undefined;
24
- const commands = [];
25
- const executeCommand = input.executeCommand ?? executeAllowedWpCommand;
37
+ const sandbox = overrideUnsandboxed ? "disabled-by-operator" : "srt";
26
38
  const logRoot = path.join(input.projectRoot, ".webpresso", "logs", "delivery-verification", input.gateId);
27
- for (const gate of gates) {
39
+ const runTmpDir = sandbox === "srt" ? mkdtempSync(path.join(tmpdir(), "wp-review-run-")) : undefined;
40
+ try {
41
+ return await runGateLoop(input, { gates, sandbox, logRoot, runTmpDir });
42
+ }
43
+ finally {
44
+ if (runTmpDir !== undefined)
45
+ rmSync(runTmpDir, { recursive: true, force: true });
46
+ }
47
+ }
48
+ async function runGateLoop(input, ctx) {
49
+ const commands = [];
50
+ const runSandboxedGate = input.runSandboxedGate ?? defaultRunSandboxedGate;
51
+ for (const gate of ctx.gates) {
28
52
  if (input.signal?.aborted) {
29
53
  return {
30
54
  status: "failed",
31
55
  commands,
32
56
  failureCode: "verification-cancelled",
57
+ sandbox: ctx.sandbox,
33
58
  };
34
59
  }
35
60
  if (isApprovalDependentLifecycleGate(gate.command)) {
36
- commands.push({
37
- command: gate.command,
38
- outcome: "deferred",
39
- durationMs: 0,
40
- exitCode: null,
41
- });
61
+ commands.push({ command: gate.command, outcome: "deferred", durationMs: 0, exitCode: null });
42
62
  continue;
43
63
  }
44
- const result = executeCommand({
45
- command: gate.command,
46
- executionRoot: input.checkout.cwd,
47
- logRoot,
48
- env: { CI: "1", NO_COLOR: "1", WP_FORCE_SOURCE: "1" },
49
- });
64
+ const result = ctx.sandbox === "srt"
65
+ ? await runSandboxedGate({
66
+ command: gate.command,
67
+ executionRoot: input.checkout.cwd,
68
+ logRoot: ctx.logRoot,
69
+ runTmpDir: ctx.runTmpDir ?? "",
70
+ projectRoot: input.projectRoot,
71
+ ...(input.signal ? { signal: input.signal } : {}),
72
+ })
73
+ : (input.executeCommand ?? executeAllowedWpCommand)({
74
+ command: gate.command,
75
+ executionRoot: input.checkout.cwd,
76
+ logRoot: ctx.logRoot,
77
+ env: { CI: "1", NO_COLOR: "1", WP_FORCE_SOURCE: "1" },
78
+ });
50
79
  commands.push(publicCommandResult(result));
80
+ // A cancellation DURING a gate (abort mid-execution) must report as
81
+ // cancelled, not a generic command failure.
82
+ if (input.signal?.aborted || result.failureCode === "command-cancelled") {
83
+ return {
84
+ status: "failed",
85
+ commands,
86
+ failureCode: "verification-cancelled",
87
+ sandbox: ctx.sandbox,
88
+ };
89
+ }
51
90
  if (result.outcome !== "passed") {
52
91
  return {
53
92
  status: "failed",
54
93
  commands,
55
94
  failureCode: result.failureCode ?? "verification-command-failed",
56
95
  logPath: relativeCommandLogPath(input.projectRoot, result.logPath),
96
+ sandbox: ctx.sandbox,
57
97
  };
58
98
  }
59
99
  const changes = input.checkout.changes();
@@ -63,12 +103,76 @@ export function verifyDeliveryPromotionGates(input) {
63
103
  commands,
64
104
  failureCode: "verification-worktree-contaminated",
65
105
  logPath: relativeCommandLogPath(input.projectRoot, result.logPath),
106
+ sandbox: ctx.sandbox,
66
107
  };
67
108
  }
68
109
  }
110
+ return { status: "passed", commands, sandbox: ctx.sandbox };
111
+ }
112
+ /**
113
+ * Builds the real {@link RunSandboxedGate}. `cleanupSandbox` is a test-only
114
+ * seam (defaults to the real {@link cleanupSandboxCommand}) so unit tests can
115
+ * force the fail-closed "passing gate, leaky sandbox" path without a real srt
116
+ * backend; every non-test caller gets the real cleanup and byte-identical
117
+ * behavior to before this seam existed.
118
+ */
119
+ export function createRunSandboxedGate(cleanupSandbox = cleanupSandboxCommand) {
120
+ return async (args) => {
121
+ const startedAt = Date.now();
122
+ const env = buildSandboxedGateEnv(args.runTmpDir);
123
+ let invocation;
124
+ try {
125
+ invocation = resolveInvocationFromCommand(args.executionRoot, args.command, env, {
126
+ replaceProcessEnv: true,
127
+ });
128
+ }
129
+ catch (error) {
130
+ return rejectedInvocationResult(args.command, args.logRoot, startedAt, error);
131
+ }
132
+ let result;
133
+ try {
134
+ // The wrap is INSIDE the try so a wrap failure (unresolvable srt, empty
135
+ // argv) still produces a persisted failed verification instead of escaping.
136
+ const wrapped = await wrapGateForSandbox(invocation, {
137
+ checkoutRoot: realpathSync(args.executionRoot),
138
+ runTmpDir: realpathSync(args.runTmpDir),
139
+ projectRoot: args.projectRoot,
140
+ });
141
+ result = await runResolvedInvocationAsync({ command: wrapped.command, args: [...wrapped.args], env: wrapped.env }, {
142
+ command: args.command,
143
+ executionRoot: args.executionRoot,
144
+ logRoot: args.logRoot,
145
+ startedAt,
146
+ ...(args.signal ? { signal: args.signal } : {}),
147
+ });
148
+ }
149
+ catch (error) {
150
+ result = rejectedInvocationResult(args.command, args.logRoot, startedAt, error);
151
+ }
152
+ // Sandbox cleanup is part of the gate's integrity: an unbalanced srt counter
153
+ // or leftover mounts must NOT be reported as a clean pass. If cleanup fails
154
+ // after an otherwise-passing gate, convert the result to a failed
155
+ // verification and keep the gate output as secondary evidence. A gate that
156
+ // already failed keeps its more-informative primary failure.
157
+ try {
158
+ await cleanupSandbox();
159
+ }
160
+ catch (error) {
161
+ if (result.outcome === "passed")
162
+ return sandboxCleanupFailedResult(result, error);
163
+ }
164
+ return result;
165
+ };
166
+ }
167
+ const defaultRunSandboxedGate = createRunSandboxedGate();
168
+ function sandboxCleanupFailedResult(gateResult, error) {
169
+ const message = error instanceof Error ? error.message : String(error);
69
170
  return {
70
- status: "passed",
71
- commands,
171
+ ...gateResult,
172
+ outcome: "failed",
173
+ failureCode: "sandbox-cleanup-failed",
174
+ errorMessage: `sandbox cleanup did not complete after a passing gate: ${message}`,
175
+ stderr: `${gateResult.stderr}\n[sandbox-cleanup-failed] ${message}`.trim(),
72
176
  };
73
177
  }
74
178
  export function verificationPromptSummary(verification) {
@@ -77,7 +181,7 @@ export function verificationPromptSummary(verification) {
77
181
  if (verification.status !== "passed")
78
182
  return undefined;
79
183
  return [
80
- "Host verification before outside review: passed.",
184
+ `Host verification before outside review: passed (sandbox: ${verification.sandbox ?? "unknown"}).`,
81
185
  ...verification.commands.map((command, index) => `${index + 1}. ${command.command}: ${command.outcome === "deferred" ? "deferred until review publication" : "passed"}`),
82
186
  ].join("\n");
83
187
  }
@@ -97,6 +201,8 @@ export function verificationArtifactSection(verification) {
97
201
  "## Host Verification",
98
202
  "",
99
203
  `Status: ${verification.status}`,
204
+ `Sandbox: ${verification.sandbox ?? "unknown"}`,
205
+ ...(verification.sandboxReason ? [`Sandbox detail: ${verification.sandboxReason}`] : []),
100
206
  ...verification.commands.map((command, index) => `${index + 1}. ${command.command} -> ${command.outcome} (${command.durationMs}ms, exit ${command.exitCode ?? "null"})`),
101
207
  ...(verification.failureCode ? [`Failure code: ${verification.failureCode}`] : []),
102
208
  ...(verification.logPath ? [`Log: ${verification.logPath}`] : []),
@@ -6,6 +6,7 @@ export interface ReviewTargetCheckout {
6
6
  }
7
7
  declare function statusEntryPath(line: string): string;
8
8
  export declare function createReviewTargetCheckout(repositoryRoot: string, targetSha: string): ReviewTargetCheckout;
9
+ export declare function assertDependencyContainment(checkoutRoot: string): void;
9
10
  /** Test-only surface for porcelain path parsing. */
10
11
  export declare const reviewCheckoutInternals: {
11
12
  statusEntryPath: typeof statusEntryPath;