create-agdf 0.4.9 → 0.6.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 (43) hide show
  1. package/README.md +9 -7
  2. package/bin/create-agdf.js +284 -152
  3. package/generated/.agdf/control/README.md +15 -3
  4. package/generated/.agdf/control/templates/RUN_STATE.md +48 -0
  5. package/generated/.github/skills/agdf-brownfield-analysis/SKILL.md +3 -3
  6. package/generated/.github/skills/agdf-delivery-path-search/SKILL.md +14 -0
  7. package/generated/.github/skills/agdf-gate-check/SKILL.md +15 -10
  8. package/generated/.github/skills/agdf-release-or/SKILL.md +1 -1
  9. package/generated/.github/skills/agdf-runtime-contract.md +24 -8
  10. package/generated/.opencode/agdf-runtime-contract.md +24 -8
  11. package/generated/.opencode/agents/agdf-brownfield-analysis.md +2 -2
  12. package/generated/.opencode/agents/agdf-delivery-path-search.md +14 -0
  13. package/generated/.opencode/agents/agdf-gate-check.md +15 -10
  14. package/generated/.opencode/agents/agdf-release-or.md +1 -1
  15. package/generated/plugins/agdf/.codex-plugin/plugin.json +1 -1
  16. package/generated/plugins/agdf/control/README.md +15 -3
  17. package/generated/plugins/agdf/control/templates/RUN_STATE.md +48 -0
  18. package/generated/plugins/agdf/hooks/session-start.sh +2 -0
  19. package/generated/plugins/agdf/meta/agdf-plugin.definition.json +1 -1
  20. package/generated/plugins/agdf/meta/agdf-runtime-contract.md +24 -8
  21. package/generated/plugins/agdf/skills/brownfield-analysis/SKILL.md +3 -3
  22. package/generated/plugins/agdf/skills/delivery-path-search/SKILL.md +14 -0
  23. package/generated/plugins/agdf/skills/gate-check/SKILL.md +15 -10
  24. package/generated/plugins/agdf/skills/release-or/SKILL.md +1 -1
  25. package/lib/control-state/aggregate.js +18 -0
  26. package/lib/control-state/index.js +6 -0
  27. package/lib/control-state/legacy-migration.js +94 -0
  28. package/lib/control-state/run-state-parser.js +196 -0
  29. package/lib/control-state/run-state-repository.js +68 -0
  30. package/lib/control-state/run-state-resolver.js +45 -0
  31. package/lib/control-state/run-state-writer.js +96 -0
  32. package/lib/delivery-path-search/candidate-policy.js +67 -2
  33. package/lib/delivery-path-search/contracts.js +127 -0
  34. package/lib/delivery-path-search/evaluators/claude.js +2 -16
  35. package/lib/delivery-path-search/evaluators/codex.js +2 -16
  36. package/lib/delivery-path-search/generators/claude.js +40 -0
  37. package/lib/delivery-path-search/generators/codex.js +38 -0
  38. package/lib/delivery-path-search/generators/protocol.js +12 -0
  39. package/lib/delivery-path-search/persistence.js +5 -0
  40. package/lib/delivery-path-search/search-engine.js +64 -2
  41. package/lib/delivery-path-search/state-adapter.js +119 -16
  42. package/lib/delivery-path-search/transports/read-only-guard.js +43 -0
  43. package/package.json +4 -2
@@ -1,16 +1,34 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { CONTRACT_VERSION } from "./contracts.js";
3
+ import {
4
+ CONTRACT_VERSION,
5
+ GENERATOR_CONTRACT_VERSION,
6
+ validateGeneratorRequest,
7
+ } from "./contracts.js";
8
+ import { resolveRuns, verifyLegacyProjection } from "../control-state/index.js";
4
9
 
5
10
  function section(content, heading) {
6
- return content.match(new RegExp(`## ${heading}\\r?\\n([\\s\\S]*?)(?=\\r?\\n## |$)`))?.[1] ?? "";
11
+ return (
12
+ content.match(
13
+ new RegExp(`## ${heading}\\r?\\n([\\s\\S]*?)(?=\\r?\\n## |$)`),
14
+ )?.[1] ?? ""
15
+ );
7
16
  }
8
17
 
9
18
  function tableAnswers(content) {
10
19
  const answers = {};
11
20
  for (const line of section(content, "Current Control State").split(/\r?\n/)) {
12
- const cells = line.split("|").slice(1, -1).map((cell) => cell.trim());
13
- if (cells.length >= 2 && cells[0] && !cells[0].startsWith("---") && cells[0] !== "Question") answers[cells[0]] = cells[1];
21
+ const cells = line
22
+ .split("|")
23
+ .slice(1, -1)
24
+ .map((cell) => cell.trim());
25
+ if (
26
+ cells.length >= 2 &&
27
+ cells[0] &&
28
+ !cells[0].startsWith("---") &&
29
+ cells[0] !== "Question"
30
+ )
31
+ answers[cells[0]] = cells[1];
14
32
  }
15
33
  return answers;
16
34
  }
@@ -18,34 +36,83 @@ function tableAnswers(content) {
18
36
  function statusCard(content) {
19
37
  const card = {};
20
38
  for (const line of section(content, "Run Status Card").split(/\r?\n/)) {
21
- const cells = line.split("|").slice(1, -1).map((cell) => cell.trim().replace(/^`|`$/g, ""));
22
- if (cells.length >= 2 && cells[0] && !cells[0].startsWith("---") && cells[0] !== "Run status") card[cells[0]] = cells[1];
39
+ const cells = line
40
+ .split("|")
41
+ .slice(1, -1)
42
+ .map((cell) => cell.trim().replace(/^`|`$/g, ""));
43
+ if (
44
+ cells.length >= 2 &&
45
+ cells[0] &&
46
+ !cells[0].startsWith("---") &&
47
+ cells[0] !== "Run status"
48
+ )
49
+ card[cells[0]] = cells[1];
23
50
  }
24
51
  return card;
25
52
  }
26
53
 
27
54
  function listCell(value) {
28
- return String(value ?? "").split(/\s*;\s*/).map((item) => item.trim()).filter(Boolean);
55
+ return String(value ?? "")
56
+ .split(/\s*;\s*/)
57
+ .map((item) => item.trim())
58
+ .filter(Boolean);
29
59
  }
30
60
 
31
61
  export function searchInputFromControl(targetDir, options = {}) {
32
- const runPath = join(targetDir, ".agdf", "control", "AGDF_RUN.md");
33
- if (!existsSync(runPath)) throw new Error("missing .agdf/control/AGDF_RUN.md");
62
+ const canonicalRoot = join(targetDir, ".agdf", "control", "runs");
63
+ if (existsSync(canonicalRoot)) {
64
+ const projection = verifyLegacyProjection(targetDir);
65
+ if (!["absent", "valid"].includes(projection.status)) {
66
+ throw new Error(`AGDF_LEGACY_PROJECTION_DRIFT:${projection.status}`);
67
+ }
68
+ }
69
+ const resolved = existsSync(canonicalRoot)
70
+ ? resolveRuns(targetDir, {
71
+ runIdArg: options.scopeKey,
72
+ runIdEnv: process.env.AGDF_RUN_ID,
73
+ })
74
+ : null;
75
+ const runPath =
76
+ resolved?.run.path ?? join(targetDir, ".agdf", "control", "AGDF_RUN.md");
77
+ if (!existsSync(runPath)) throw new Error("missing AGDF run state");
34
78
  const content = readFileSync(runPath, "utf8");
35
- const meta = Object.fromEntries([...content.matchAll(/^- ([a-z_]+):\s*(.+)$/gm)].map((match) => [match[1], match[2].replace(/^`|`$/g, "").trim()]));
79
+ const meta = Object.fromEntries(
80
+ [...content.matchAll(/^- ([a-z_]+):\s*(.+)$/gm)].map((match) => [
81
+ match[1],
82
+ match[2].replace(/^`|`$/g, "").trim(),
83
+ ]),
84
+ );
36
85
  const answers = tableAnswers(content);
37
86
  const card = statusCard(content);
38
- return {
87
+ const result = {
39
88
  contract_version: CONTRACT_VERSION,
40
89
  scope_key: options.scopeKey ?? meta.run_id ?? "unknown-scope",
41
90
  objective: section(content, "Objective").trim(),
42
91
  current_gate: card["Current gate"] ?? meta.current_gate ?? "unknown",
43
92
  allowed_actions: options.allowedActions ?? listCell(card["Allowed now"]),
44
- forbidden_actions: options.forbiddenActions ?? listCell(answers["What is explicitly forbidden right now?"]),
45
- evidence_refs: [...content.matchAll(/\|\s*([^|]+)\s*\|\s*([^|]+)\s*\|\s*([^|]+)\s*\|\s*(direct|indirect)\s*\|/g)]
46
- .slice(1).map((match) => `${match[1].trim()}: ${match[2].trim()}`),
47
- risks: section(content, "Risks").split(/\r?\n/).filter((line) => line.startsWith("|") && !line.includes("---") && !line.includes("| Risk |")).map((line) => line.split("|")[1].trim()),
48
- enforcement: options.enforcement ?? { level: "instruction_only", evidence: ["surface instruction prohibits implementation during search"] },
93
+ forbidden_actions:
94
+ options.forbiddenActions ??
95
+ listCell(answers["What is explicitly forbidden right now?"]),
96
+ evidence_refs: [
97
+ ...content.matchAll(
98
+ /\|\s*([^|]+)\s*\|\s*([^|]+)\s*\|\s*([^|]+)\s*\|\s*(direct|indirect)\s*\|/g,
99
+ ),
100
+ ]
101
+ .slice(1)
102
+ .map((match) => `${match[1].trim()}: ${match[2].trim()}`),
103
+ risks: section(content, "Risks")
104
+ .split(/\r?\n/)
105
+ .filter(
106
+ (line) =>
107
+ line.startsWith("|") &&
108
+ !line.includes("---") &&
109
+ !line.includes("| Risk |"),
110
+ )
111
+ .map((line) => line.split("|")[1].trim()),
112
+ enforcement: options.enforcement ?? {
113
+ level: "instruction_only",
114
+ evidence: ["surface instruction prohibits implementation during search"],
115
+ },
49
116
  budgets: {
50
117
  max_candidates: options.maxCandidates ?? 5,
51
118
  max_depth: options.maxDepth ?? 2,
@@ -55,4 +122,40 @@ export function searchInputFromControl(targetDir, options = {}) {
55
122
  stability_window: options.stabilityWindow ?? 3,
56
123
  },
57
124
  };
125
+ if (options.generation?.enabled)
126
+ result.generation = {
127
+ enabled: true,
128
+ max_calls: 1,
129
+ max_proposals: options.generation.maxProposals ?? 5,
130
+ max_duration_ms: options.generation.maxDurationMs ?? 30000,
131
+ max_cost_units: options.generation.maxCostUnits ?? 5,
132
+ };
133
+ return result;
134
+ }
135
+
136
+ export function generatorRequestFromInput(input) {
137
+ return validateGeneratorRequest({
138
+ contract_version: GENERATOR_CONTRACT_VERSION,
139
+ scope_key: input.scope_key,
140
+ objective: input.objective,
141
+ scope_summary: input.objective,
142
+ current_gate: input.current_gate,
143
+ allowed_actions: input.allowed_actions,
144
+ forbidden_actions: input.forbidden_actions,
145
+ artefact_refs: [],
146
+ evidence: input.evidence_refs ?? [],
147
+ missing_evidence: [],
148
+ risks: input.risks ?? [],
149
+ constraints: [
150
+ "advisory only",
151
+ "canonical gate-check remains authoritative",
152
+ ],
153
+ enforcement: input.enforcement,
154
+ budgets: {
155
+ max_calls: input.generation.max_calls,
156
+ max_proposals: input.generation.max_proposals,
157
+ max_duration_ms: input.generation.max_duration_ms,
158
+ max_cost_units: input.generation.max_cost_units,
159
+ },
160
+ });
58
161
  }
@@ -0,0 +1,43 @@
1
+ import { execFileSync } from "node:child_process";
2
+
3
+ export function repositoryState(cwd) {
4
+ try {
5
+ return execFileSync("git", ["status", "--porcelain=v1", "-z"], {
6
+ cwd,
7
+ encoding: "utf8",
8
+ stdio: ["ignore", "pipe", "ignore"],
9
+ });
10
+ } catch {
11
+ return null;
12
+ }
13
+ }
14
+
15
+ export function guardedExecFileSync(file, args, options = {}) {
16
+ const before = repositoryState(options.cwd);
17
+ let output;
18
+ let failure;
19
+ try {
20
+ output = execFileSync(file, args, {
21
+ ...options,
22
+ encoding: options.encoding ?? "utf8",
23
+ stdio: options.stdio ?? ["ignore", "pipe", "pipe"],
24
+ timeout: options.timeout ?? 30000,
25
+ killSignal: "SIGTERM",
26
+ });
27
+ } catch (error) {
28
+ failure = error;
29
+ }
30
+ const after = repositoryState(options.cwd);
31
+ if (before !== null && after !== before) {
32
+ const error = new Error("repository mutation detected during read-only run");
33
+ error.code = "GENERATOR_MUTATION_DETECTED";
34
+ throw error;
35
+ }
36
+ if (failure?.code === "ETIMEDOUT" || failure?.signal === "SIGTERM") {
37
+ const timeout = new Error("read-only process timed out");
38
+ timeout.code = "GENERATOR_TIMEOUT";
39
+ throw timeout;
40
+ }
41
+ if (failure) throw failure;
42
+ return output;
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-agdf",
3
- "version": "0.4.9",
3
+ "version": "0.6.0",
4
4
  "description": "Bootstrap AGDF repository-local plugin files, Copilot/OpenCode instructions, skills, control files and machine-readable checks.",
5
5
  "type": "module",
6
6
  "files": [
@@ -23,8 +23,10 @@
23
23
  "sync-package-assets": "node ./scripts/sync-package-assets.js",
24
24
  "test:delivery-path-search": "node ./scripts/delivery-path-search-test.js",
25
25
  "test:delivery-path-search-unit": "node ./scripts/delivery-path-search-unit-test.js",
26
+ "test:delivery-path-search-generator": "node ./scripts/delivery-path-search-generator-test.js",
27
+ "test:control-state": "node ./scripts/control-state-test.js",
26
28
  "test:routing": "npm run sync-package-assets && node ./scripts/test-routing.js",
27
- "smoke-test": "npm run sync-package-assets && npm run test:delivery-path-search && npm run test:delivery-path-search-unit && node ./scripts/smoke-test.js && node ./scripts/test-routing.js",
29
+ "smoke-test": "npm run sync-package-assets && npm run test:control-state && npm run test:delivery-path-search && npm run test:delivery-path-search-unit && npm run test:delivery-path-search-generator && node ./scripts/smoke-test.js && node ./scripts/test-routing.js",
28
30
  "prepack": "npm run sync-package-assets"
29
31
  },
30
32
  "keywords": [