@boyingliu01/dsh-plugin-xp-gate 0.31.4 → 0.32.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 (58) hide show
  1. package/README.md +51 -2
  2. package/lib/client.js +760 -0
  3. package/lib/command.d.ts +11 -5
  4. package/lib/command.d.ts.map +1 -1
  5. package/lib/command.js +19 -13
  6. package/lib/command.js.map +1 -1
  7. package/lib/credentials.d.ts +39 -0
  8. package/lib/credentials.d.ts.map +1 -0
  9. package/lib/credentials.js +57 -0
  10. package/lib/credentials.js.map +1 -0
  11. package/lib/delphi-config.d.ts +34 -3
  12. package/lib/delphi-config.d.ts.map +1 -1
  13. package/lib/delphi-config.js +117 -48
  14. package/lib/delphi-config.js.map +1 -1
  15. package/lib/delphi-run.d.ts +1 -1
  16. package/lib/delphi-run.d.ts.map +1 -1
  17. package/lib/delphi-run.js +24 -3
  18. package/lib/delphi-run.js.map +1 -1
  19. package/lib/delphi-settings.d.ts +52 -0
  20. package/lib/delphi-settings.d.ts.map +1 -0
  21. package/lib/delphi-settings.js +76 -0
  22. package/lib/delphi-settings.js.map +1 -0
  23. package/lib/delphi.d.ts +6 -0
  24. package/lib/delphi.d.ts.map +1 -1
  25. package/lib/delphi.js +101 -55
  26. package/lib/delphi.js.map +1 -1
  27. package/lib/evidence.d.ts +70 -0
  28. package/lib/evidence.d.ts.map +1 -0
  29. package/lib/evidence.js +92 -0
  30. package/lib/evidence.js.map +1 -0
  31. package/lib/gate-runner.d.ts +33 -2
  32. package/lib/gate-runner.d.ts.map +1 -1
  33. package/lib/gate-runner.js +53 -4
  34. package/lib/gate-runner.js.map +1 -1
  35. package/lib/git-context.d.ts +26 -0
  36. package/lib/git-context.d.ts.map +1 -0
  37. package/lib/git-context.js +30 -0
  38. package/lib/git-context.js.map +1 -0
  39. package/lib/hooks.d.ts +55 -0
  40. package/lib/hooks.d.ts.map +1 -0
  41. package/lib/hooks.js +152 -0
  42. package/lib/hooks.js.map +1 -0
  43. package/lib/index.d.ts +79 -1
  44. package/lib/index.d.ts.map +1 -1
  45. package/lib/index.js +385 -12
  46. package/lib/index.js.map +1 -1
  47. package/lib/skill-provider.d.ts +15 -0
  48. package/lib/skill-provider.d.ts.map +1 -0
  49. package/lib/skill-provider.js +205 -0
  50. package/lib/skill-provider.js.map +1 -0
  51. package/lib/sprint.d.ts +60 -0
  52. package/lib/sprint.d.ts.map +1 -0
  53. package/lib/sprint.js +92 -0
  54. package/lib/sprint.js.map +1 -0
  55. package/package.json +26 -10
  56. package/skills/delphi-review/AGENTS.md +3 -3
  57. package/skills/sprint-flow/AGENTS.md +3 -3
  58. package/skills/test-specification-alignment/AGENTS.md +3 -3
@@ -1,7 +1,34 @@
1
1
  import { TOOL_ABORTED } from "@deepseek-ai/dsh-tools";
2
2
  import { HarnessError } from "@deepseek-ai/dsh-llm";
3
- /** Render a completed shell run as a single model-facing text block. */
4
- export function renderGateResult(result) {
3
+ /**
4
+ * Classify a completed shell run.
5
+ *
6
+ * The order below is load-bearing and must not be rearranged:
7
+ *
8
+ * 1. timeout / truncation -> INDETERMINATE (a killed or clipped run yields no verdict)
9
+ * 2. exit 0 with no stdout -> INDETERMINATE (the command succeeded but said nothing)
10
+ * 3. exit 0 with stdout -> PASS
11
+ * 4. otherwise -> GATE FAILED (nonzero with output) or INDETERMINATE (silent)
12
+ *
13
+ * Step 1 must precede step 3: a timed-out process can still report exit 0 from
14
+ * the state it held when the deadline killed it, so testing `exitCode === 0`
15
+ * first would render a timeout as a pass. That is the exact defect this project
16
+ * fixed in Gate 8 and Gate 10, and the plugin must not reintroduce it.
17
+ */
18
+ export function classifyGateRun(result) {
19
+ const stdout = result.stdout.text.trim();
20
+ if (result.timedOut)
21
+ return "INDETERMINATE";
22
+ if (result.stdout.truncated)
23
+ return "INDETERMINATE";
24
+ if (result.exitCode === 0)
25
+ return stdout.length > 0 ? "PASS" : "INDETERMINATE";
26
+ // Nonzero: a verdict exists only when the run produced something to show.
27
+ const stderr = result.stderr.text.trim();
28
+ return stdout.length > 0 || stderr.length > 0 ? "GATE FAILED" : "INDETERMINATE";
29
+ }
30
+ /** Detailed diagnostics appended after the verdict line, when present. */
31
+ function renderDetails(result) {
5
32
  const lines = [];
6
33
  const stdout = result.stdout.text.trim();
7
34
  if (stdout.length > 0)
@@ -26,7 +53,28 @@ export function renderGateResult(result) {
26
53
  const spill = result.stderr.spillPath !== undefined ? `, full output: ${result.stderr.spillPath}` : "";
27
54
  lines.push(`[stderr truncated${spill}]`);
28
55
  }
29
- return lines.length > 0 ? lines.join("\n") : "[XP-Gate] command completed (no output).";
56
+ return lines;
57
+ }
58
+ /** Install hint appended whenever no verdict could be reached. */
59
+ const INDETERMINATE_HINT = "The gate produced no usable verdict. Check that the xp-gate CLI is installed " +
60
+ "and runnable (npm i -g @boyingliu01/xp-gate), then retry.";
61
+ /**
62
+ * Render a completed shell run as model-facing text.
63
+ *
64
+ * Every run resolves to exactly one of three verdicts. A run that could not
65
+ * establish a verdict says INDETERMINATE and states explicitly that it is not a
66
+ * pass, because an empty output read as a green check is worse than no output.
67
+ */
68
+ export function renderGateResult(result) {
69
+ const verdict = classifyGateRun(result);
70
+ const lines = renderDetails(result);
71
+ if (verdict === "PASS") {
72
+ return `[XP-Gate] PASS\n${lines.join("\n")}`;
73
+ }
74
+ if (verdict === "GATE FAILED") {
75
+ return `[XP-Gate] GATE FAILED\n${lines.join("\n")}`;
76
+ }
77
+ return [`[XP-Gate] INDETERMINATE — gate produced no output; NOT a pass`, ...lines, INDETERMINATE_HINT].join("\n");
30
78
  }
31
79
  /**
32
80
  * Run an xp-gate command through the harness shell seam. Nonzero exits, timeouts,
@@ -35,7 +83,8 @@ export function renderGateResult(result) {
35
83
  */
36
84
  export async function runXpGate(shell, signal, command, workdir, timeoutMs) {
37
85
  const spec = shell.resolve({ command, workdir, timeoutMs, signal });
38
- const result = await shell.run(spec);
86
+ const execution = await shell.execute(spec);
87
+ const result = await execution.result();
39
88
  if (result.aborted) {
40
89
  const error = new HarnessError("tool call aborted", TOOL_ABORTED);
41
90
  error.name = "AbortError";
@@ -1 +1 @@
1
- {"version":3,"file":"gate-runner.js","sourceRoot":"","sources":["../src/gate-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAYnD,wEAAwE;AACxE,MAAM,UAAU,gBAAgB,CAAC,MAAsB;IACrD,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IACxC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IACxC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,MAAM,EAAE,CAAC,CAAA;IACvD,IAAI,MAAM,CAAC,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,oBAAoB,MAAM,CAAC,SAAS,KAAK,CAAC,CAAA;IAC1E,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAA;IACpG,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;IACpE,IAAI,MAAM,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC;QACpC,KAAK,CAAC,IAAI,CAAC,sCAAsC,MAAM,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,CAAA;IAC/E,CA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.
3
+ *
4
+ * @test REQ-DSH-012 delphi-review can produce Gate MW evidence
5
+ * @intent Read HEAD and the current branch name, which the walkthrough evidence must
6
+ * name exactly, without adding a git library dependency.
7
+ * @covers AC-DSH-012-02
8
+ *
9
+ * Spawned git, not a parsed .git directory: worktrees and detached HEAD have
10
+ * layouts that are easy to misread, and getting either wrong produces evidence the
11
+ * validator rejects at push time with no hint about why.
12
+ */
13
+ /** The two facts the validator compares against. */
14
+ export interface GitContext {
15
+ readonly head: string;
16
+ readonly branch: string;
17
+ }
18
+ /**
19
+ * Read HEAD and the branch.
20
+ *
21
+ * The validator compares `branch` to the name the push reports; a detached HEAD
22
+ * reports "HEAD", which is what git itself would say, so it is passed through
23
+ * rather than guessed at.
24
+ */
25
+ export declare function readGitContext(cwd: string): GitContext;
26
+ //# sourceMappingURL=git-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-context.d.ts","sourceRoot":"","sources":["../src/git-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,oDAAoD;AACpD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAStD"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Minimal git context for evidence.
3
+ *
4
+ * @test REQ-DSH-012 delphi-review can produce Gate MW evidence
5
+ * @intent Read HEAD and the current branch name, which the walkthrough evidence must
6
+ * name exactly, without adding a git library dependency.
7
+ * @covers AC-DSH-012-02
8
+ *
9
+ * Spawned git, not a parsed .git directory: worktrees and detached HEAD have
10
+ * layouts that are easy to misread, and getting either wrong produces evidence the
11
+ * validator rejects at push time with no hint about why.
12
+ */
13
+ import { execFileSync } from "node:child_process";
14
+ /**
15
+ * Read HEAD and the branch.
16
+ *
17
+ * The validator compares `branch` to the name the push reports; a detached HEAD
18
+ * reports "HEAD", which is what git itself would say, so it is passed through
19
+ * rather than guessed at.
20
+ */
21
+ export function readGitContext(cwd) {
22
+ const run = (args) => execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
23
+ try {
24
+ return { head: run(["rev-parse", "HEAD"]), branch: run(["rev-parse", "--abbrev-ref", "HEAD"]) };
25
+ }
26
+ catch (error) {
27
+ throw new Error(`cannot read git context in ${cwd}: ${error.message}`);
28
+ }
29
+ }
30
+ //# sourceMappingURL=git-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-context.js","sourceRoot":"","sources":["../src/git-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAQjD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,GAAG,GAAG,CAAC,IAAuB,EAAU,EAAE,CAC9C,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;IAEhG,IAAI,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC,EAAE,CAAA;IACjG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;IACnF,CAAC;AACH,CAAC"}
package/lib/hooks.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * DSH-native hooks: the delphi-review guard and the save-time principles check.
3
+ *
4
+ * @test REQ-DSH-015 sprint-phase writes are gated the way the IDE plugin gates them
5
+ * @intent Port the Claude Code guard and save-check to DSH's own pre/post-execute
6
+ * seams, keeping the degrade rules that made them safe there.
7
+ * @covers AC-DSH-015-01
8
+ *
9
+ * Degrade semantics are copied from plugins/claude-code/bin/delphi-review-guard.sh,
10
+ * which has been in use long enough to have settled them:
11
+ *
12
+ * no .sprint-state -> ALLOW (not a sprint project; gating it would punish every
13
+ * ordinary repo that installed the plugin)
14
+ * state, no verdict -> DENY (sprint is open, review not done)
15
+ * verdict != APPROVED-> DENY (reason names the actual verdict)
16
+ * APPROVED -> ALLOW
17
+ *
18
+ * The guard only ever inspects state. It must not throw: a throw inside pre-execute
19
+ * aborts the tool call, which is a worse failure than letting an edit through.
20
+ */
21
+ /** Denial the guard returns; shape matches DSH's PreToolDecision deny variant. */
22
+ export interface GuardDenial {
23
+ readonly kind: "deny";
24
+ readonly reason: string;
25
+ }
26
+ /**
27
+ * Can this tool modify the workspace? Anything not proven read-only can.
28
+ *
29
+ * Used by the save-time principles check, which must fire only for the tools that
30
+ * actually write a source file — `bash` is excluded here even though the guard
31
+ * gates it, because the check needs a `file_path` argument to inspect.
32
+ */
33
+ export declare function isEditTool(name: string): boolean;
34
+ /**
35
+ * Must this tool be gated by the sprint review guard?
36
+ *
37
+ * The inverse of {@link READ_ONLY_TOOLS}: an unrecognised tool is treated as
38
+ * capable of writing, which is what closes the `bash` hole.
39
+ */
40
+ export declare function mayModifyFiles(name: string): boolean;
41
+ /**
42
+ * Should a save-time check run for this path?
43
+ *
44
+ * Documents and data files are excluded on purpose: they are a large share of the
45
+ * commits in repositories using xp-gate, and the engine has nothing to say about
46
+ * them. Skipping them removes most of the hook's cost.
47
+ */
48
+ export declare function isCheckablePath(path: string): boolean;
49
+ /**
50
+ * Decide whether an edit may proceed.
51
+ *
52
+ * Returns undefined to mean "allow" so the caller can `if (denial) return denial`.
53
+ */
54
+ export declare function delphiGuardDecision(root: string, toolName: string): GuardDenial | undefined;
55
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAoCH,kFAAkF;AAClF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAsBD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKrD;AAgBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CA8B3F"}
package/lib/hooks.js ADDED
@@ -0,0 +1,152 @@
1
+ /**
2
+ * DSH-native hooks: the delphi-review guard and the save-time principles check.
3
+ *
4
+ * @test REQ-DSH-015 sprint-phase writes are gated the way the IDE plugin gates them
5
+ * @intent Port the Claude Code guard and save-check to DSH's own pre/post-execute
6
+ * seams, keeping the degrade rules that made them safe there.
7
+ * @covers AC-DSH-015-01
8
+ *
9
+ * Degrade semantics are copied from plugins/claude-code/bin/delphi-review-guard.sh,
10
+ * which has been in use long enough to have settled them:
11
+ *
12
+ * no .sprint-state -> ALLOW (not a sprint project; gating it would punish every
13
+ * ordinary repo that installed the plugin)
14
+ * state, no verdict -> DENY (sprint is open, review not done)
15
+ * verdict != APPROVED-> DENY (reason names the actual verdict)
16
+ * APPROVED -> ALLOW
17
+ *
18
+ * The guard only ever inspects state. It must not throw: a throw inside pre-execute
19
+ * aborts the tool call, which is a worse failure than letting an edit through.
20
+ */
21
+ import { existsSync, readFileSync } from "node:fs";
22
+ import { join } from "node:path";
23
+ /**
24
+ * Tools that provably cannot modify a file. Everything else is gated.
25
+ *
26
+ * This is an ALLOWLIST on purpose. The guard used to name the write tools
27
+ * instead (`write`, `edit`, `str_replace_editor`), which let `bash` through —
28
+ * one shell command writes a file, so the guard was bypassable by the very tool
29
+ * a model reaches for first. A write-blacklist loses again on every new
30
+ * file-touching tool; a read-only allowlist loses only by being too strict,
31
+ * which surfaces as an over-eager denial rather than a silent hole.
32
+ */
33
+ const READ_ONLY_TOOLS = new Set([
34
+ "read",
35
+ "read_image",
36
+ "grep",
37
+ "glob",
38
+ "todo_write",
39
+ "ask_user_question",
40
+ "list_agents",
41
+ "present",
42
+ // XP-Gate's report tools only read: `xp-gate check/principles/arch` report to
43
+ // stdout, and the one file they ever write is a temp file list under the OS
44
+ // temp directory (gate-runner's --all path), never the workspace.
45
+ "gate-check",
46
+ "gate-principles",
47
+ "gate-arch",
48
+ ]);
49
+ /** Where Sprint Flow records the review verdict. */
50
+ const SPRINT_STATE_DIR = ".sprint-state";
51
+ const VERDICT_FILE = "delphi-reviewed.json";
52
+ /** The file extensions the principles engine actually covers. */
53
+ const CHECKABLE_EXTENSIONS = new Set([
54
+ ".ts",
55
+ ".tsx",
56
+ ".js",
57
+ ".jsx",
58
+ ".py",
59
+ ".go",
60
+ ".java",
61
+ ".kt",
62
+ ".c",
63
+ ".cpp",
64
+ ".h",
65
+ ".swift",
66
+ ".m",
67
+ ".dart",
68
+ ".sh",
69
+ ".ps1",
70
+ ]);
71
+ /**
72
+ * Can this tool modify the workspace? Anything not proven read-only can.
73
+ *
74
+ * Used by the save-time principles check, which must fire only for the tools that
75
+ * actually write a source file — `bash` is excluded here even though the guard
76
+ * gates it, because the check needs a `file_path` argument to inspect.
77
+ */
78
+ export function isEditTool(name) {
79
+ return name === "write" || name === "edit" || name === "str_replace_editor";
80
+ }
81
+ /**
82
+ * Must this tool be gated by the sprint review guard?
83
+ *
84
+ * The inverse of {@link READ_ONLY_TOOLS}: an unrecognised tool is treated as
85
+ * capable of writing, which is what closes the `bash` hole.
86
+ */
87
+ export function mayModifyFiles(name) {
88
+ return !READ_ONLY_TOOLS.has(name);
89
+ }
90
+ /**
91
+ * Should a save-time check run for this path?
92
+ *
93
+ * Documents and data files are excluded on purpose: they are a large share of the
94
+ * commits in repositories using xp-gate, and the engine has nothing to say about
95
+ * them. Skipping them removes most of the hook's cost.
96
+ */
97
+ export function isCheckablePath(path) {
98
+ const lowered = path.toLowerCase();
99
+ const dot = lowered.lastIndexOf(".");
100
+ if (dot < 0)
101
+ return false;
102
+ return CHECKABLE_EXTENSIONS.has(lowered.slice(dot));
103
+ }
104
+ /** Read the recorded verdict, or a reason it cannot be read. */
105
+ function readVerdict(root) {
106
+ const file = join(root, SPRINT_STATE_DIR, VERDICT_FILE);
107
+ try {
108
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
109
+ const verdict = typeof parsed.verdict === "string" ? parsed.verdict : "";
110
+ return { verdict };
111
+ }
112
+ catch (error) {
113
+ // Corrupt JSON is a real state (a half-written file, a merge conflict). Treat it
114
+ // as "not reviewed" and say why, rather than throwing into the tool pipeline.
115
+ return { unreadable: error.message };
116
+ }
117
+ }
118
+ /**
119
+ * Decide whether an edit may proceed.
120
+ *
121
+ * Returns undefined to mean "allow" so the caller can `if (denial) return denial`.
122
+ */
123
+ export function delphiGuardDecision(root, toolName) {
124
+ if (!mayModifyFiles(toolName))
125
+ return undefined;
126
+ if (!existsSync(join(root, SPRINT_STATE_DIR)))
127
+ return undefined;
128
+ const verdictFile = join(root, SPRINT_STATE_DIR, VERDICT_FILE);
129
+ if (!existsSync(verdictFile)) {
130
+ return {
131
+ kind: "deny",
132
+ reason: "delphi-review has not run for this sprint. Complete the Phase 2 delphi-review " +
133
+ "before modifying code, then retry.",
134
+ };
135
+ }
136
+ const { verdict, unreadable } = readVerdict(root);
137
+ if (unreadable !== undefined) {
138
+ return {
139
+ kind: "deny",
140
+ reason: `${VERDICT_FILE} is not readable as JSON (${unreadable}). Re-run delphi-review.`,
141
+ };
142
+ }
143
+ if (verdict !== "APPROVED") {
144
+ return {
145
+ kind: "deny",
146
+ reason: `delphi-review verdict is "${verdict || "(missing)"}", not APPROVED. ` +
147
+ "Address the findings and re-run delphi-review, then retry.",
148
+ };
149
+ }
150
+ return undefined;
151
+ }
152
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;;;GASG;AACH,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,MAAM;IACN,YAAY;IACZ,MAAM;IACN,MAAM;IACN,YAAY;IACZ,mBAAmB;IACnB,aAAa;IACb,SAAS;IACT,8EAA8E;IAC9E,4EAA4E;IAC5E,kEAAkE;IAClE,YAAY;IACZ,iBAAiB;IACjB,WAAW;CACZ,CAAC,CAAA;AAEF,oDAAoD;AACpD,MAAM,gBAAgB,GAAG,eAAe,CAAA;AACxC,MAAM,YAAY,GAAG,sBAAsB,CAAA;AAQ3C,iEAAiE;AACjE,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IACxD,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,OAAO;IACP,KAAK;IACL,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,QAAQ;IACR,IAAI;IACJ,OAAO;IACP,KAAK;IACL,MAAM;CACP,CAAC,CAAA;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,oBAAoB,CAAA;AAC7E,CAAC;AAED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AA;IAE/D,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAA;IAC9D,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,MAAM,EACJ,gFAAgF;gBAChF,oCAAoC;SACvC,CAAA;IACH,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;IACjD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,GAAG,YAAY,6BAA6B,UAAU,0BAA0B;SACzF,CAAA;IACH,CAAC;IACD,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QAC3B,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,MAAM,EACJ,6BAA6B,OAAO,IAAI,WAAW,mBAAmB;gBACtE,4DAA4D;SAC/D,CAAA;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,83 @@
1
+ import z from "@deepseek-ai/schemastery";
1
2
  import type { Context } from "@deepseek-ai/cordis";
2
3
  export declare const name = "tool-xp-gate";
3
4
  export declare const inject: string[];
4
- export declare function apply(ctx: Context, _config?: unknown): void;
5
+ /**
6
+ * Runtime schema for the keys above.
7
+ *
8
+ * Exported as a schema, not just a type: DSH validates against it and surfaces the
9
+ * keys in the profile schema, so a user can discover and set them. A bare interface
10
+ * is invisible to the harness.
11
+ *
12
+ * The `delphi` block is `.volatile()`: the settings page edits it live, and DSH
13
+ * refuses to write a path that is not beneath a volatile node. The two hook
14
+ * switches stay ordinary fields — they are read at mount and remounting a hook is
15
+ * what "off" is supposed to require.
16
+ */
17
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
18
+ principlesCheck: z<"auto" | "off", "auto" | "off", "defined">;
19
+ delphiGuard: z<"auto" | "off", "auto" | "off", "defined">;
20
+ delphi: z<NoInfer<Schemastery.ObjectS<NoInfer<{
21
+ baseUrl: z<string, string, "defined">;
22
+ apiKey: z<string, string, "defined">;
23
+ seats: z<({
24
+ role?: string | null | undefined;
25
+ model?: string | null | undefined;
26
+ maxTokens?: number | null | undefined;
27
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
28
+ role: z<string, string, "defined">;
29
+ model: z<string, string, "defined">;
30
+ maxTokens: z<number, number, "plain">;
31
+ }>>[], "defined">;
32
+ thresholdPercent: z<number, number, "plain">;
33
+ maxRounds: z<number, number, "plain">;
34
+ }>>>, NoInfer<Schemastery.ObjectT<NoInfer<{
35
+ baseUrl: z<string, string, "defined">;
36
+ apiKey: z<string, string, "defined">;
37
+ seats: z<({
38
+ role?: string | null | undefined;
39
+ model?: string | null | undefined;
40
+ maxTokens?: number | null | undefined;
41
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
42
+ role: z<string, string, "defined">;
43
+ model: z<string, string, "defined">;
44
+ maxTokens: z<number, number, "plain">;
45
+ }>>[], "defined">;
46
+ thresholdPercent: z<number, number, "plain">;
47
+ maxRounds: z<number, number, "plain">;
48
+ }>>>, "volatile">;
49
+ }>>, Schemastery.ObjectT<NoInfer<{
50
+ principlesCheck: z<"auto" | "off", "auto" | "off", "defined">;
51
+ delphiGuard: z<"auto" | "off", "auto" | "off", "defined">;
52
+ delphi: z<NoInfer<Schemastery.ObjectS<NoInfer<{
53
+ baseUrl: z<string, string, "defined">;
54
+ apiKey: z<string, string, "defined">;
55
+ seats: z<({
56
+ role?: string | null | undefined;
57
+ model?: string | null | undefined;
58
+ maxTokens?: number | null | undefined;
59
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
60
+ role: z<string, string, "defined">;
61
+ model: z<string, string, "defined">;
62
+ maxTokens: z<number, number, "plain">;
63
+ }>>[], "defined">;
64
+ thresholdPercent: z<number, number, "plain">;
65
+ maxRounds: z<number, number, "plain">;
66
+ }>>>, NoInfer<Schemastery.ObjectT<NoInfer<{
67
+ baseUrl: z<string, string, "defined">;
68
+ apiKey: z<string, string, "defined">;
69
+ seats: z<({
70
+ role?: string | null | undefined;
71
+ model?: string | null | undefined;
72
+ maxTokens?: number | null | undefined;
73
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
74
+ role: z<string, string, "defined">;
75
+ model: z<string, string, "defined">;
76
+ maxTokens: z<number, number, "plain">;
77
+ }>>[], "defined">;
78
+ thresholdPercent: z<number, number, "plain">;
79
+ maxRounds: z<number, number, "plain">;
80
+ }>>>, "volatile">;
81
+ }>>, "plain">;
82
+ export declare function apply(ctx: Context, config?: unknown): void;
5
83
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAOlD,eAAO,MAAM,IAAI,iBAAiB,CAAA;AAClC,eAAO,MAAM,MAAM,UAAqB,CAAA;AAuKxC,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,OAAY,GAAG,IAAI,CAS/D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AA0BlD,eAAO,MAAM,IAAI,iBAAiB,CAAA;AAGlC,eAAO,MAAM,MAAM,UAA+B,CAAA;AAsZlD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA4BjB,CAAA;AAEF,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,OAAY,GAAG,IAAI,CA6B9D"}