create-agdf 0.4.1 → 0.4.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.
- package/README.md +21 -0
- package/bin/create-agdf.js +89 -5
- package/generated/.agdf/control/templates/AGDF_RUN.md +1 -0
- package/generated/.agdf/control/templates/artefacts/OR.md +1 -0
- package/generated/.github/skills/README.md +1 -0
- package/generated/.github/skills/agdf-delivery-closeout/SKILL.md +9 -4
- package/generated/.github/skills/agdf-delivery-path-search/SKILL.md +75 -0
- package/generated/.github/skills/agdf-release-or/SKILL.md +8 -4
- package/generated/.github/skills/agdf-runtime-contract.md +24 -0
- package/generated/.opencode/AGDF.md +2 -0
- package/generated/.opencode/README.md +1 -0
- package/generated/.opencode/agdf-runtime-contract.md +24 -0
- package/generated/.opencode/agents/agdf-delivery-closeout.md +9 -4
- package/generated/.opencode/agents/agdf-delivery-path-search.md +76 -0
- package/generated/.opencode/agents/agdf-release-or.md +8 -4
- package/generated/AGENTS.md +2 -0
- package/generated/plugins/agdf/.codex-plugin/plugin.json +1 -1
- package/generated/plugins/agdf/control/templates/AGDF_RUN.md +1 -0
- package/generated/plugins/agdf/control/templates/artefacts/OR.md +1 -0
- package/generated/plugins/agdf/meta/agdf-agent-router.md +2 -0
- package/generated/plugins/agdf/meta/agdf-plugin.definition.json +6 -1
- package/generated/plugins/agdf/meta/agdf-runtime-contract.md +24 -0
- package/generated/plugins/agdf/skills/delivery-closeout/SKILL.md +9 -4
- package/generated/plugins/agdf/skills/delivery-path-search/SKILL.md +75 -0
- package/generated/plugins/agdf/skills/delivery-path-search/help.md +5 -0
- package/generated/plugins/agdf/skills/release-or/SKILL.md +8 -4
- package/lib/delivery-path-search/candidate-policy.js +34 -0
- package/lib/delivery-path-search/contracts.js +110 -0
- package/lib/delivery-path-search/evaluators/codex.js +67 -0
- package/lib/delivery-path-search/evaluators/protocol.js +13 -0
- package/lib/delivery-path-search/persistence.js +34 -0
- package/lib/delivery-path-search/scoring.js +21 -0
- package/lib/delivery-path-search/search-engine.js +92 -0
- package/lib/delivery-path-search/state-adapter.js +58 -0
- package/lib/delivery-path-search/surfaces/capabilities.js +14 -0
- package/package.json +4 -2
package/generated/AGENTS.md
CHANGED
|
@@ -11,6 +11,7 @@ GitHub Copilot repository skills do not have a plugin namespace.
|
|
|
11
11
|
|
|
12
12
|
Therefore generated Copilot skill names use the AGDF prefix:
|
|
13
13
|
|
|
14
|
+
- `agdf-delivery-path-search`
|
|
14
15
|
- `agdf-brownfield-analysis`
|
|
15
16
|
- `agdf-clean-implementation-review`
|
|
16
17
|
- `agdf-code-review`
|
|
@@ -48,6 +49,7 @@ Structured Delivery Mode must respect gates, reviews and closeout discipline.
|
|
|
48
49
|
## Skill Routing
|
|
49
50
|
| Skill | Use For | Boundary |
|
|
50
51
|
|---|---|---|
|
|
52
|
+
| `agdf-delivery-path-search` | high-impact planning decisions with several plausible next delivery steps before implementation | read-only advisory search; never grants gate permission or replaces gate-check |
|
|
51
53
|
| `agdf-brownfield-analysis` | after gate-check permits Brownfield Review or implementation preparation, before non-trivial changes in existing systems | clarifies reuse, owners, risks and Mode/Slice Decision; never bypasses gate-check; Brownfield Review is not implementation permission |
|
|
52
54
|
| `agdf-clean-implementation-review` | inspect workarounds, fallbacks, parallel structures or symptom fixes | not a TP or QA substitute |
|
|
53
55
|
| `agdf-code-review` | mandatory CR step after code changes, focused on defects, regression and security findings | does not replace TP review, clean review or QA |
|
|
@@ -117,6 +117,7 @@ Keep the active work item traceable. A gate may open only when the previous gate
|
|
|
117
117
|
|
|
118
118
|
- context_graph_impact: `none | link_only | update_existing_node | new_node_required | sot_drift`
|
|
119
119
|
- context_graph_refs:
|
|
120
|
+
- context_graph_reconciliation: `resolved | not_applicable | open_gap`
|
|
120
121
|
- context_graph_required_action: `none | link | update | create | resolve_drift`
|
|
121
122
|
- context_graph_gate_effect: `none | warning | revise | block`
|
|
122
123
|
- context_graph_evidence:
|
|
@@ -81,6 +81,7 @@ This is a compact projection of the control state. It does not replace gate-chec
|
|
|
81
81
|
|
|
82
82
|
- context_graph_impact: `none | link_only | update_existing_node | new_node_required | sot_drift`
|
|
83
83
|
- context_graph_refs:
|
|
84
|
+
- context_graph_reconciliation: `resolved | not_applicable | open_gap`
|
|
84
85
|
- context_graph_required_action: `none | link | update | create | resolve_drift`
|
|
85
86
|
- context_graph_gate_effect: `none | warning | revise | block`
|
|
86
87
|
- context_graph_evidence:
|
|
@@ -12,6 +12,7 @@ Codex and Claude Code already provide the `agdf` plugin namespace.
|
|
|
12
12
|
Therefore plugin skill names are intentionally unprefixed:
|
|
13
13
|
|
|
14
14
|
- `gate-check`
|
|
15
|
+
- `delivery-path-search`
|
|
15
16
|
- `brownfield-analysis`
|
|
16
17
|
- `task-plan-review`
|
|
17
18
|
- `clean-implementation-review`
|
|
@@ -49,6 +50,7 @@ Structured Delivery Mode must respect gates, reviews and closeout discipline.
|
|
|
49
50
|
## Skill Routing
|
|
50
51
|
| Skill | Use For | Boundary |
|
|
51
52
|
|---|---|---|
|
|
53
|
+
| `delivery-path-search` | high-impact planning decisions with several plausible next delivery steps before implementation | read-only advisory search; never grants gate permission or replaces gate-check |
|
|
52
54
|
| `brownfield-analysis` | after gate-check permits Brownfield Review or implementation preparation, before non-trivial changes in existing systems | clarifies reuse, owners, risks and Mode/Slice Decision; never bypasses gate-check; Brownfield Review is not implementation permission |
|
|
53
55
|
| `clean-implementation-review` | inspect workarounds, fallbacks, parallel structures or symptom fixes | not a TP or QA substitute |
|
|
54
56
|
| `code-review` | mandatory CR step after code changes, focused on defects, regression and security findings | does not replace TP review, clean review or QA |
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"id": "agdf",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"displayName": "AI Governance & Delivery Framework",
|
|
6
6
|
"developerName": "AI-native Governance & Delivery Framework",
|
|
7
7
|
"description": "Codex-first workflow skills for gated, auditable AI-assisted software delivery.",
|
|
@@ -61,6 +61,11 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"skillSet": [
|
|
64
|
+
{
|
|
65
|
+
"slug": "delivery-path-search",
|
|
66
|
+
"useFor": "high-impact planning decisions with several plausible next delivery steps before implementation",
|
|
67
|
+
"boundary": "read-only advisory search; never grants gate permission or replaces gate-check"
|
|
68
|
+
},
|
|
64
69
|
{
|
|
65
70
|
"slug": "brownfield-analysis",
|
|
66
71
|
"useFor": "after gate-check permits Brownfield Review or implementation preparation, before non-trivial changes in existing systems",
|
|
@@ -52,6 +52,18 @@ It must not introduce a second gate model or override `gate-check`, `delivery-ma
|
|
|
52
52
|
|
|
53
53
|
`quality_outlook` must not unlock gates, imply QA pass, or substitute for missing evidence.
|
|
54
54
|
|
|
55
|
+
## Delivery Path Search
|
|
56
|
+
|
|
57
|
+
Delivery Path Search is an optional read-only planning step for high-impact decisions with several materially different next actions.
|
|
58
|
+
|
|
59
|
+
- It consumes current AGDF state and must reject gate-illegal candidates before model evaluation.
|
|
60
|
+
- It returns one advisory recommendation or `no_safe_recommendation`.
|
|
61
|
+
- It must report budgets, stopping reason and `full | tool_enforced | instruction_only` enforcement.
|
|
62
|
+
- Model scores are judgements, not measurements.
|
|
63
|
+
- Search output is evidence only. Canonical `gate-check` independently decides what may proceed.
|
|
64
|
+
- The bounded first-release algorithm must not be labelled MCTS.
|
|
65
|
+
- Surface adapters may translate transport and presentation, but must not fork scoring, search or gate semantics.
|
|
66
|
+
|
|
55
67
|
The field names above are the stable machine-readable contract used by JSON
|
|
56
68
|
reports and automation. Human-facing Markdown must present the same projection
|
|
57
69
|
with readable labels such as `Current gate`, `Allowed now`, `Blocked by`,
|
|
@@ -254,6 +266,7 @@ When a run affects project memory or a Context Graph, use:
|
|
|
254
266
|
- `Situation:` short plain-language summary when the impact is non-trivial
|
|
255
267
|
- `context_graph_impact`: `none | link_only | update_existing_node | new_node_required | sot_drift`
|
|
256
268
|
- `context_graph_refs`
|
|
269
|
+
- `context_graph_reconciliation`: `resolved | not_applicable | open_gap`
|
|
257
270
|
- `context_graph_required_action`: `none | link | update | create | resolve_drift`
|
|
258
271
|
- `context_graph_gate_effect`: `none | warning | revise | block`
|
|
259
272
|
- `context_graph_evidence`
|
|
@@ -261,6 +274,17 @@ When a run affects project memory or a Context Graph, use:
|
|
|
261
274
|
Do not create a new node for a mere version, a general chat summary, or a local observation without a concrete next clean step.
|
|
262
275
|
`sot_drift` must not pass silently as a warning.
|
|
263
276
|
|
|
277
|
+
### Context Graph Reconciliation
|
|
278
|
+
|
|
279
|
+
Relevant-run closeout must reconcile Context Graph impact before presenting a clean delivery handoff.
|
|
280
|
+
|
|
281
|
+
- Use `not_applicable` only when `context_graph_impact: none` and no durable graph knowledge is claimed.
|
|
282
|
+
- Use `resolved` when required graph work is complete and concrete refs are present.
|
|
283
|
+
- Use `open_gap` when graph work remains pending, refs are missing, or a node/update must still be curated.
|
|
284
|
+
- `link`, `update`, `create` and `resolve_drift` require either `resolved` evidence or an explicit `open_gap`.
|
|
285
|
+
- Resolved `link_only`, `update_existing_node` and `new_node_required` states require concrete `context_graph_refs`; `none`, empty refs or vague future-action language are not enough.
|
|
286
|
+
- OR and delivery-closeout must not present commit-ready, release-ready or otherwise clean handoff while `context_graph_reconciliation: open_gap` remains.
|
|
287
|
+
|
|
264
288
|
## Control Scaffold
|
|
265
289
|
|
|
266
290
|
When a repository needs durable AGDF state, use the plugin-local `control/` scaffold as the starting point.
|
|
@@ -32,6 +32,7 @@ Use `../../meta/agdf-runtime-contract.md` for closeout discipline, gate terms, C
|
|
|
32
32
|
4. `Approval: UAT` unlocks an active commit offer when code changes exist.
|
|
33
33
|
5. No commit handoff for runs without code changes.
|
|
34
34
|
6. Always include exactly one next step and one quality outlook.
|
|
35
|
+
7. If OR, QA or current run state reports `context_graph_reconciliation: open_gap`, do not provide a clean commit-ready handoff; set the next step to resolve or explicitly retain the Context Graph gap.
|
|
35
36
|
|
|
36
37
|
## When To Use
|
|
37
38
|
- after `QA pass` with code changes
|
|
@@ -62,8 +63,10 @@ If code-change status is unclear, do not claim a commit handoff.
|
|
|
62
63
|
- `uat_approved_with_code`
|
|
63
64
|
- `uat_approved_without_code`
|
|
64
65
|
- `non_delivery_closeout`
|
|
65
|
-
2.
|
|
66
|
-
3.
|
|
66
|
+
2. Check Context Graph reconciliation from OR, QA, review and current run state.
|
|
67
|
+
3. If reconciliation is `open_gap`, report the delivery status as not cleanly handoff-ready and do not derive commit-ready Git text.
|
|
68
|
+
4. Derive Git handoff only when code changes exist and no unresolved Context Graph gap remains.
|
|
69
|
+
5. Set exactly one next delivery step:
|
|
67
70
|
- offer commit
|
|
68
71
|
- offer push
|
|
69
72
|
- offer PR
|
|
@@ -71,13 +74,15 @@ If code-change status is unclear, do not claim a commit handoff.
|
|
|
71
74
|
- run QA/review
|
|
72
75
|
- obtain UAT/approval
|
|
73
76
|
- perform documentation follow-up
|
|
74
|
-
|
|
77
|
+
- resolve Context Graph gap
|
|
78
|
+
6. Set quality outlook:
|
|
75
79
|
- no further technical follow-up
|
|
76
80
|
- more tests
|
|
77
81
|
- refactoring
|
|
78
82
|
- documentation sharpening
|
|
79
83
|
- monitoring/runtime verification
|
|
80
|
-
|
|
84
|
+
- Context Graph reconciliation
|
|
85
|
+
7. If `Approval: UAT` exists, code changes were delivered, and no Context Graph gap remains, actively offer the commit but do not run it.
|
|
81
86
|
|
|
82
87
|
## Output
|
|
83
88
|
For code-changing runs:
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: delivery-path-search
|
|
3
|
+
description: Use this skill for high-impact planning decisions when several materially different next delivery steps are plausible and comparing scope, risk, evidence, tests, cost and gate readiness would reduce expensive rework. Do not use for routine tasks, during implementation, or as gate permission.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Delivery Path Search
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Search a bounded set of possible delivery paths before implementation and return one safest evidence-backed next step.
|
|
11
|
+
|
|
12
|
+
The search is advisory and read-only. Canonical AGDF `gate-check` remains the only authority for whether the recommended step may proceed.
|
|
13
|
+
|
|
14
|
+
## Runtime Contract
|
|
15
|
+
|
|
16
|
+
Use `../../meta/agdf-runtime-contract.md` for canonical gate state, output discipline and Delivery Path Search boundaries. This skill must not maintain a second gate or scoring model.
|
|
17
|
+
|
|
18
|
+
## Trigger
|
|
19
|
+
|
|
20
|
+
Use only when at least one applies:
|
|
21
|
+
|
|
22
|
+
- high product, architecture, security, policy, persistence or release impact
|
|
23
|
+
- several materially different next actions are plausible
|
|
24
|
+
- a wrong decision would cause expensive rework
|
|
25
|
+
- the best evidence-gathering or test action is unclear
|
|
26
|
+
|
|
27
|
+
Skip for routine questions, obvious local fixes and approved implementation with one clear next action.
|
|
28
|
+
|
|
29
|
+
## Workflow
|
|
30
|
+
|
|
31
|
+
1. Run AGDF gate-check and inspect durable control state.
|
|
32
|
+
2. Confirm that search is allowed and implementation is not occurring during exploration.
|
|
33
|
+
3. Declare the active surface and its enforcement level.
|
|
34
|
+
4. Invoke the shared CLI runtime:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx --yes @agdf/cli@latest delivery-path-search --surface <surface> --json
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
5. Treat facts, repository evidence, assumptions and model judgements separately.
|
|
41
|
+
6. Return exactly one recommendation or `no_safe_recommendation`.
|
|
42
|
+
7. Run canonical AGDF gate-check after search. Never translate a recommendation into permission.
|
|
43
|
+
|
|
44
|
+
## Enforcement
|
|
45
|
+
|
|
46
|
+
Report exactly one:
|
|
47
|
+
|
|
48
|
+
- `full`: trusted lifecycle controls prevent writes
|
|
49
|
+
- `tool_enforced`: the evaluator receives read/evaluation tools only
|
|
50
|
+
- `instruction_only`: write prevention is instructional and not technically proven
|
|
51
|
+
|
|
52
|
+
Do not overstate the surface's guarantee.
|
|
53
|
+
|
|
54
|
+
## Output
|
|
55
|
+
|
|
56
|
+
Keep chat output compact:
|
|
57
|
+
|
|
58
|
+
- recommendation or `no_safe_recommendation`
|
|
59
|
+
- current gate
|
|
60
|
+
- enforcement level
|
|
61
|
+
- decisive evidence and assumptions
|
|
62
|
+
- rejected alternatives and reasons
|
|
63
|
+
- budgets and stopping reason
|
|
64
|
+
- next AGDF gate action
|
|
65
|
+
|
|
66
|
+
Persist only the redacted decision summary when durable evidence is required. Do not persist raw prompts, hidden reasoning, secrets or source snapshots.
|
|
67
|
+
|
|
68
|
+
## Boundaries
|
|
69
|
+
|
|
70
|
+
- This is bounded Delivery Path Search, not MCTS.
|
|
71
|
+
- Do not modify repository files during search.
|
|
72
|
+
- Do not execute evaluator-returned commands.
|
|
73
|
+
- Do not invent default scores for invalid evaluator output.
|
|
74
|
+
- Do not implement, approve or release based on search output.
|
|
75
|
+
- Do not create agent-specific scoring, gate logic or skill copies.
|
|
@@ -44,6 +44,8 @@ Use the Runtime Contract definition of `Relevant Run` to decide whether OR is ma
|
|
|
44
44
|
10. `CD+Tests` is not completion.
|
|
45
45
|
11. When moving a backlog item to Completed or Superseded, use the canonical human-readable table and link the final OR with a document-relative Markdown link.
|
|
46
46
|
12. Keep machine status normalization in the CLI; do not write internal snake_case status values into the human-facing backlog.
|
|
47
|
+
13. Reconcile Context Graph impact before clean closeout: report `context_graph_reconciliation: resolved | not_applicable | open_gap`.
|
|
48
|
+
14. If Context Graph work remains unresolved, report it as an explicit open gap and do not describe the run as cleanly handoff-ready.
|
|
47
49
|
|
|
48
50
|
## When To Use
|
|
49
51
|
- at the end of every relevant run
|
|
@@ -89,10 +91,11 @@ If information is missing, state the gap instead of guessing.
|
|
|
89
91
|
6. Summarize Brownfield fit and solution integrity if reviewed.
|
|
90
92
|
7. Summarize tests and verification.
|
|
91
93
|
8. Summarize documentation and Context Graph impact if relevant.
|
|
92
|
-
9.
|
|
93
|
-
10.
|
|
94
|
-
11. Set exactly one
|
|
95
|
-
12.
|
|
94
|
+
9. Record Context Graph reconciliation as `resolved`, `not_applicable`, or `open_gap`.
|
|
95
|
+
10. Name retained fallbacks and exit criteria.
|
|
96
|
+
11. Set exactly one next permissible step.
|
|
97
|
+
12. Set exactly one quality outlook.
|
|
98
|
+
13. State whether `delivery-closeout` is the next operational handoff step when code changes exist and the delivery state allows it.
|
|
96
99
|
|
|
97
100
|
## Output
|
|
98
101
|
Use a compact structure:
|
|
@@ -114,6 +117,7 @@ Use a compact structure:
|
|
|
114
117
|
```
|
|
115
118
|
|
|
116
119
|
When Context Graph impact is relevant, include the fields from `../../meta/agdf-runtime-contract.md`.
|
|
120
|
+
Include `context_graph_reconciliation` whenever Context Graph impact is present. If the value is `open_gap`, required next step must resolve or explicitly retain that gap before commit-ready or release-ready handoff.
|
|
117
121
|
|
|
118
122
|
## Forbidden
|
|
119
123
|
This skill must not:
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { validateCandidate } from "./contracts.js";
|
|
2
|
+
|
|
3
|
+
function normalized(value) {
|
|
4
|
+
return String(value).toLowerCase().replace(/[`*_]/g, "").replace(/\s+/g, " ").trim();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function candidateLegality(candidateValue, input) {
|
|
8
|
+
const candidate = validateCandidate(candidateValue);
|
|
9
|
+
const action = normalized(candidate.action);
|
|
10
|
+
const forbiddenMatch = input.forbidden_actions.find((item) => {
|
|
11
|
+
const forbidden = normalized(item);
|
|
12
|
+
return forbidden && action === forbidden;
|
|
13
|
+
});
|
|
14
|
+
if (forbiddenMatch) return { legal: false, reason: `forbidden_by_gate: ${forbiddenMatch}`, candidate };
|
|
15
|
+
|
|
16
|
+
const allowedMatch = input.allowed_actions.some((item) => {
|
|
17
|
+
const allowed = normalized(item);
|
|
18
|
+
return allowed && action === allowed;
|
|
19
|
+
});
|
|
20
|
+
if (!allowedMatch) return { legal: false, reason: "not_in_allowed_actions", candidate };
|
|
21
|
+
return { legal: true, reason: "allowed_by_current_gate", candidate };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function candidatesFromInput(input) {
|
|
25
|
+
return input.allowed_actions.slice(0, input.budgets.max_candidates).map((action, index) => ({
|
|
26
|
+
id: `candidate-${index + 1}`,
|
|
27
|
+
action,
|
|
28
|
+
expected_evidence: input.evidence_refs,
|
|
29
|
+
tests: [],
|
|
30
|
+
assumptions: [],
|
|
31
|
+
depth: 0,
|
|
32
|
+
parent_id: null,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export const CONTRACT_VERSION = "1";
|
|
2
|
+
export const SCORING_POLICY_VERSION = "1";
|
|
3
|
+
export const SCORE_DIMENSIONS = [
|
|
4
|
+
"scope_fit",
|
|
5
|
+
"gate_readiness",
|
|
6
|
+
"risk_reduction",
|
|
7
|
+
"evidence_gain",
|
|
8
|
+
"testability",
|
|
9
|
+
"reversibility",
|
|
10
|
+
"cost",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
function requireObject(value, label) {
|
|
14
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be an object`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function requireString(value, label) {
|
|
19
|
+
if (typeof value !== "string" || !value.trim()) throw new Error(`${label} must be a non-empty string`);
|
|
20
|
+
return value.trim();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function stringArray(value, label) {
|
|
24
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) throw new Error(`${label} must be a string array`);
|
|
25
|
+
return value.map((item) => item.trim()).filter(Boolean);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function validateSearchInput(value) {
|
|
29
|
+
const input = requireObject(value, "search input");
|
|
30
|
+
if (input.contract_version !== CONTRACT_VERSION) throw new Error(`unsupported search input contract_version: ${input.contract_version}`);
|
|
31
|
+
requireString(input.scope_key, "scope_key");
|
|
32
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(input.scope_key) || input.scope_key.includes("..")) {
|
|
33
|
+
throw new Error("scope_key must be a safe path segment");
|
|
34
|
+
}
|
|
35
|
+
requireString(input.objective, "objective");
|
|
36
|
+
requireString(input.current_gate, "current_gate");
|
|
37
|
+
stringArray(input.allowed_actions, "allowed_actions");
|
|
38
|
+
stringArray(input.forbidden_actions, "forbidden_actions");
|
|
39
|
+
stringArray(input.evidence_refs ?? [], "evidence_refs");
|
|
40
|
+
stringArray(input.risks ?? [], "risks");
|
|
41
|
+
validateEnforcement(input.enforcement);
|
|
42
|
+
const budgets = requireObject(input.budgets, "budgets");
|
|
43
|
+
for (const key of ["max_candidates", "max_depth", "max_evaluations", "max_duration_ms", "max_cost_units", "stability_window"]) {
|
|
44
|
+
if (!Number.isInteger(budgets[key]) || budgets[key] < 1) throw new Error(`budgets.${key} must be a positive integer`);
|
|
45
|
+
}
|
|
46
|
+
return structuredClone(input);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function validateCandidate(value) {
|
|
50
|
+
const candidate = requireObject(value, "candidate");
|
|
51
|
+
requireString(candidate.id, "candidate.id");
|
|
52
|
+
requireString(candidate.action, "candidate.action");
|
|
53
|
+
stringArray(candidate.expected_evidence ?? [], "candidate.expected_evidence");
|
|
54
|
+
stringArray(candidate.tests ?? [], "candidate.tests");
|
|
55
|
+
stringArray(candidate.assumptions ?? [], "candidate.assumptions");
|
|
56
|
+
return structuredClone(candidate);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function validateEvaluation(value, candidateId) {
|
|
60
|
+
const evaluation = requireObject(value, "evaluation");
|
|
61
|
+
if (evaluation.contract_version !== CONTRACT_VERSION) throw new Error(`unsupported evaluator contract_version: ${evaluation.contract_version}`);
|
|
62
|
+
if (evaluation.candidate_id !== candidateId) throw new Error(`evaluation candidate_id must be ${candidateId}`);
|
|
63
|
+
for (const dimension of SCORE_DIMENSIONS) {
|
|
64
|
+
if (!Number.isInteger(evaluation[dimension]) || evaluation[dimension] < 0 || evaluation[dimension] > 5) {
|
|
65
|
+
throw new Error(`${dimension} must be an integer from 0 to 5`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!Number.isInteger(evaluation.uncertainty) || evaluation.uncertainty < 0 || evaluation.uncertainty > 5) {
|
|
69
|
+
throw new Error("uncertainty must be an integer from 0 to 5");
|
|
70
|
+
}
|
|
71
|
+
requireString(evaluation.rationale, "evaluation.rationale");
|
|
72
|
+
stringArray(evaluation.risks ?? [], "evaluation.risks");
|
|
73
|
+
stringArray(evaluation.assumptions ?? [], "evaluation.assumptions");
|
|
74
|
+
stringArray(evaluation.child_actions ?? [], "evaluation.child_actions");
|
|
75
|
+
if (/(^|\s)(rm|sudo|curl|wget|bash|sh|exec)\s/i.test(evaluation.rationale)) {
|
|
76
|
+
throw new Error("evaluation rationale contains executable instructions");
|
|
77
|
+
}
|
|
78
|
+
return structuredClone(evaluation);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function validateEnforcement(value) {
|
|
82
|
+
const enforcement = requireObject(value, "enforcement");
|
|
83
|
+
if (!["full", "tool_enforced", "instruction_only"].includes(enforcement.level)) {
|
|
84
|
+
throw new Error("enforcement.level must be full, tool_enforced or instruction_only");
|
|
85
|
+
}
|
|
86
|
+
const evidence = stringArray(enforcement.evidence ?? [], "enforcement.evidence");
|
|
87
|
+
if (enforcement.level !== "instruction_only" && evidence.length === 0) {
|
|
88
|
+
throw new Error(`${enforcement.level} requires enforcement evidence`);
|
|
89
|
+
}
|
|
90
|
+
return { level: enforcement.level, evidence };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function evaluatorOutputSchema() {
|
|
94
|
+
const scoreProperties = Object.fromEntries(SCORE_DIMENSIONS.map((key) => [key, { type: "integer", minimum: 0, maximum: 5 }]));
|
|
95
|
+
return {
|
|
96
|
+
type: "object",
|
|
97
|
+
additionalProperties: false,
|
|
98
|
+
required: ["contract_version", "candidate_id", ...SCORE_DIMENSIONS, "uncertainty", "rationale", "risks", "assumptions", "child_actions"],
|
|
99
|
+
properties: {
|
|
100
|
+
contract_version: { type: "string", const: CONTRACT_VERSION },
|
|
101
|
+
candidate_id: { type: "string" },
|
|
102
|
+
...scoreProperties,
|
|
103
|
+
uncertainty: { type: "integer", minimum: 0, maximum: 5 },
|
|
104
|
+
rationale: { type: "string", minLength: 1, maxLength: 1000 },
|
|
105
|
+
risks: { type: "array", items: { type: "string" } },
|
|
106
|
+
assumptions: { type: "array", items: { type: "string" } },
|
|
107
|
+
child_actions: { type: "array", items: { type: "string" }, maxItems: 5 },
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { evaluatorOutputSchema, validateEvaluation } from "../contracts.js";
|
|
6
|
+
|
|
7
|
+
export function codexEvaluator(options = {}) {
|
|
8
|
+
const codexBin = options.codexBin ?? "codex";
|
|
9
|
+
let runtime = "codex version unavailable";
|
|
10
|
+
try {
|
|
11
|
+
runtime = execFileSync(codexBin, ["--version"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
12
|
+
} catch {}
|
|
13
|
+
|
|
14
|
+
function gitState() {
|
|
15
|
+
try {
|
|
16
|
+
return execFileSync("git", ["status", "--porcelain=v1", "-z"], {
|
|
17
|
+
cwd: options.cwd,
|
|
18
|
+
encoding: "utf8",
|
|
19
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
20
|
+
});
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
name: "codex",
|
|
28
|
+
metadata: { name: "codex", runtime, model: options.model ?? "configured-default" },
|
|
29
|
+
async evaluate(input, candidate) {
|
|
30
|
+
const temp = mkdtempSync(join(tmpdir(), "agdf-dps-"));
|
|
31
|
+
const schemaPath = join(temp, "schema.json");
|
|
32
|
+
const outputPath = join(temp, "output.json");
|
|
33
|
+
try {
|
|
34
|
+
writeFileSync(schemaPath, `${JSON.stringify(evaluatorOutputSchema(), null, 2)}\n`, "utf8");
|
|
35
|
+
const prompt = [
|
|
36
|
+
"You are an evaluation-only component. Do not use tools, execute commands, or modify files.",
|
|
37
|
+
`Return JSON matching contract version ${input.contract_version}.`,
|
|
38
|
+
`Objective: ${input.objective}`,
|
|
39
|
+
`Current gate: ${input.current_gate}`,
|
|
40
|
+
`Candidate id: ${candidate.id}`,
|
|
41
|
+
`Candidate action: ${candidate.action}`,
|
|
42
|
+
"Score scope_fit, gate_readiness, risk_reduction, evidence_gain, testability, reversibility and cost from 0 to 5.",
|
|
43
|
+
"Cost 0 is low and 5 is high. uncertainty is 0 low to 5 high.",
|
|
44
|
+
"Keep rationale concise. child_actions must only contain actions permitted by the current gate.",
|
|
45
|
+
].join("\n");
|
|
46
|
+
const args = [
|
|
47
|
+
"exec", "--sandbox", "read-only", "--ephemeral", "--ignore-user-config",
|
|
48
|
+
"--output-schema", schemaPath, "--output-last-message", outputPath, "--color", "never",
|
|
49
|
+
];
|
|
50
|
+
if (options.model) args.push("--model", options.model);
|
|
51
|
+
args.push(prompt);
|
|
52
|
+
const before = gitState();
|
|
53
|
+
execFileSync(codexBin, args, {
|
|
54
|
+
cwd: options.cwd,
|
|
55
|
+
encoding: "utf8",
|
|
56
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
57
|
+
timeout: options.timeoutMs ?? 120000,
|
|
58
|
+
});
|
|
59
|
+
const after = gitState();
|
|
60
|
+
if (before !== null && after !== before) throw new Error("repository mutation detected during read-only evaluator run");
|
|
61
|
+
return validateEvaluation(JSON.parse(readFileSync(outputPath, "utf8")), candidate.id);
|
|
62
|
+
} finally {
|
|
63
|
+
rmSync(temp, { recursive: true, force: true });
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validateEvaluation } from "../contracts.js";
|
|
2
|
+
|
|
3
|
+
export function fixtureEvaluator(evaluations) {
|
|
4
|
+
return {
|
|
5
|
+
name: "fixture",
|
|
6
|
+
metadata: { name: "fixture", runtime: "deterministic-test" },
|
|
7
|
+
async evaluate(_input, candidate) {
|
|
8
|
+
const value = evaluations[candidate.id];
|
|
9
|
+
if (!value) throw new Error(`missing fixture evaluation for ${candidate.id}`);
|
|
10
|
+
return validateEvaluation(value, candidate.id);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
function safeResult(result) {
|
|
5
|
+
return JSON.parse(JSON.stringify(result, (key, value) => {
|
|
6
|
+
if (/(prompt|hidden_reasoning|secret|credential|source_snapshot)/i.test(key)) return undefined;
|
|
7
|
+
return value;
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function persistSearchResult(targetDir, result) {
|
|
12
|
+
const root = join(targetDir, ".agdf", "control", "artefacts", result.scope_key);
|
|
13
|
+
const jsonPath = join(root, "DELIVERY_PATH_SEARCH.json");
|
|
14
|
+
const markdownPath = join(root, "DELIVERY_PATH_SEARCH.md");
|
|
15
|
+
mkdirSync(dirname(jsonPath), { recursive: true });
|
|
16
|
+
const safe = safeResult(result);
|
|
17
|
+
writeFileSync(jsonPath, `${JSON.stringify(safe, null, 2)}\n`, "utf8");
|
|
18
|
+
const recommendation = safe.recommendation?.action ?? "No safe recommendation";
|
|
19
|
+
writeFileSync(markdownPath, [
|
|
20
|
+
"# Delivery Path Search Decision",
|
|
21
|
+
"",
|
|
22
|
+
`- status: ${safe.status}`,
|
|
23
|
+
`- current_gate: ${safe.current_gate}`,
|
|
24
|
+
`- enforcement: ${safe.enforcement.level}`,
|
|
25
|
+
`- recommendation: ${recommendation}`,
|
|
26
|
+
`- stopping_reason: ${safe.stopping_reason}`,
|
|
27
|
+
`- evaluations: ${safe.budgets.evaluations}`,
|
|
28
|
+
`- next_gate_action: ${safe.next_gate_action}`,
|
|
29
|
+
"",
|
|
30
|
+
"This summary contains model judgements, not measured facts. Canonical AGDF gate-check remains authoritative.",
|
|
31
|
+
"",
|
|
32
|
+
].join("\n"), "utf8");
|
|
33
|
+
return { jsonPath, markdownPath };
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SCORING_POLICY_VERSION } from "./contracts.js";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_WEIGHTS = Object.freeze({
|
|
4
|
+
scope_fit: 3,
|
|
5
|
+
gate_readiness: 3,
|
|
6
|
+
risk_reduction: 2,
|
|
7
|
+
evidence_gain: 2,
|
|
8
|
+
testability: 2,
|
|
9
|
+
reversibility: 1,
|
|
10
|
+
cost: -1,
|
|
11
|
+
uncertainty: -2,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const enforcementPenalty = { full: 0, tool_enforced: 1, instruction_only: 4 };
|
|
15
|
+
|
|
16
|
+
export function scoreEvaluation(evaluation, enforcementLevel, weights = DEFAULT_WEIGHTS) {
|
|
17
|
+
const contributions = Object.fromEntries(Object.entries(weights).map(([key, weight]) => [key, evaluation[key] * weight]));
|
|
18
|
+
const penalty = enforcementPenalty[enforcementLevel] ?? 4;
|
|
19
|
+
const score = Object.values(contributions).reduce((sum, value) => sum + value, 0) - penalty;
|
|
20
|
+
return { score, contributions, enforcement_penalty: penalty, scoring_policy_version: SCORING_POLICY_VERSION };
|
|
21
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { CONTRACT_VERSION, SCORING_POLICY_VERSION, validateEvaluation, validateSearchInput } from "./contracts.js";
|
|
2
|
+
import { candidateLegality, candidatesFromInput } from "./candidate-policy.js";
|
|
3
|
+
import { scoreEvaluation } from "./scoring.js";
|
|
4
|
+
|
|
5
|
+
export async function runDeliveryPathSearch(inputValue, evaluator, options = {}) {
|
|
6
|
+
const input = validateSearchInput(inputValue);
|
|
7
|
+
const startedAt = Date.now();
|
|
8
|
+
const queue = [...(options.candidates ?? candidatesFromInput(input))];
|
|
9
|
+
const rejected = [];
|
|
10
|
+
const evaluated = [];
|
|
11
|
+
let evaluations = 0;
|
|
12
|
+
let costUnits = 0;
|
|
13
|
+
let lastLeaderId = null;
|
|
14
|
+
let stableComparisons = 0;
|
|
15
|
+
let stoppingReason = "candidate_queue_exhausted";
|
|
16
|
+
|
|
17
|
+
while (queue.length > 0) {
|
|
18
|
+
if (evaluations >= input.budgets.max_evaluations) { stoppingReason = "evaluation_budget_exhausted"; break; }
|
|
19
|
+
if (costUnits >= input.budgets.max_cost_units) { stoppingReason = "cost_budget_exhausted"; break; }
|
|
20
|
+
if (Date.now() - startedAt >= input.budgets.max_duration_ms) { stoppingReason = "duration_budget_exhausted"; break; }
|
|
21
|
+
const candidate = queue.shift();
|
|
22
|
+
const legality = candidateLegality(candidate, input);
|
|
23
|
+
if (!legality.legal) {
|
|
24
|
+
rejected.push({ candidate_id: candidate.id, action: candidate.action, reason: legality.reason });
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const evaluation = validateEvaluation(await evaluator.evaluate(input, candidate), candidate.id);
|
|
30
|
+
evaluations += 1;
|
|
31
|
+
costUnits += evaluation.cost;
|
|
32
|
+
const scored = scoreEvaluation(evaluation, input.enforcement.level);
|
|
33
|
+
evaluated.push({ candidate, evaluation, ...scored });
|
|
34
|
+
const currentLeader = [...evaluated].sort((a, b) => b.score - a.score || a.candidate.id.localeCompare(b.candidate.id))[0];
|
|
35
|
+
if (currentLeader?.candidate.id === lastLeaderId) stableComparisons += 1;
|
|
36
|
+
else stableComparisons = 1;
|
|
37
|
+
lastLeaderId = currentLeader?.candidate.id ?? null;
|
|
38
|
+
if (evaluated.length > 1 && stableComparisons >= input.budgets.stability_window) {
|
|
39
|
+
stoppingReason = "stable_leader";
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
if ((candidate.depth ?? 0) + 1 < input.budgets.max_depth) {
|
|
43
|
+
for (const [index, action] of evaluation.child_actions.slice(0, input.budgets.max_candidates).entries()) {
|
|
44
|
+
queue.push({
|
|
45
|
+
id: `${candidate.id}.${index + 1}`,
|
|
46
|
+
parent_id: candidate.id,
|
|
47
|
+
depth: (candidate.depth ?? 0) + 1,
|
|
48
|
+
action,
|
|
49
|
+
expected_evidence: [],
|
|
50
|
+
tests: [],
|
|
51
|
+
assumptions: evaluation.assumptions,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
rejected.push({ candidate_id: candidate.id, action: candidate.action, reason: `invalid_evaluation: ${error.message}` });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
evaluated.sort((a, b) => b.score - a.score || a.candidate.id.localeCompare(b.candidate.id));
|
|
61
|
+
const leader = evaluated[0];
|
|
62
|
+
if (!leader) stoppingReason = rejected.length ? "no_safe_candidate" : stoppingReason;
|
|
63
|
+
return {
|
|
64
|
+
contract_version: CONTRACT_VERSION,
|
|
65
|
+
scoring_policy_version: SCORING_POLICY_VERSION,
|
|
66
|
+
scope_key: input.scope_key,
|
|
67
|
+
current_gate: input.current_gate,
|
|
68
|
+
status: leader ? "recommendation" : "no_safe_recommendation",
|
|
69
|
+
recommendation: leader ? {
|
|
70
|
+
candidate_id: leader.candidate.id,
|
|
71
|
+
action: leader.candidate.action,
|
|
72
|
+
score: leader.score,
|
|
73
|
+
rationale: leader.evaluation.rationale,
|
|
74
|
+
expected_evidence: leader.candidate.expected_evidence,
|
|
75
|
+
tests: leader.candidate.tests,
|
|
76
|
+
risks: leader.evaluation.risks,
|
|
77
|
+
assumptions: leader.evaluation.assumptions,
|
|
78
|
+
} : null,
|
|
79
|
+
alternatives: evaluated.slice(1).map((item) => ({
|
|
80
|
+
candidate_id: item.candidate.id,
|
|
81
|
+
action: item.candidate.action,
|
|
82
|
+
score: item.score,
|
|
83
|
+
rejection_reason: `ranked_below_${leader?.candidate.id ?? "safety_threshold"}`,
|
|
84
|
+
})),
|
|
85
|
+
rejected,
|
|
86
|
+
enforcement: input.enforcement,
|
|
87
|
+
evaluator: evaluator.metadata ?? { name: evaluator.name ?? "unknown" },
|
|
88
|
+
budgets: { configured: input.budgets, evaluations, cost_units: costUnits, stable_comparisons: stableComparisons, duration_ms: Date.now() - startedAt },
|
|
89
|
+
stopping_reason: stoppingReason,
|
|
90
|
+
next_gate_action: "Run canonical AGDF gate-check; search does not grant permission.",
|
|
91
|
+
};
|
|
92
|
+
}
|