@punks/cli 3.3.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/BASELINE_CHANGELOG.md +10 -2
  2. package/dist/CHANGELOG.md +22 -0
  3. package/dist/baseline/scaffold-baseline/baseline.json +5 -5
  4. package/dist/baseline/scaffold-baseline/data/catalog/lint-assets.json +5 -0
  5. package/dist/baseline/scaffold-baseline/data/catalog/packs.json +3 -0
  6. package/dist/baseline/scaffold-baseline/data/catalog/skills.json +24 -0
  7. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/SKILL.md +20 -4
  8. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +14 -9
  9. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/backlog-sync.md +61 -29
  10. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/plan-schema.md +25 -6
  11. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/SKILL.md +10 -4
  12. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/readiness.md +4 -0
  13. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/SKILL.md +20 -1
  14. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/lifecycle.md +20 -3
  15. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/wayfinder/SKILL.md +13 -36
  16. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/EXAMPLES.md +42 -26
  17. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/REFERENCE.md +80 -97
  18. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/SKILL.md +93 -96
  19. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +43 -52
  20. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/concepts/story-shape.md +70 -136
  21. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/backlog-initialization.md +88 -0
  22. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/business-projection.md +31 -0
  23. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/delivery-status.md +66 -0
  24. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/fog-intake.md +72 -0
  25. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/functional-projection.md +27 -0
  26. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/issue-reconciliation.md +76 -0
  27. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/normalization.md +105 -0
  28. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/project-context.md +43 -0
  29. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/providers/github.md +168 -0
  30. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/providers/linear.md +190 -0
  31. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/technical-projection.md +65 -0
  32. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/scripts/validate-task-blocker-graph.mjs +137 -0
  33. package/dist/baseline/scaffold-baseline/skills/phases/business-finder/SKILL.md +30 -0
  34. package/dist/baseline/scaffold-baseline/skills/phases/business-finder/agents/openai.yaml +2 -0
  35. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/backlog.md +10 -3
  36. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/closeout.md +12 -0
  37. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/implement.md +21 -0
  38. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +8 -0
  39. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/artifact-state.md +18 -3
  40. package/dist/baseline/scaffold-baseline/skills/phases/design-phase/phases/backlog.md +9 -1
  41. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/AUTHORING-HANDOFF.md +276 -0
  42. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/SKILL.md +43 -51
  43. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/agents/openai.yaml +1 -1
  44. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/adopt-business-path.md +52 -0
  45. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/business-grilling.md +68 -0
  46. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/ensure-fog.md +43 -0
  47. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/functional-grilling.md +53 -0
  48. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/handback.md +36 -0
  49. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/prototype.md +40 -0
  50. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/reconcile.md +52 -0
  51. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/research.md +38 -0
  52. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/return-target.md +42 -0
  53. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/router.md +64 -0
  54. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/technical-grilling.md +67 -0
  55. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/entrypoint-contract.md +38 -0
  56. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/root-routing.md +14 -27
  57. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/runtime-handoff.md +62 -0
  58. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/state-graph.md +60 -0
  59. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/scripts/finder-contract.mjs +383 -0
  60. package/dist/baseline/scaffold-baseline/skills/phases/functional-finder/SKILL.md +78 -0
  61. package/dist/baseline/scaffold-baseline/skills/phases/functional-finder/agents/openai.yaml +2 -0
  62. package/dist/baseline/scaffold-baseline/skills/phases/technical-finder/SKILL.md +74 -0
  63. package/dist/baseline/scaffold-baseline/skills/phases/technical-finder/agents/openai.yaml +2 -0
  64. package/dist/baseline/scaffold-baseline.json +5 -5
  65. package/dist/baseline/scaffold-baseline.tgz +0 -0
  66. package/dist/index.js +69 -71
  67. package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +20 -4
  68. package/dist/skills/agnostic/planning/create-plan/SKILL.md +14 -9
  69. package/dist/skills/agnostic/planning/create-plan/references/backlog-sync.md +61 -29
  70. package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +25 -6
  71. package/dist/skills/agnostic/planning/create-spec/SKILL.md +10 -4
  72. package/dist/skills/agnostic/planning/create-spec/references/readiness.md +4 -0
  73. package/dist/skills/agnostic/planning/implement-spec/SKILL.md +20 -1
  74. package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +20 -3
  75. package/dist/skills/agnostic/planning/wayfinder/SKILL.md +13 -36
  76. package/dist/skills/agnostic/requirements/write-backlog/EXAMPLES.md +42 -26
  77. package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +80 -97
  78. package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +93 -96
  79. package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +43 -52
  80. package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/story-shape.md +70 -136
  81. package/dist/skills/agnostic/requirements/write-backlog/references/backlog-initialization.md +88 -0
  82. package/dist/skills/agnostic/requirements/write-backlog/references/business-projection.md +31 -0
  83. package/dist/skills/agnostic/requirements/write-backlog/references/delivery-status.md +66 -0
  84. package/dist/skills/agnostic/requirements/write-backlog/references/fog-intake.md +72 -0
  85. package/dist/skills/agnostic/requirements/write-backlog/references/functional-projection.md +27 -0
  86. package/dist/skills/agnostic/requirements/write-backlog/references/issue-reconciliation.md +76 -0
  87. package/dist/skills/agnostic/requirements/write-backlog/references/normalization.md +105 -0
  88. package/dist/skills/agnostic/requirements/write-backlog/references/project-context.md +43 -0
  89. package/dist/skills/agnostic/requirements/write-backlog/references/providers/github.md +168 -0
  90. package/dist/skills/agnostic/requirements/write-backlog/references/providers/linear.md +190 -0
  91. package/dist/skills/agnostic/requirements/write-backlog/references/technical-projection.md +65 -0
  92. package/dist/skills/agnostic/requirements/write-backlog/scripts/validate-task-blocker-graph.mjs +135 -0
  93. package/dist/skills/phases/business-finder/SKILL.md +30 -0
  94. package/dist/skills/phases/business-finder/agents/openai.yaml +2 -0
  95. package/dist/skills/phases/delivery-phase/phases/backlog.md +10 -3
  96. package/dist/skills/phases/delivery-phase/phases/closeout.md +12 -0
  97. package/dist/skills/phases/delivery-phase/phases/implement.md +21 -0
  98. package/dist/skills/phases/delivery-phase/phases/router.md +8 -0
  99. package/dist/skills/phases/delivery-phase/references/artifact-state.md +18 -3
  100. package/dist/skills/phases/design-phase/phases/backlog.md +9 -1
  101. package/dist/skills/phases/finder-phase/AUTHORING-HANDOFF.md +276 -0
  102. package/dist/skills/phases/finder-phase/SKILL.md +43 -51
  103. package/dist/skills/phases/finder-phase/agents/openai.yaml +1 -1
  104. package/dist/skills/phases/finder-phase/phases/adopt-business-path.md +52 -0
  105. package/dist/skills/phases/finder-phase/phases/business-grilling.md +68 -0
  106. package/dist/skills/phases/finder-phase/phases/ensure-fog.md +43 -0
  107. package/dist/skills/phases/finder-phase/phases/functional-grilling.md +53 -0
  108. package/dist/skills/phases/finder-phase/phases/handback.md +36 -0
  109. package/dist/skills/phases/finder-phase/phases/prototype.md +40 -0
  110. package/dist/skills/phases/finder-phase/phases/reconcile.md +52 -0
  111. package/dist/skills/phases/finder-phase/phases/research.md +38 -0
  112. package/dist/skills/phases/finder-phase/phases/return-target.md +42 -0
  113. package/dist/skills/phases/finder-phase/phases/router.md +64 -0
  114. package/dist/skills/phases/finder-phase/phases/technical-grilling.md +67 -0
  115. package/dist/skills/phases/finder-phase/references/entrypoint-contract.md +38 -0
  116. package/dist/skills/phases/finder-phase/references/root-routing.md +14 -27
  117. package/dist/skills/phases/finder-phase/references/runtime-handoff.md +62 -0
  118. package/dist/skills/phases/finder-phase/references/state-graph.md +60 -0
  119. package/dist/skills/phases/finder-phase/scripts/finder-contract.mjs +383 -0
  120. package/dist/skills/phases/functional-finder/SKILL.md +78 -0
  121. package/dist/skills/phases/functional-finder/agents/openai.yaml +2 -0
  122. package/dist/skills/phases/technical-finder/SKILL.md +74 -0
  123. package/dist/skills/phases/technical-finder/agents/openai.yaml +2 -0
  124. package/package.json +4 -2
  125. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/convergence.md +0 -39
  126. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/frontier-lifecycle.md +0 -76
  127. package/dist/skills/phases/finder-phase/references/convergence.md +0 -39
  128. package/dist/skills/phases/finder-phase/references/frontier-lifecycle.md +0 -76
@@ -0,0 +1,67 @@
1
+ # Technical Grilling Gate
2
+
3
+ ## Entry guard
4
+
5
+ Target depth is Technical, Functional projection readback exists, and the
6
+ selected Story lacks valid Technical evidence.
7
+
8
+ ## Inputs
9
+
10
+ Exact Fog, accepted Business and Functional evidence, one stable Story identity,
11
+ current Technical children, and wrapper presentation profile.
12
+
13
+ ## Bounded action
14
+
15
+ 1. Read every Technical-stage child for the selected Story. Resume reuses the
16
+ exact child and its durable wiki/provider identities.
17
+ 2. When none exists, allocate and persist one durable Technical grilling-child
18
+ wiki identity. Authorize its child shell by the exact Fog identity, Stage
19
+ `Technical`, and stable Story identity. Send that child-shell ensure intent
20
+ to `$write-backlog` and require exact readback before technical grilling.
21
+ This ensure does not require accepted grilling evidence. Ambiguity or
22
+ duplicate child identity for the Story produces zero writes and routes to
23
+ human steering.
24
+ 3. Activate one full `$requirements-grill` on the ensured Technical child for
25
+ this Story. The requirements authority owns technical decision closure.
26
+ 4. Persist the immutable accepted resolution for that Technical child.
27
+ 5. Invoke `$create-spec` with the Story identity and accepted Business,
28
+ Functional, and Technical evidence.
29
+ 6. Require a returned SPEC with `readiness: agent-ready` and a verified stable
30
+ blob URL before continuing.
31
+ 7. Derive a nonempty Task intent containing at least one atomic Task and its
32
+ blocker relationships from that authoritative SPEC.
33
+ 8. Only then emit one semantic technical projection intent to `$write-backlog`
34
+ for exact Task and relation readback. Require its successful
35
+ `validate-task-blocker-graph` result over the full reachable graph, resolved
36
+ milestone order, and resulting provider snapshot.
37
+
38
+ ## Invariants
39
+
40
+ This gate owns stage identity, ordering, and resume. The requirements authority
41
+ owns technical decisions, `$create-spec` owns compilation, and `$write-backlog`
42
+ owns provider mutation. `spec-not-ready` or missing verified stable blob returns
43
+ zero projection and zero target-depth return, then routes to human steering.
44
+ Empty Task intent does the same. Resume reuses the exact child; ambiguity or
45
+ duplicate identity produces zero writes and routes to human steering.
46
+
47
+ ## Completion evidence
48
+
49
+ One exact Technical child for the Story, immutable accepted resolution pointer,
50
+ agent-ready SPEC, verified stable blob URL, nonempty Task intent, semantic
51
+ projection intent, exact Task/relation readback, and the successful
52
+ full-reachable Task graph validator result bound to that provider snapshot.
53
+
54
+ ## Declared exits
55
+
56
+ - `technical_accepted` -> reconciliation.
57
+ - `support_required` -> Research or Prototype through router re-entry.
58
+ - `spec-not-ready` -> handback with zero projection.
59
+ - `task_intent_empty` -> handback with zero projection.
60
+ - `human_steering_required` -> handback.
61
+ - `blocked` -> stop with missing evidence.
62
+
63
+ ## Durable handoff
64
+
65
+ Persist Story and durable Technical child wiki/provider identities before the
66
+ grill, then the immutable resolution pointer, SPEC stable blob URL, readiness,
67
+ Task intent, support relations, projection/readback state, and exit.
@@ -0,0 +1,38 @@
1
+ # Direct-Composition Contract
2
+
3
+ ## Inputs
4
+
5
+ - target depth: exactly `Business`, `Functional`, or `Technical`
6
+ - request and accepted audience-specific context
7
+ - optional stable provider Fog identity or durable wiki Fog identity
8
+ - wrapper presentation profile
9
+ - optional durable runtime-handoff locator
10
+
11
+ The invoking wrapper stays in control while loading this engine. It supplies no
12
+ route, lifecycle state, or provider mutation instructions.
13
+
14
+ ## Shared Invariants
15
+
16
+ - One invocation creates or resumes exactly one Fog.
17
+ - Fog is lateral provenance, never a parent in the product hierarchy.
18
+ - One Fog owns exactly one Business grilling child, one or more Functional
19
+ children, and one Technical child per Story.
20
+ - Research and Prototype are direct Fog children that support named grilling
21
+ children. They cannot authorize backlog projection.
22
+ - Current provider and immutable evidence defeat stale artifacts and route
23
+ suggestions.
24
+ - Functional or Technical depth may adopt an exact existing Product Area ->
25
+ Initiative -> Epic path only after the human accepts `reuse-unchanged`; the
26
+ engine still persists one exact Business child and immutable resolution.
27
+ - Ambiguous identity or conflicting accepted evidence produces zero writes and
28
+ routes to human steering.
29
+ - Reaching target depth returns control without completing the Fog.
30
+
31
+ ## Return
32
+
33
+ Return the stable Fog identities, target depth reached, accepted stage child
34
+ identities and immutable resolution pointers, created-or-enriched provider
35
+ object identities from exact readback, unresolved support evidence, and the
36
+ durable handoff locator. Business returns exactly one Business child;
37
+ Functional returns one or more Functional children selected for this
38
+ invocation; Technical returns exactly one Technical child per selected Story.
@@ -1,35 +1,22 @@
1
- # Root Routing
1
+ # Root Routing Boundary
2
2
 
3
- ## Trigger
3
+ Finder entry is human-only. Root guidance may explain the three choices and
4
+ return an exact explicit invocation, then stops:
4
5
 
5
- Route to `finder-phase` before `requirements-phase` when a loose idea is too large for one agent session and still wrapped in fog.
6
+ - `$business-finder` for Business depth.
7
+ - `$functional-finder` for cumulative Business and Functional depth.
8
+ - `$technical-finder` for cumulative Business, Functional, and Technical depth.
6
9
 
7
- Use this route when the first question is not "which requirement is unclear?"
8
- but "which concept and child flow can close this frontier?"
10
+ Root or model routing never starts a Finder wrapper or `finder-phase`.
11
+ `finder-phase` is the wrappers' shared direct-composition engine and internal
12
+ resume target.
9
13
 
10
- ## Placement In Root Guidance
11
-
12
- Keep root prompt guidance short:
13
-
14
- - Foggy oversized work routes to `finder-phase` first.
15
- - Unclear requirements inside a bounded topic route to `requirements-phase`.
16
- - Accepted specs, issues, or plans route to `delivery-phase`.
17
- - Runtime failures route to `debugging-phase`.
18
- - Review requests persist the bounded target and accepted-bounds context, then
19
- point the operator to the exact explicit `$review-phase` invocation.
20
- - Docs learning after proven changes routes to `docs-ingest-phase`.
21
-
22
- ## Boundary
23
-
24
- `finder-phase` should not replace:
25
-
26
- - `requirements-phase` for human decision closure inside a known topic.
27
- - `parallel-research` for split-friendly readonly investigation.
28
- - `prototype-phase` for human-evaluated artifact-driven learning.
29
- - `create-spec`, `create-plan`, or `delivery-phase` after implementation scope is accepted.
30
-
31
- It chooses the route and updates the frontier handoff.
14
+ Unclear requirements inside accepted bounded scope remain requirements work.
15
+ Accepted specs, issues, or plans remain delivery work. Runtime failures remain
16
+ debugging work. Docs learning after proven changes remains docs-ingest work.
32
17
 
18
+ Review requests persist the bounded target and accepted-bounds context, then
19
+ point the operator to the exact explicit `$review-phase` invocation.
33
20
  `finder-phase`, root routing, and `delivery-phase` never invoke, delegate to, or
34
21
  model-select `review-phase`. They may only persist its input context, return the
35
22
  exact explicit `$review-phase` instruction, and stop.
@@ -0,0 +1,62 @@
1
+ # Runtime Handoff
2
+
3
+ Store the current record at
4
+ `.devpunks/finder-phase/handoffs/<durable-wiki-fog-id>.md`. Before provider
5
+ creation, allocate that durable wiki identity once and use it for every retry.
6
+ After exact provider readback, add the stable provider Fog identity without
7
+ replacing the wiki identity.
8
+
9
+ ```text
10
+ Phase:
11
+ Status: complete | blocked | skipped | checkpoint | human_steering_required
12
+ Scope:
13
+ Artifacts:
14
+ Validation:
15
+ Finder state:
16
+ UI Evidence:
17
+ Next suggested route:
18
+ Blockers:
19
+ Resume identity:
20
+
21
+ Finder target depth:
22
+ Durable wiki Fog identity:
23
+ Provider Fog identity:
24
+ Provider snapshot identity:
25
+ Selected gate or outcome:
26
+ Stage child identities:
27
+ Immutable resolution pointers:
28
+ Business path identities:
29
+ Business path decision:
30
+ Intended projection:
31
+ Exact readback identities:
32
+ Business hierarchy readback:
33
+ Functional Story placement readback:
34
+ Technical Task graph readback:
35
+ Technical Task graph validator result:
36
+ Support evidence:
37
+ Checkpoint or blocker:
38
+ Last verified at:
39
+ ```
40
+
41
+ Discover by exact durable wiki or provider Fog identity. Conflicting valid
42
+ records for one identity are `human_steering_required`. `Suggested route` is
43
+ advisory; the router always recomputes from fresh evidence.
44
+
45
+ `Finder state` is the workflow-specific domain-state field. `UI Evidence` is
46
+ optional and records any retained `$show-me` artifact. `Next suggested route`
47
+ is advisory.
48
+
49
+ Each gate updates only fields it proves. Preserve prior exact identities and
50
+ immutable pointers. Record checkpoint, blocked, skip, target-return, and
51
+ `human_steering_required` outcomes before stopping.
52
+
53
+ Business hierarchy readback names the exact Product Area, Initiative, and Epic
54
+ identities plus exact parent membership. Functional Story placement readback
55
+ names the Story, parent Epic, contextual `V*` milestone, exact milestone
56
+ membership, and exact Fog and source links. Technical Task graph readback names
57
+ each Task, its parent Story, the same `V*` milestone as that Story, and the exact
58
+ provider snapshot. Technical Task graph validator result preserves the
59
+ successful `write-backlog/validate-task-blocker-graph` result over every
60
+ reachable Story and Task, the resolved milestone-order readback, and its bound
61
+ provider snapshot identity. It covers every returned Task and outgoing edge;
62
+ connected blockers may live under other Stories or Epics.
@@ -0,0 +1,60 @@
1
+ # Finder State Graph
2
+
3
+ ## Evidence Authority
4
+
5
+ 1. Current direct provider, repository, and wiki evidence.
6
+ 2. Fresh workflow-native artifacts and immutable resolution pointers.
7
+ 3. Valid committed runtime handoff.
8
+ 4. Suggested route.
9
+
10
+ The first admissible signal wins. Stale, invalid, ambiguous, or out-of-scope
11
+ evidence cannot satisfy a gate.
12
+
13
+ ## Topology
14
+
15
+ ```text
16
+ ensure-fog
17
+ -> (business-grilling <-> research | prototype) | adopt-business-path
18
+ -> reconcile
19
+ -> return-target [Business]
20
+ -> functional-grilling <-> research | prototype
21
+ -> reconcile
22
+ -> return-target [Functional]
23
+ -> technical-grilling per Story <-> research | prototype
24
+ -> reconcile
25
+ -> return-target [Technical]
26
+
27
+ any identity or authority conflict -> handback -> human_steering_required
28
+ scope boundary expansion -> scope-expansion-checkpoint -> router re-entry
29
+ ```
30
+
31
+ `adopt-business-path` is available only for Functional or Technical depth when
32
+ the human supplies exact provider readback for one Product Area -> Initiative
33
+ -> Epic path and accepts `reuse-unchanged`. It creates the required Business
34
+ child and immutable resolution without a Business grill, then rejoins normal
35
+ reconciliation.
36
+
37
+ `return-target` is successful return from this invocation, not Fog completion.
38
+ The Fog remains open until separate production evidence covers all accepted
39
+ resulting Stories and Tasks.
40
+
41
+ ## State Evidence
42
+
43
+ For each stage, record `missing`, `active`, `accepted`, or `invalid`; its exact
44
+ child identity; immutable resolution pointer; supported-by relations; intended
45
+ semantic projection; and exact provider readback. Accepted state without an
46
+ exact child identity or immutable pointer is an authority conflict. Business
47
+ completion requires exactly one valid Business child from the fresh complete
48
+ direct-child collection and exact Product Area -> Initiative -> Epic identity
49
+ and hierarchy readback. Functional completion requires each Story's exact
50
+ parent Epic, contextual `V*` milestone membership, and Fog/source links. Every
51
+ selected Technical Story must equal the distinct projected Story of one
52
+ selected accepted Functional child. Technical completion also requires every
53
+ Task to retain its Story milestone and the exact successful result of
54
+ `write-backlog`'s provider-neutral validator over the full reachable Task
55
+ graph, resolved milestone order, and current provider snapshot. The result must
56
+ cover every projected Task and outgoing edge. It rejects future-iteration,
57
+ self, missing-target, duplicate, and cyclic edges while preserving valid
58
+ same-or-earlier-milestone blockers across Stories and Epics. Invalid stage
59
+ evidence routes to that stage again. Accepted evidence without readback routes
60
+ to reconciliation.
@@ -0,0 +1,383 @@
1
+ const DEPTHS = ["Business", "Functional", "Technical"];
2
+ const CONFLICT_IDENTITIES = ["ambiguous", "duplicate", "conflict"];
3
+ const isStableIdentity = (value) => typeof value === "string" && value.trim().length > 0;
4
+
5
+ const hasExactBusinessProjection = (child) =>
6
+ isStableIdentity(child?.projectedProductArea) &&
7
+ isStableIdentity(child.projectedInitiative) &&
8
+ isStableIdentity(child.projectedEpic) &&
9
+ child.hierarchyReadback === "exact";
10
+
11
+ const businessChildCollectionConflicts = (children) => {
12
+ if (!Array.isArray(children)) return false;
13
+ return (
14
+ children.length > 1 ||
15
+ children.some(
16
+ (child) =>
17
+ !child ||
18
+ child.identity !== "exact" ||
19
+ (child.status === "accepted" &&
20
+ child.scope === "in-scope" &&
21
+ child.projection === "read-back" &&
22
+ !hasExactBusinessProjection(child)),
23
+ )
24
+ );
25
+ };
26
+
27
+ const deriveBusinessStageRoute = (state) => {
28
+ if (!Array.isArray(state.businessChildren)) {
29
+ return state.business === "accepted" ? "human-steering" : "business-grilling";
30
+ }
31
+ if (state.businessChildren.length === 0) {
32
+ return state.business === "accepted" ? "human-steering" : "business-grilling";
33
+ }
34
+
35
+ const [child] = state.businessChildren;
36
+ if (child.status !== "accepted" || child.scope !== "in-scope") {
37
+ return "business-grilling";
38
+ }
39
+ if (child.resolution !== "immutable") return "human-steering";
40
+ if (child.projection !== "read-back") return "reconcile";
41
+ if (!hasExactBusinessProjection(child)) return "human-steering";
42
+ return "ready";
43
+ };
44
+
45
+ const childCollectionConflicts = (children, foreignKey) => {
46
+ if (!Array.isArray(children)) return false;
47
+
48
+ const seen = new Set();
49
+ for (const child of children) {
50
+ if (!child || CONFLICT_IDENTITIES.includes(child.identity)) return true;
51
+ const key = child[foreignKey];
52
+ if (!isStableIdentity(key)) return true;
53
+ if (seen.has(key)) return true;
54
+ seen.add(key);
55
+ }
56
+
57
+ return false;
58
+ };
59
+
60
+ const functionalProjectionConflicts = (children, businessChildren) => {
61
+ if (!Array.isArray(children)) return false;
62
+
63
+ const projectedEpic = businessChildren?.[0]?.projectedEpic;
64
+ const stories = new Set();
65
+ for (const child of children) {
66
+ if (
67
+ child?.status !== "accepted" ||
68
+ child.scope !== "in-scope" ||
69
+ child.projection !== "read-back"
70
+ ) {
71
+ continue;
72
+ }
73
+ if (
74
+ !isStableIdentity(projectedEpic) ||
75
+ !isStableIdentity(child.projectedStory) ||
76
+ child.projectedStoryParentEpic !== projectedEpic ||
77
+ !isStableIdentity(child.projectedStoryMilestone) ||
78
+ child.projectedStoryMilestoneKind !== "V*" ||
79
+ child.projectedStoryFogLink !== "exact" ||
80
+ child.projectedStorySourceLink !== "exact" ||
81
+ child.projectedStoryMembershipReadback !== "exact"
82
+ ) {
83
+ return true;
84
+ }
85
+ if (stories.has(child.projectedStory)) return true;
86
+ stories.add(child.projectedStory);
87
+ }
88
+ return false;
89
+ };
90
+
91
+ const hasExactWriterTaskGraphValidation = (state, projectedTasks) => {
92
+ const validation = state.taskGraphValidation;
93
+ const result = validation?.result;
94
+ if (
95
+ !isStableIdentity(state.providerSnapshotIdentity) ||
96
+ validation?.validator !== "write-backlog/validate-task-blocker-graph" ||
97
+ validation.scope !== "full-reachable" ||
98
+ validation.milestoneOrderReadback !== "exact" ||
99
+ validation.providerSnapshotIdentity !== state.providerSnapshotIdentity ||
100
+ result?.ok !== true ||
101
+ !Array.isArray(result.taskIds) ||
102
+ !Array.isArray(result.edges)
103
+ ) {
104
+ return false;
105
+ }
106
+
107
+ const validatedTaskIds = new Set();
108
+ for (const taskId of result.taskIds) {
109
+ if (!isStableIdentity(taskId) || validatedTaskIds.has(taskId)) return false;
110
+ validatedTaskIds.add(taskId);
111
+ }
112
+
113
+ const validatedEdges = new Set();
114
+ for (const edge of result.edges) {
115
+ if (
116
+ !isStableIdentity(edge?.blockedTaskId) ||
117
+ !isStableIdentity(edge.blockingTaskId) ||
118
+ !validatedTaskIds.has(edge.blockedTaskId) ||
119
+ !validatedTaskIds.has(edge.blockingTaskId)
120
+ ) {
121
+ return false;
122
+ }
123
+ const key = `${edge.blockedTaskId}\u0000${edge.blockingTaskId}`;
124
+ if (validatedEdges.has(key)) return false;
125
+ validatedEdges.add(key);
126
+ }
127
+
128
+ const projectedTaskIds = new Set(projectedTasks.map((task) => task.id));
129
+ const projectedEdges = new Set();
130
+ for (const task of projectedTasks) {
131
+ if (!validatedTaskIds.has(task.id)) return false;
132
+ for (const blockingTaskId of task.blockedBy) {
133
+ if (!validatedTaskIds.has(blockingTaskId)) return false;
134
+ projectedEdges.add(`${task.id}\u0000${blockingTaskId}`);
135
+ }
136
+ }
137
+ if ([...projectedEdges].some((edge) => !validatedEdges.has(edge))) {
138
+ return false;
139
+ }
140
+ if (
141
+ [...validatedEdges].some((edge) => {
142
+ const [blockedTaskId] = edge.split("\u0000");
143
+ return projectedTaskIds.has(blockedTaskId) && !projectedEdges.has(edge);
144
+ })
145
+ ) {
146
+ return false;
147
+ }
148
+
149
+ return true;
150
+ };
151
+
152
+ const technicalProjectionConflicts = (state) => {
153
+ const children = state.technicalChildren;
154
+ const functionalChildren = state.functionalChildren;
155
+ if (!Array.isArray(children)) return false;
156
+
157
+ const storyMilestones = new Map(
158
+ (Array.isArray(functionalChildren) ? functionalChildren : [])
159
+ .filter(
160
+ (child) =>
161
+ child?.status === "accepted" &&
162
+ child.scope === "in-scope" &&
163
+ child.projection === "read-back" &&
164
+ isStableIdentity(child.projectedStory) &&
165
+ isStableIdentity(child.projectedStoryMilestone),
166
+ )
167
+ .map((child) => [child.projectedStory, child.projectedStoryMilestone]),
168
+ );
169
+ const taskIds = new Set();
170
+ const tasks = [];
171
+ for (const child of children) {
172
+ if (
173
+ child?.status !== "accepted" ||
174
+ child.scope !== "in-scope" ||
175
+ child.projection !== "read-back"
176
+ ) {
177
+ continue;
178
+ }
179
+ const storyMilestone = storyMilestones.get(child.story);
180
+ if (
181
+ !isStableIdentity(storyMilestone) ||
182
+ child.taskGraphReadback !== "exact" ||
183
+ !Array.isArray(child.projectedTasks) ||
184
+ child.projectedTasks.length !== child.taskIntentCount
185
+ ) {
186
+ return true;
187
+ }
188
+ for (const task of child.projectedTasks) {
189
+ if (
190
+ !task ||
191
+ !isStableIdentity(task.id) ||
192
+ task.story !== child.story ||
193
+ task.milestone !== storyMilestone ||
194
+ task.readback !== "exact" ||
195
+ !Array.isArray(task.blockedBy) ||
196
+ task.blockedBy.some((identity) => !isStableIdentity(identity)) ||
197
+ taskIds.has(task.id)
198
+ ) {
199
+ return true;
200
+ }
201
+ taskIds.add(task.id);
202
+ tasks.push(task);
203
+ }
204
+ }
205
+ if (tasks.length === 0) return false;
206
+
207
+ for (const task of tasks) {
208
+ if (
209
+ new Set(task.blockedBy).size !== task.blockedBy.length ||
210
+ task.blockedBy.includes(task.id)
211
+ ) {
212
+ return true;
213
+ }
214
+ }
215
+ return !hasExactWriterTaskGraphValidation(state, tasks);
216
+ };
217
+
218
+ const technicalSelectionConflicts = ({
219
+ selectedStoryIntents,
220
+ selectedStories,
221
+ functionalChildren,
222
+ }) => {
223
+ if (!Array.isArray(selectedStories) || selectedStories.length === 0) {
224
+ return false;
225
+ }
226
+
227
+ const selectedIntents = new Set(Array.isArray(selectedStoryIntents) ? selectedStoryIntents : []);
228
+ const selectedFunctionalChildren = (
229
+ Array.isArray(functionalChildren) ? functionalChildren : []
230
+ ).filter(
231
+ (child) =>
232
+ selectedIntents.has(child.storyIntent) &&
233
+ child.status === "accepted" &&
234
+ child.scope === "in-scope" &&
235
+ child.projection === "read-back",
236
+ );
237
+
238
+ return (
239
+ new Set(selectedStories).size !== selectedStories.length ||
240
+ selectedStories.some(
241
+ (story) =>
242
+ !isStableIdentity(story) ||
243
+ selectedFunctionalChildren.filter((child) => child.projectedStory === story).length !== 1,
244
+ )
245
+ );
246
+ };
247
+
248
+ const deriveChildStageRoute = ({
249
+ selected,
250
+ children,
251
+ foreignKey,
252
+ grillingRoute,
253
+ validateAcceptedChild = () => true,
254
+ }) => {
255
+ if (!Array.isArray(selected)) return grillingRoute;
256
+ if (selected.length === 0) return grillingRoute;
257
+ if (new Set(selected).size !== selected.length) return "human-steering";
258
+
259
+ const matchesBySelected = selected.map((selectedIdentity) =>
260
+ (Array.isArray(children) ? children : []).filter(
261
+ (child) => child[foreignKey] === selectedIdentity,
262
+ ),
263
+ );
264
+
265
+ if (
266
+ matchesBySelected.some(
267
+ (matches) =>
268
+ matches.length > 1 || matches.some((child) => CONFLICT_IDENTITIES.includes(child.identity)),
269
+ )
270
+ ) {
271
+ return "human-steering";
272
+ }
273
+
274
+ if (
275
+ matchesBySelected
276
+ .filter(
277
+ (matches) =>
278
+ matches.length === 1 &&
279
+ matches[0].status === "accepted" &&
280
+ matches[0].scope === "in-scope",
281
+ )
282
+ .some(
283
+ ([child]) =>
284
+ child.identity !== "exact" ||
285
+ child.resolution !== "immutable" ||
286
+ !validateAcceptedChild(child),
287
+ )
288
+ ) {
289
+ return "human-steering";
290
+ }
291
+
292
+ if (
293
+ matchesBySelected
294
+ .filter(
295
+ (matches) =>
296
+ matches.length === 1 &&
297
+ matches[0].status === "accepted" &&
298
+ matches[0].scope === "in-scope",
299
+ )
300
+ .some(([child]) => child.projection !== "read-back")
301
+ ) {
302
+ return "reconcile";
303
+ }
304
+
305
+ if (
306
+ matchesBySelected.some(
307
+ (matches) =>
308
+ matches.length !== 1 || matches[0].status !== "accepted" || matches[0].scope !== "in-scope",
309
+ )
310
+ ) {
311
+ return grillingRoute;
312
+ }
313
+
314
+ return "ready";
315
+ };
316
+
317
+ export const deriveFinderRoute = (state) => {
318
+ if (!DEPTHS.includes(state.targetDepth)) return "human-steering";
319
+ if (state.humanSteering === "required") return "human-steering";
320
+ if (CONFLICT_IDENTITIES.includes(state.fogIdentity)) {
321
+ return "human-steering";
322
+ }
323
+ if (
324
+ businessChildCollectionConflicts(state.businessChildren) ||
325
+ childCollectionConflicts(state.functionalChildren, "storyIntent") ||
326
+ childCollectionConflicts(state.technicalChildren, "story") ||
327
+ functionalProjectionConflicts(state.functionalChildren, state.businessChildren) ||
328
+ technicalProjectionConflicts(state)
329
+ ) {
330
+ return "human-steering";
331
+ }
332
+ if (state.fogIdentity !== "exact") return "ensure-fog";
333
+ if (CONFLICT_IDENTITIES.includes(state.businessIdentity)) {
334
+ return "human-steering";
335
+ }
336
+ if (state.acceptedEvidence === "conflict") return "human-steering";
337
+ if (state.scopeExpansion === "approval-required") {
338
+ return "scope-expansion-checkpoint";
339
+ }
340
+ if (state.support === "research") return "research";
341
+ if (state.support === "prototype") return "prototype";
342
+ if (state.businessEvidenceScope === "out-of-scope") {
343
+ return "business-grilling";
344
+ }
345
+ if (state.business !== "accepted") {
346
+ if (
347
+ state.targetDepth !== "Business" &&
348
+ state.business === "missing" &&
349
+ state.businessPathIdentity === "exact" &&
350
+ state.businessPathDecision === "reuse-unchanged"
351
+ ) {
352
+ return "adopt-business-path";
353
+ }
354
+ return "business-grilling";
355
+ }
356
+ const businessRoute = deriveBusinessStageRoute(state);
357
+ if (businessRoute !== "ready") return businessRoute;
358
+ if (state.targetDepth === "Business") return "return-target";
359
+
360
+ const functionalRoute = deriveChildStageRoute({
361
+ selected: state.selectedStoryIntents,
362
+ children: state.functionalChildren,
363
+ foreignKey: "storyIntent",
364
+ grillingRoute: "functional-grilling",
365
+ });
366
+ if (functionalRoute !== "ready") return functionalRoute;
367
+ if (state.targetDepth === "Functional") return "return-target";
368
+ if (technicalSelectionConflicts(state)) return "human-steering";
369
+
370
+ const technicalRoute = deriveChildStageRoute({
371
+ selected: state.selectedStories,
372
+ children: state.technicalChildren,
373
+ foreignKey: "story",
374
+ grillingRoute: "technical-grilling",
375
+ validateAcceptedChild: (child) =>
376
+ child.specReadiness === "agent-ready" &&
377
+ child.stableBlob === "verified" &&
378
+ Number.isInteger(child.taskIntentCount) &&
379
+ child.taskIntentCount > 0,
380
+ });
381
+ if (technicalRoute !== "ready") return technicalRoute;
382
+ return "return-target";
383
+ };