@deftai/directive-core 0.103.0 → 0.105.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 (255) hide show
  1. package/dist/authz/classify.js +682 -35
  2. package/dist/check/cached-orchestrator.d.ts +1 -1
  3. package/dist/check/cached-orchestrator.js +2 -2
  4. package/dist/check/gate-lists.d.ts +3 -2
  5. package/dist/check/gate-lists.js +5 -2
  6. package/dist/check/index.d.ts +1 -0
  7. package/dist/check/index.js +1 -0
  8. package/dist/check/named-cause.d.ts +1 -1
  9. package/dist/check/named-cause.js +33 -3
  10. package/dist/check/session-completed-ac.d.ts +39 -0
  11. package/dist/check/session-completed-ac.js +198 -0
  12. package/dist/codebase/default-extractor.d.ts +5 -0
  13. package/dist/codebase/default-extractor.js +7 -15
  14. package/dist/deposit/copy-tree.js +60 -0
  15. package/dist/deposit/python-free.js +26 -18
  16. package/dist/doctor/checks.d.ts +8 -0
  17. package/dist/doctor/checks.js +37 -25
  18. package/dist/doctor/doctor-state.d.ts +4 -0
  19. package/dist/doctor/doctor-state.js +7 -1
  20. package/dist/doctor/main.js +9 -14
  21. package/dist/doctor/types.d.ts +9 -0
  22. package/dist/fs/contained-write.d.ts +115 -1
  23. package/dist/fs/contained-write.js +242 -5
  24. package/dist/fs/mutation-ledger.d.ts +54 -0
  25. package/dist/fs/mutation-ledger.js +133 -0
  26. package/dist/fs/non-product-dirs.d.ts +79 -0
  27. package/dist/fs/non-product-dirs.js +96 -0
  28. package/dist/hooks/dispatcher.d.ts +3 -1
  29. package/dist/hooks/dispatcher.js +14 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.js +3 -0
  32. package/dist/init-deposit/agent-hooks.js +17 -15
  33. package/dist/init-deposit/core-guard-pin-content.d.ts +7 -0
  34. package/dist/init-deposit/core-guard-pin-content.js +393 -0
  35. package/dist/init-deposit/gitignore.js +9 -0
  36. package/dist/init-deposit/hygiene.d.ts +47 -11
  37. package/dist/init-deposit/hygiene.js +172 -37
  38. package/dist/init-deposit/legacy-detect.js +6 -2
  39. package/dist/init-deposit/refresh.d.ts +21 -1
  40. package/dist/init-deposit/refresh.js +106 -9
  41. package/dist/init-deposit/scaffold.js +28 -279
  42. package/dist/init-deposit/slash-deposit.js +13 -7
  43. package/dist/init-deposit/xbrief-projections.d.ts +8 -1
  44. package/dist/init-deposit/xbrief-projections.js +24 -11
  45. package/dist/intake/clause-derivation.d.ts +74 -0
  46. package/dist/intake/clause-derivation.js +409 -0
  47. package/dist/intake/index.d.ts +1 -0
  48. package/dist/intake/index.js +1 -0
  49. package/dist/intake/issue-ingest.d.ts +3 -1
  50. package/dist/intake/issue-ingest.js +36 -43
  51. package/dist/lifecycle/completed-tracked-on-delivery.d.ts +5 -0
  52. package/dist/lifecycle/completed-tracked-on-delivery.js +85 -18
  53. package/dist/literal-acceptance/capture.d.ts +10 -0
  54. package/dist/literal-acceptance/capture.js +224 -75
  55. package/dist/literal-acceptance/evaluate.d.ts +29 -4
  56. package/dist/literal-acceptance/evaluate.js +70 -2
  57. package/dist/literal-acceptance/index.d.ts +3 -3
  58. package/dist/literal-acceptance/index.js +3 -3
  59. package/dist/literal-acceptance/safety.d.ts +41 -0
  60. package/dist/literal-acceptance/safety.js +126 -2
  61. package/dist/literal-acceptance/types.d.ts +8 -0
  62. package/dist/orphan-active/evaluate.d.ts +7 -1
  63. package/dist/orphan-active/evaluate.js +102 -23
  64. package/dist/platform/platform-capabilities.js +2 -3
  65. package/dist/policy/base-branch.d.ts +37 -0
  66. package/dist/policy/base-branch.js +114 -0
  67. package/dist/policy/branch-sync.d.ts +80 -0
  68. package/dist/policy/branch-sync.js +211 -0
  69. package/dist/policy/ceremony-dial-escalation.js +1 -0
  70. package/dist/policy/ceremony-dial.js +4 -14
  71. package/dist/policy/delivery-branch.d.ts +5 -3
  72. package/dist/policy/delivery-branch.js +7 -3
  73. package/dist/policy/file-size-thresholds.d.ts +24 -0
  74. package/dist/policy/file-size-thresholds.js +23 -0
  75. package/dist/policy/forge-outage-retry.d.ts +47 -0
  76. package/dist/policy/forge-outage-retry.js +157 -0
  77. package/dist/policy/index.d.ts +7 -0
  78. package/dist/policy/index.js +66 -7
  79. package/dist/policy/project-invariants.d.ts +50 -0
  80. package/dist/policy/project-invariants.js +205 -0
  81. package/dist/policy/sync-default.d.ts +129 -0
  82. package/dist/policy/sync-default.js +452 -0
  83. package/dist/policy/sync-max-files.d.ts +93 -0
  84. package/dist/policy/sync-max-files.js +192 -0
  85. package/dist/pr-monitor/absent-required.d.ts +11 -0
  86. package/dist/pr-monitor/absent-required.js +61 -0
  87. package/dist/pr-monitor/constants.d.ts +7 -0
  88. package/dist/pr-monitor/constants.js +7 -0
  89. package/dist/pr-monitor/index.d.ts +2 -1
  90. package/dist/pr-monitor/index.js +2 -1
  91. package/dist/pr-monitor/main.js +4 -0
  92. package/dist/pr-monitor/monitor.js +24 -1
  93. package/dist/pr-wait-mergeable/classify.js +6 -0
  94. package/dist/preflight/evaluate.d.ts +9 -0
  95. package/dist/preflight/evaluate.js +49 -1
  96. package/dist/preflight/index.d.ts +5 -1
  97. package/dist/preflight/index.js +2 -0
  98. package/dist/preflight/intended-placement.d.ts +62 -0
  99. package/dist/preflight/intended-placement.js +275 -0
  100. package/dist/preflight/project-invariants-gate.d.ts +29 -0
  101. package/dist/preflight/project-invariants-gate.js +82 -0
  102. package/dist/product-first-done-gate/acceptance-resolver.d.ts +128 -0
  103. package/dist/product-first-done-gate/acceptance-resolver.js +144 -0
  104. package/dist/product-first-done-gate/acceptance.d.ts +7 -4
  105. package/dist/product-first-done-gate/acceptance.js +79 -8
  106. package/dist/product-first-done-gate/empty-resolution.d.ts +5 -2
  107. package/dist/product-first-done-gate/empty-resolution.js +13 -2
  108. package/dist/product-first-done-gate/evaluate.d.ts +29 -0
  109. package/dist/product-first-done-gate/evaluate.js +307 -33
  110. package/dist/product-first-done-gate/index.d.ts +3 -1
  111. package/dist/product-first-done-gate/index.js +2 -1
  112. package/dist/release/build-dist.d.ts +101 -0
  113. package/dist/release/build-dist.js +428 -46
  114. package/dist/run-summary/emit.d.ts +50 -4
  115. package/dist/run-summary/emit.js +262 -26
  116. package/dist/run-summary/index.d.ts +3 -2
  117. package/dist/run-summary/index.js +2 -1
  118. package/dist/run-summary/session-id.d.ts +21 -0
  119. package/dist/run-summary/session-id.js +92 -0
  120. package/dist/run-summary/share.d.ts +1 -1
  121. package/dist/run-summary/share.js +2 -2
  122. package/dist/run-summary/types.d.ts +38 -6
  123. package/dist/run-summary/types.js +1 -0
  124. package/dist/scope/acceptance-activate-gate.d.ts +1 -1
  125. package/dist/scope/acceptance-activate-gate.js +4 -4
  126. package/dist/scope/acceptance-evidence.d.ts +27 -0
  127. package/dist/scope/acceptance-evidence.js +66 -0
  128. package/dist/scope/capacity-stamp.d.ts +2 -0
  129. package/dist/scope/capacity-stamp.js +4 -0
  130. package/dist/scope/delivery-evidence.d.ts +9 -3
  131. package/dist/scope/delivery-evidence.js +39 -27
  132. package/dist/scope/index.d.ts +1 -0
  133. package/dist/scope/index.js +1 -0
  134. package/dist/scope/parent-lineage.js +7 -6
  135. package/dist/scope/project-invariant-coverage.d.ts +54 -0
  136. package/dist/scope/project-invariant-coverage.js +322 -0
  137. package/dist/scope/transition.js +66 -4
  138. package/dist/scope-provenance/compare-intent.d.ts +27 -0
  139. package/dist/scope-provenance/compare-intent.js +233 -0
  140. package/dist/scope-provenance/digest.d.ts +18 -1
  141. package/dist/scope-provenance/digest.js +16 -11
  142. package/dist/scope-provenance/evaluate.d.ts +5 -1
  143. package/dist/scope-provenance/evaluate.js +64 -4
  144. package/dist/scope-provenance/extract-intent.d.ts +43 -0
  145. package/dist/scope-provenance/extract-intent.js +262 -0
  146. package/dist/scope-provenance/index.d.ts +7 -1
  147. package/dist/scope-provenance/index.js +7 -1
  148. package/dist/scope-provenance/intent-digest.d.ts +12 -0
  149. package/dist/scope-provenance/intent-digest.js +33 -0
  150. package/dist/scope-provenance/intent-evaluate.d.ts +43 -0
  151. package/dist/scope-provenance/intent-evaluate.js +149 -0
  152. package/dist/scope-provenance/json-tokenizer.d.ts +19 -0
  153. package/dist/scope-provenance/json-tokenizer.js +225 -0
  154. package/dist/scope-provenance/known-machine.d.ts +38 -0
  155. package/dist/scope-provenance/known-machine.js +157 -0
  156. package/dist/scope-provenance/mint-artifacts.d.ts +102 -0
  157. package/dist/scope-provenance/mint-artifacts.js +425 -0
  158. package/dist/session/ac-pass-banking.d.ts +4 -36
  159. package/dist/session/ac-pass-banking.js +30 -77
  160. package/dist/session/ac-pass-reuse.d.ts +53 -0
  161. package/dist/session/ac-pass-reuse.js +95 -0
  162. package/dist/session/ceremony-dial-evidence.d.ts +42 -0
  163. package/dist/session/ceremony-dial-evidence.js +194 -0
  164. package/dist/session/git.js +19 -4
  165. package/dist/session/index.d.ts +5 -0
  166. package/dist/session/index.js +5 -0
  167. package/dist/session/occupancy-stress-worker.d.ts +7 -0
  168. package/dist/session/occupancy-stress-worker.js +36 -0
  169. package/dist/session/occupancy.d.ts +97 -0
  170. package/dist/session/occupancy.js +422 -0
  171. package/dist/session/openclaw-soft-rebind-deposit.js +6 -6
  172. package/dist/session/product-state-hash.d.ts +26 -0
  173. package/dist/session/product-state-hash.js +683 -0
  174. package/dist/session/session-ready.d.ts +2 -0
  175. package/dist/session/session-ready.js +52 -30
  176. package/dist/session/session-start.d.ts +7 -0
  177. package/dist/session/session-start.js +88 -5
  178. package/dist/session/verify-ac-session-cache.d.ts +42 -0
  179. package/dist/session/verify-ac-session-cache.js +126 -0
  180. package/dist/session/verify-session-ritual.d.ts +5 -0
  181. package/dist/session/verify-session-ritual.js +9 -0
  182. package/dist/slash/openclaw-deposit.js +13 -9
  183. package/dist/slice/constants.d.ts +2 -2
  184. package/dist/slice/constants.js +2 -2
  185. package/dist/slice/existing.js +21 -4
  186. package/dist/slice/lock.d.ts +16 -1
  187. package/dist/slice/lock.js +137 -11
  188. package/dist/slice/record.d.ts +8 -5
  189. package/dist/slice/record.js +21 -13
  190. package/dist/story-ready/evaluate.d.ts +2 -0
  191. package/dist/story-ready/evaluate.js +13 -0
  192. package/dist/swarm/complete-cohort.d.ts +3 -0
  193. package/dist/swarm/complete-cohort.js +59 -11
  194. package/dist/swarm/finalize-cohort.js +33 -2
  195. package/dist/swarm/launch.d.ts +22 -0
  196. package/dist/swarm/launch.js +155 -0
  197. package/dist/swarm/routing-set-cli.d.ts +11 -1
  198. package/dist/swarm/routing-set-cli.js +13 -3
  199. package/dist/swarm/routing-verify.d.ts +12 -0
  200. package/dist/swarm/routing-verify.js +59 -20
  201. package/dist/swarm/routing.d.ts +14 -0
  202. package/dist/swarm/routing.js +53 -3
  203. package/dist/telemetry-coverage/evaluate.d.ts +42 -0
  204. package/dist/telemetry-coverage/evaluate.js +148 -0
  205. package/dist/telemetry-coverage/fake-trial.d.ts +45 -0
  206. package/dist/telemetry-coverage/fake-trial.js +204 -0
  207. package/dist/telemetry-coverage/index.d.ts +5 -0
  208. package/dist/telemetry-coverage/index.js +5 -0
  209. package/dist/telemetry-coverage/kinds.d.ts +19 -0
  210. package/dist/telemetry-coverage/kinds.js +54 -0
  211. package/dist/telemetry-coverage/scan-callers.d.ts +25 -0
  212. package/dist/telemetry-coverage/scan-callers.js +168 -0
  213. package/dist/triage/actions/index.js +4 -1
  214. package/dist/ts-check-lane/index.d.ts +3 -0
  215. package/dist/ts-check-lane/index.js +2 -0
  216. package/dist/ts-check-lane/progress-reporter.d.ts +17 -0
  217. package/dist/ts-check-lane/progress-reporter.js +38 -0
  218. package/dist/ts-check-lane/progress.d.ts +32 -0
  219. package/dist/ts-check-lane/progress.js +57 -0
  220. package/dist/ts-check-lane/run-lane.d.ts +3 -1
  221. package/dist/ts-check-lane/run-lane.js +8 -6
  222. package/dist/validate-content/validate-links.d.ts +8 -0
  223. package/dist/validate-content/validate-links.js +9 -15
  224. package/dist/value/feedback-file.js +12 -2
  225. package/dist/vbrief-build/index.d.ts +1 -0
  226. package/dist/vbrief-build/index.js +1 -0
  227. package/dist/vbrief-build/project-invariants-io.d.ts +16 -0
  228. package/dist/vbrief-build/project-invariants-io.js +41 -0
  229. package/dist/vbrief-reconcile/graph.js +18 -1
  230. package/dist/vbrief-reconcile/index.d.ts +3 -1
  231. package/dist/vbrief-reconcile/index.js +2 -1
  232. package/dist/vbrief-reconcile/origin-freshness.d.ts +44 -0
  233. package/dist/vbrief-reconcile/origin-freshness.js +221 -0
  234. package/dist/vbrief-reconcile/types.d.ts +13 -0
  235. package/dist/vbrief-reconcile/umbrellas.d.ts +14 -0
  236. package/dist/vbrief-reconcile/umbrellas.js +261 -26
  237. package/dist/vbrief-validate/index.d.ts +1 -1
  238. package/dist/vbrief-validate/index.js +1 -1
  239. package/dist/vbrief-validate/plan-hooks.d.ts +4 -0
  240. package/dist/vbrief-validate/plan-hooks.js +68 -0
  241. package/dist/verify-ac/evaluate.d.ts +7 -1
  242. package/dist/verify-ac/evaluate.js +34 -26
  243. package/dist/verify-ac/flag.d.ts +4 -0
  244. package/dist/verify-ac/flag.js +16 -0
  245. package/dist/verify-ac/index.d.ts +2 -2
  246. package/dist/verify-ac/index.js +2 -2
  247. package/dist/verify-source/contained-writes.js +2 -0
  248. package/dist/verify-source/index.d.ts +1 -0
  249. package/dist/verify-source/index.js +1 -0
  250. package/dist/verify-source/verify-stubs.d.ts +15 -1
  251. package/dist/verify-source/verify-stubs.js +20 -16
  252. package/dist/vitest-runner/win32-coverage-tmp-setup.d.ts +5 -6
  253. package/dist/vitest-runner/win32-coverage-tmp-setup.js +5 -6
  254. package/dist/xbrief-migrate/migrate-project.js +2 -5
  255. package/package.json +3 -3
@@ -43,8 +43,6 @@ const ALLOWED_FIRST_TOKENS = new Set([
43
43
  "yarn",
44
44
  "bun",
45
45
  "vitest",
46
- "true",
47
- "false",
48
46
  ]);
49
47
  /**
50
48
  * Exact wrapper subcommands that are verification-shaped (no scope/policy/scm/swarm
@@ -65,6 +63,128 @@ const ALLOWED_WRAPPER_SUBCOMMANDS = new Set([
65
63
  * `verify:` / `verify-` cover task verify:* family; bare `verify ` is the space form.
66
64
  */
67
65
  const ALLOWED_WRAPPER_PREFIXES = ["verify:", "verify-", "verify "];
66
+ /** One remediation when a command cannot fail (#3396). */
67
+ export const NOOP_ACCEPTANCE_REMEDIATION = "acceptance commands must be able to fail; name a command that exercises the artifact";
68
+ /** Capture/stamp outcome recorded on the acceptance event (#3396). */
69
+ export const REJECTED_NOOP_OUTCOME = "rejected-noop";
70
+ /** First tokens that always succeed or always fail without exercising an artifact. */
71
+ const NOOP_FIRST_TOKENS = new Set(["true", "false", ":", "echo", "printf"]);
72
+ /** `test` operators that inspect a path (not a constant comparison). */
73
+ const TEST_FILE_OPERATORS = new Set([
74
+ "-b",
75
+ "-c",
76
+ "-d",
77
+ "-e",
78
+ "-f",
79
+ "-g",
80
+ "-h",
81
+ "-k",
82
+ "-L",
83
+ "-p",
84
+ "-r",
85
+ "-S",
86
+ "-s",
87
+ "-t",
88
+ "-u",
89
+ "-w",
90
+ "-x",
91
+ ]);
92
+ function firstTokenAndRest(trimmed) {
93
+ let end = 0;
94
+ while (end < trimmed.length && trimmed[end] !== " " && trimmed[end] !== "\t") {
95
+ end += 1;
96
+ }
97
+ return { first: trimmed.slice(0, end).toLowerCase(), rest: trimmed.slice(end).trim() };
98
+ }
99
+ function noopRefusal() {
100
+ return {
101
+ ok: false,
102
+ reason: NOOP_ACCEPTANCE_REMEDIATION,
103
+ outcome: REJECTED_NOOP_OUTCOME,
104
+ };
105
+ }
106
+ /**
107
+ * Unconditional no-ops cannot be acceptance oracles (#3396).
108
+ * `test` with only constant args is a no-op; `test -f path` is an assertion.
109
+ */
110
+ export function evaluateNoopDenylist(command) {
111
+ if (typeof command !== "string") {
112
+ return { ok: true, reason: null };
113
+ }
114
+ const trimmed = command.trim();
115
+ if (trimmed.length === 0) {
116
+ return { ok: true, reason: null };
117
+ }
118
+ const { first, rest } = firstTokenAndRest(trimmed);
119
+ if (NOOP_FIRST_TOKENS.has(first)) {
120
+ return noopRefusal();
121
+ }
122
+ if (first === "exit" && rest.length === 0) {
123
+ return noopRefusal();
124
+ }
125
+ if (first === "test") {
126
+ const tokens = rest.length === 0 ? [] : rest.split(/\s+/);
127
+ if (!tokens.some((token) => TEST_FILE_OPERATORS.has(token))) {
128
+ return noopRefusal();
129
+ }
130
+ }
131
+ return { ok: true, reason: null };
132
+ }
133
+ /** True when a refusal reason is the #3396 no-op remediation. */
134
+ export function isNoopRefusalReason(reason) {
135
+ return typeof reason === "string" && reason.includes("acceptance commands must be able to fail");
136
+ }
137
+ /**
138
+ * Capture records verbatim statement spans as fence@ / labeled@ / prompt@ / inline@.
139
+ * Metadata and plan.acceptance mirrors are not statement provenance.
140
+ */
141
+ export function isVerbatimStatementSpan(sourceSpan) {
142
+ if (typeof sourceSpan !== "string" || sourceSpan.trim().length === 0) {
143
+ return false;
144
+ }
145
+ return /^(fence|labeled|prompt|inline)@/i.test(sourceSpan.trim());
146
+ }
147
+ function commandHasStatementProvenance(cmd) {
148
+ if (cmd.source !== undefined && cmd.source !== "task_statement") {
149
+ return false;
150
+ }
151
+ return isVerbatimStatementSpan(cmd.sourceSpan ?? null);
152
+ }
153
+ /**
154
+ * Stamp-time no-op refuse + stated-only-with-span (#3396).
155
+ * A restamp cannot raise the rung to stated without a recorded statement span.
156
+ */
157
+ export function evaluateStampAcceptanceSafety(input) {
158
+ const hasVerbatimStatementSpan = input.commands.some(commandHasStatementProvenance);
159
+ let sourceRung;
160
+ if (input.commands.length === 0) {
161
+ sourceRung = input.previousRung ?? "project_floor";
162
+ }
163
+ else if (hasVerbatimStatementSpan) {
164
+ sourceRung = "stated";
165
+ }
166
+ else {
167
+ sourceRung = "derived";
168
+ }
169
+ for (const cmd of input.commands) {
170
+ const noop = evaluateNoopDenylist(cmd.command);
171
+ if (!noop.ok) {
172
+ return {
173
+ ok: false,
174
+ reason: noop.reason,
175
+ outcome: REJECTED_NOOP_OUTCOME,
176
+ sourceRung,
177
+ hasVerbatimStatementSpan,
178
+ };
179
+ }
180
+ }
181
+ return {
182
+ ok: true,
183
+ reason: null,
184
+ sourceRung,
185
+ hasVerbatimStatementSpan,
186
+ };
187
+ }
68
188
  /** Whether this provenance is allowed to spawn a shell (#3267). */
69
189
  export function isExecutableLiteralSource(source) {
70
190
  return EXECUTABLE_LITERAL_SOURCES.includes(source);
@@ -81,6 +201,10 @@ export function evaluateCommandSafety(command) {
81
201
  if (trimmed.length > 500) {
82
202
  return { ok: false, reason: "command exceeds 500 characters" };
83
203
  }
204
+ const noop = evaluateNoopDenylist(trimmed);
205
+ if (!noop.ok) {
206
+ return noop;
207
+ }
84
208
  for (let i = 0; i < trimmed.length; i += 1) {
85
209
  const ch = trimmed[i];
86
210
  if (SHELL_META_CHARS.has(ch)) {
@@ -63,6 +63,14 @@ export interface LiteralAcceptanceGateResult {
63
63
  readonly runs: readonly LiteralAcceptanceRunResult[];
64
64
  /** Safety-rejected shell-shaped lines (fail-loud ledger; may be empty). */
65
65
  readonly rejected?: readonly RejectedLiteralCommand[];
66
+ /**
67
+ * Prose/fence/inline-derived rejections demoted to advisory (#3484 / #3511).
68
+ * Reported, never blocking — consumers MUST NOT read these back as a blocking
69
+ * ledger, and must not sniff the rendered message for their reasons (#3497).
70
+ */
71
+ readonly advisoryRejected?: readonly RejectedLiteralCommand[];
72
+ /** Prompt lines skipped inside a transcript-shaped fence (#3511). */
73
+ readonly transcriptPromptSkipped?: number;
66
74
  }
67
75
  /** Metadata key for operator-visible rejected command ledger (#3267). */
68
76
  export declare const LITERAL_ACCEPTANCE_REJECTED_METADATA_KEY: "literal_acceptance_rejected";
@@ -1,8 +1,10 @@
1
1
  import type { RunGhFn } from "../pr-protected-issues/types.js";
2
2
  export type OutputStream = "stdout" | "stderr" | "none";
3
+ export type OrphanKind = "shipped" | "unresolved";
3
4
  export interface OrphanActiveBrief {
4
5
  readonly path: string;
5
6
  readonly reason: string;
7
+ readonly kind: OrphanKind;
6
8
  }
7
9
  export interface EvaluateResult {
8
10
  readonly code: 0 | 1 | 2;
@@ -15,11 +17,15 @@ export interface EvaluateOptions {
15
17
  readonly repo?: string | null;
16
18
  readonly runGh?: RunGhFn;
17
19
  readonly skipGh?: boolean;
20
+ /** When set, scan only active/running briefs that reference this issue (#3429). */
21
+ readonly issue?: number | null;
18
22
  }
19
23
  /**
20
- * Pure evaluator for orphaned active/running xBRIEF detection (#2321).
24
+ * Pure evaluator for orphaned active/running xBRIEF detection (#2321 / #3429).
21
25
  * Fails when active/ briefs with plan.status==running reference only closed
22
26
  * issues and/or a merged PR — the stop-at:pr-open orphan signature.
27
+ * Pass `issue` to scan one origin after merge. Confirmed shipped prints
28
+ * scope:complete; unresolved lookup still exits 1 with a retry remediation.
23
29
  */
24
30
  export declare function evaluate(projectRoot: string, options?: EvaluateOptions): EvaluateResult;
25
31
  //# sourceMappingURL=evaluate.d.ts.map
@@ -137,55 +137,127 @@ function fetchPrMerged(ref, runGh) {
137
137
  return null;
138
138
  }
139
139
  }
140
- function assessOrphanSignature(issueRefs, prRefs, projectRoot, runGh, skipGh) {
140
+ const PASS = { orphaned: false, reason: null, kind: null };
141
+ function shipped(reason) {
142
+ return { orphaned: true, reason, kind: "shipped" };
143
+ }
144
+ function unresolved(reason) {
145
+ return { orphaned: true, reason, kind: "unresolved" };
146
+ }
147
+ function assessOrphanSignature(issueRefs, prRefs, projectRoot, runGh, skipGh, selectedIssue) {
148
+ if (selectedIssue !== null) {
149
+ // Confirmed closed origin is shipped even if a linked PR lookup fails.
150
+ const selectedRef = issueRefs.find((ref) => ref.number === selectedIssue);
151
+ const selectedState = selectedRef === undefined ? null : resolveIssueState(selectedRef, projectRoot, runGh, skipGh);
152
+ if (selectedState === "closed") {
153
+ return shipped(`issue #${selectedIssue} is closed`);
154
+ }
155
+ for (const pr of prRefs) {
156
+ if (skipGh) {
157
+ return unresolved(`linked PR #${pr.number} state could not be resolved`);
158
+ }
159
+ const merged = fetchPrMerged(pr, runGh);
160
+ if (merged === true) {
161
+ return shipped(`linked PR #${pr.number} is merged`);
162
+ }
163
+ if (merged === null) {
164
+ return unresolved(`linked PR #${pr.number} state could not be resolved`);
165
+ }
166
+ }
167
+ // --issue N is one origin: sibling open/unknown must not mask it (#3429).
168
+ if (selectedRef !== undefined) {
169
+ if (selectedState === null) {
170
+ return unresolved(`issue #${selectedIssue} state could not be resolved`);
171
+ }
172
+ return PASS;
173
+ }
174
+ const issueStates = issueRefs.map((ref) => ({
175
+ ref,
176
+ state: resolveIssueState(ref, projectRoot, runGh, skipGh),
177
+ }));
178
+ const unknownIssue = issueStates.find((row) => row.state === null);
179
+ if (unknownIssue !== undefined) {
180
+ return unresolved(`issue #${unknownIssue.ref.number} state could not be resolved`);
181
+ }
182
+ if (issueStates.some((row) => row.state === "closed")) {
183
+ return shipped("all referenced issues are closed");
184
+ }
185
+ if (prRefs.length > 0 && skipGh) {
186
+ return unresolved(`linked PR #${prRefs[0]?.number} state could not be resolved`);
187
+ }
188
+ return PASS;
189
+ }
141
190
  for (const pr of prRefs) {
142
191
  if (skipGh) {
143
192
  continue;
144
193
  }
145
194
  const merged = fetchPrMerged(pr, runGh);
146
195
  if (merged === true) {
147
- return { orphaned: true, reason: `linked PR #${pr.number} is merged` };
196
+ return shipped(`linked PR #${pr.number} is merged`);
148
197
  }
149
198
  }
150
199
  if (issueRefs.length === 0) {
151
- return { orphaned: false, reason: null };
200
+ return PASS;
152
201
  }
153
202
  let resolved = 0;
154
203
  for (const ref of issueRefs) {
155
204
  const state = resolveIssueState(ref, projectRoot, runGh, skipGh);
156
205
  if (state === null) {
157
- return { orphaned: false, reason: null };
206
+ return PASS;
158
207
  }
159
208
  resolved += 1;
160
209
  if (state !== "closed") {
161
- return { orphaned: false, reason: null };
210
+ return PASS;
162
211
  }
163
212
  }
164
213
  if (resolved > 0) {
165
- return { orphaned: true, reason: "all referenced issues are closed" };
214
+ return shipped("all referenced issues are closed");
166
215
  }
167
- return { orphaned: false, reason: null };
216
+ return PASS;
168
217
  }
169
- function formatRefusal(orphans, projectRoot) {
170
- const lines = [
171
- `verify:orphan-active: ${orphans.length} active/running xBRIEF${orphans.length === 1 ? "" : "s"} look shipped but still consume WIP (project_root=${projectRoot}).`,
172
- " Remediation: move each brief out of active/ with lifecycle ownership:",
173
- " task scope:complete -- xbrief/active/<file>.xbrief.json",
174
- " task scope:cancel -- xbrief/active/<file>.xbrief.json # when abandoning",
175
- " For stop-at:pr-open workers the orchestrator owns post-merge complete/cancel;",
176
- " for drive-to:merge-ready workers scope:complete is part of the worker unit (#2321).",
177
- " Or run task swarm:finalize-cohort / task swarm:complete-cohort after cohort merge.",
178
- " Offending briefs:",
179
- ];
218
+ function briefReferencesIssue(issues, issue) {
219
+ return issues.some((ref) => ref.number === issue);
220
+ }
221
+ function formatRefusal(orphans, projectRoot, issueFilter) {
222
+ const shippedOrphans = orphans.filter((orphan) => orphan.kind === "shipped");
223
+ const unresolvedOrphans = orphans.filter((orphan) => orphan.kind === "unresolved");
224
+ const noun = orphans.length === 1 ? "" : "s";
225
+ let headline;
226
+ if (unresolvedOrphans.length > 0 && shippedOrphans.length === 0) {
227
+ headline = `verify:orphan-active: ${unresolvedOrphans.length} active/running xBRIEF${unresolvedOrphans.length === 1 ? "" : "s"} have unresolved GitHub state (cannot confirm shipped) (project_root=${projectRoot}).`;
228
+ }
229
+ else if (shippedOrphans.length > 0 && unresolvedOrphans.length === 0) {
230
+ headline = `verify:orphan-active: ${shippedOrphans.length} active/running xBRIEF${shippedOrphans.length === 1 ? "" : "s"} look shipped but still consume WIP (project_root=${projectRoot}).`;
231
+ }
232
+ else {
233
+ headline = `verify:orphan-active: ${orphans.length} active/running xBRIEF${noun} failed the after-merge check (project_root=${projectRoot}).`;
234
+ }
235
+ const lines = [headline];
236
+ if (shippedOrphans.length > 0) {
237
+ lines.push(" Remediation: move each confirmed-shipped brief out of active/ with lifecycle ownership:");
238
+ for (const orphan of shippedOrphans) {
239
+ lines.push(` task scope:complete -- ${orphan.path}`);
240
+ }
241
+ lines.push(" task scope:cancel -- xbrief/active/<file>.xbrief.json # when abandoning", " For stop-at:pr-open workers the orchestrator owns post-merge complete/cancel;", " for drive-to:merge-ready workers scope:complete is part of the worker unit (#2321 / #3429).", " Or run task swarm:finalize-cohort / task swarm:complete-cohort after cohort merge.");
242
+ }
243
+ if (unresolvedOrphans.length > 0) {
244
+ const retry = issueFilter === null
245
+ ? "task verify:orphan-active"
246
+ : `task verify:orphan-active -- --issue ${issueFilter}`;
247
+ lines.push(" Remediation: retry the GitHub lookup (auth, rate-limit, network, skipGh) then re-run:", ` ${retry}`, " Do not run task scope:complete until the origin is confirmed closed or the linked PR is confirmed merged.");
248
+ }
249
+ lines.push(" Offending briefs:");
180
250
  for (const orphan of orphans) {
181
251
  lines.push(` - ${orphan.path} (${orphan.reason})`);
182
252
  }
183
253
  return lines.join("\n");
184
254
  }
185
255
  /**
186
- * Pure evaluator for orphaned active/running xBRIEF detection (#2321).
256
+ * Pure evaluator for orphaned active/running xBRIEF detection (#2321 / #3429).
187
257
  * Fails when active/ briefs with plan.status==running reference only closed
188
258
  * issues and/or a merged PR — the stop-at:pr-open orphan signature.
259
+ * Pass `issue` to scan one origin after merge. Confirmed shipped prints
260
+ * scope:complete; unresolved lookup still exits 1 with a retry remediation.
189
261
  */
190
262
  export function evaluate(projectRoot, options = {}) {
191
263
  const root = resolve(projectRoot);
@@ -238,24 +310,30 @@ export function evaluate(projectRoot, options = {}) {
238
310
  orphans: [],
239
311
  };
240
312
  }
313
+ const issueFilter = options.issue ?? null;
241
314
  const orphans = [];
242
315
  for (const brief of listActiveRunningBriefs(root)) {
243
316
  const { issues, prs } = collectGithubRefs(brief.plan, defaultRepo);
317
+ // --issue N is one origin: briefs that name that issue. PR-only briefs stay on the unscoped scan (#3429).
318
+ if (issueFilter !== null && !briefReferencesIssue(issues, issueFilter)) {
319
+ continue;
320
+ }
244
321
  if (issues.length === 0 && prs.length === 0) {
245
322
  continue;
246
323
  }
247
- const assessment = assessOrphanSignature(issues, prs, root, runGh, skipGh);
248
- if (assessment.orphaned && assessment.reason !== null) {
324
+ const assessment = assessOrphanSignature(issues, prs, root, runGh, skipGh, issueFilter);
325
+ if (assessment.orphaned && assessment.reason !== null && assessment.kind !== null) {
249
326
  orphans.push({
250
327
  path: relBriefPath(brief.path, root),
251
328
  reason: assessment.reason,
329
+ kind: assessment.kind,
252
330
  });
253
331
  }
254
332
  }
255
333
  if (orphans.length > 0) {
256
334
  return {
257
335
  code: 1,
258
- message: formatRefusal(orphans, root),
336
+ message: formatRefusal(orphans, root, issueFilter),
259
337
  stream: "stderr",
260
338
  orphans,
261
339
  };
@@ -264,9 +342,10 @@ export function evaluate(projectRoot, options = {}) {
264
342
  return { code: 0, message: "", stream: "none", orphans: [] };
265
343
  }
266
344
  const scanned = listActiveRunningBriefs(root).length;
345
+ const issueNote = issueFilter === null ? "" : ` for issue #${issueFilter}`;
267
346
  return {
268
347
  code: 0,
269
- message: `verify:orphan-active: no orphaned active/running xBRIEFs ` +
348
+ message: `verify:orphan-active: no orphaned active/running xBRIEFs${issueNote} ` +
270
349
  `(scanned ${scanned} running brief${scanned === 1 ? "" : "s"} in active/).`,
271
350
  stream: "stdout",
272
351
  orphans: [],
@@ -72,10 +72,9 @@ export function classifyIdentityKind(options) {
72
72
  function isCloudHeadless(environ) {
73
73
  if (envTruthy(environ, "CURSOR_AGENT"))
74
74
  return true;
75
- if (envTruthy(environ, "GROK_BUILD"))
76
- return true;
75
+ // GROK_BUILD / DEFT_AGENT_RUNTIME=grok-build identify a local TUI, not CI (#3469).
77
76
  const runtime = (environ.DEFT_AGENT_RUNTIME ?? "").trim().toLowerCase();
78
- if (runtime === "grok-build" || runtime === "cloud" || runtime === "headless")
77
+ if (runtime === "cloud" || runtime === "headless")
79
78
  return true;
80
79
  if (envTruthy(environ, "GITHUB_ACTIONS") || envTruthy(environ, "BUILDKITE"))
81
80
  return true;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Typed plan.policy.baseBranch (#3388).
3
+ *
4
+ * Integration-branch source for the shared branch-sync detector. Distinct from
5
+ * deliveryBranch (dest). Unset or invalid baseBranch resolves to dest so sync
6
+ * is a no-op. origin/develop is never identity; it may only emit a hint.
7
+ */
8
+ import { type GitRunner } from "../session/git.js";
9
+ export declare const FIELD_BASE_BRANCH = "plan.policy.baseBranch";
10
+ export declare const FIELD_BASE_BRANCH_CLI_ALIAS = "baseBranch";
11
+ /** Nudge only — never used as dest or source identity (#3388 / #3377 Q1). */
12
+ export declare const ORIGIN_DEVELOP_HINT = "origin/develop exists; set plan.policy.baseBranch if this repo uses an integration branch";
13
+ export type BaseBranchSource = "typed" | "equals-dest" | "default-on-error";
14
+ export interface BaseBranchResult {
15
+ readonly branch: string;
16
+ readonly dest: string;
17
+ readonly source: BaseBranchSource;
18
+ readonly typed: boolean;
19
+ readonly error: string | null;
20
+ readonly developHint: string | null;
21
+ }
22
+ /**
23
+ * Resolve plan.policy.baseBranch (#3388).
24
+ *
25
+ * Unset or invalid values equal dest (deliveryBranch). origin/develop is never
26
+ * substituted as the source.
27
+ */
28
+ export declare function resolveBaseBranch(projectRoot: string, runGit?: GitRunner): BaseBranchResult;
29
+ export interface BaseBranchPolicyField {
30
+ readonly name: string;
31
+ readonly current: string;
32
+ readonly default: string;
33
+ readonly source: string;
34
+ }
35
+ /** Inspector row for `task policy:show --field=baseBranch` (#3388). */
36
+ export declare function inspectBaseBranch(_data: Record<string, unknown> | null, projectRoot?: string): BaseBranchPolicyField;
37
+ //# sourceMappingURL=base-branch.d.ts.map
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Typed plan.policy.baseBranch (#3388).
3
+ *
4
+ * Integration-branch source for the shared branch-sync detector. Distinct from
5
+ * deliveryBranch (dest). Unset or invalid baseBranch resolves to dest so sync
6
+ * is a no-op. origin/develop is never identity; it may only emit a hint.
7
+ */
8
+ import { defaultGitRunner } from "../session/git.js";
9
+ import { DEFAULT_DELIVERY_BRANCH_FALLBACK, resolveDeliveryBranch } from "./delivery-branch.js";
10
+ import { readPlanPolicy } from "./plan-extensions.js";
11
+ import { loadProjectDefinition } from "./resolve.js";
12
+ export const FIELD_BASE_BRANCH = "plan.policy.baseBranch";
13
+ export const FIELD_BASE_BRANCH_CLI_ALIAS = "baseBranch";
14
+ /** Nudge only — never used as dest or source identity (#3388 / #3377 Q1). */
15
+ export const ORIGIN_DEVELOP_HINT = "origin/develop exists; set plan.policy.baseBranch if this repo uses an integration branch";
16
+ function originRefExists(projectRoot, branch, runGit) {
17
+ const check = runGit(projectRoot, [
18
+ "show-ref",
19
+ "--verify",
20
+ "--quiet",
21
+ `refs/remotes/origin/${branch}`,
22
+ ]);
23
+ return check.code === 0;
24
+ }
25
+ function developHintIfEligible(projectRoot, typed, runGit) {
26
+ if (typed)
27
+ return null;
28
+ if (!originRefExists(projectRoot, "develop", runGit))
29
+ return null;
30
+ return ORIGIN_DEVELOP_HINT;
31
+ }
32
+ /**
33
+ * Resolve plan.policy.baseBranch (#3388).
34
+ *
35
+ * Unset or invalid values equal dest (deliveryBranch). origin/develop is never
36
+ * substituted as the source.
37
+ */
38
+ export function resolveBaseBranch(projectRoot, runGit = defaultGitRunner) {
39
+ const dest = resolveDeliveryBranch(projectRoot, runGit).branch || DEFAULT_DELIVERY_BRANCH_FALLBACK;
40
+ const [data, err] = loadProjectDefinition(projectRoot);
41
+ if (data === null) {
42
+ return {
43
+ branch: dest,
44
+ dest,
45
+ source: "equals-dest",
46
+ typed: false,
47
+ error: err,
48
+ developHint: developHintIfEligible(projectRoot, false, runGit),
49
+ };
50
+ }
51
+ const plan = data.plan;
52
+ if (typeof plan !== "object" || plan === null || Array.isArray(plan)) {
53
+ return {
54
+ branch: dest,
55
+ dest,
56
+ source: "equals-dest",
57
+ typed: false,
58
+ error: "PROJECT-DEFINITION 'plan' is not an object",
59
+ developHint: developHintIfEligible(projectRoot, false, runGit),
60
+ };
61
+ }
62
+ const policyBlock = readPlanPolicy(plan);
63
+ if (typeof policyBlock === "object" &&
64
+ policyBlock !== null &&
65
+ !Array.isArray(policyBlock) &&
66
+ "baseBranch" in policyBlock) {
67
+ const raw = policyBlock.baseBranch;
68
+ if (typeof raw !== "string" || raw.trim().length === 0) {
69
+ return {
70
+ branch: dest,
71
+ dest,
72
+ source: "default-on-error",
73
+ typed: false,
74
+ error: `plan.policy.baseBranch must be a non-empty string; got ${typeof raw}`,
75
+ developHint: developHintIfEligible(projectRoot, false, runGit),
76
+ };
77
+ }
78
+ return {
79
+ branch: raw.trim(),
80
+ dest,
81
+ source: "typed",
82
+ typed: true,
83
+ error: null,
84
+ developHint: null,
85
+ };
86
+ }
87
+ return {
88
+ branch: dest,
89
+ dest,
90
+ source: "equals-dest",
91
+ typed: false,
92
+ error: null,
93
+ developHint: developHintIfEligible(projectRoot, false, runGit),
94
+ };
95
+ }
96
+ /** Inspector row for `task policy:show --field=baseBranch` (#3388). */
97
+ export function inspectBaseBranch(_data, projectRoot) {
98
+ if (projectRoot === undefined || projectRoot.length === 0) {
99
+ return {
100
+ name: FIELD_BASE_BRANCH,
101
+ current: DEFAULT_DELIVERY_BRANCH_FALLBACK,
102
+ default: DEFAULT_DELIVERY_BRANCH_FALLBACK,
103
+ source: "equals-dest",
104
+ };
105
+ }
106
+ const resolved = resolveBaseBranch(projectRoot);
107
+ return {
108
+ name: FIELD_BASE_BRANCH,
109
+ current: resolved.branch,
110
+ default: resolved.dest,
111
+ source: resolved.source,
112
+ };
113
+ }
114
+ //# sourceMappingURL=base-branch.js.map
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Shared branch-sync detector (#3388 / #3377 Wave 1).
3
+ *
4
+ * Dest = deliveryBranch. Source = typed baseBranch (unset equals dest → not a
5
+ * sync). Predicate: PR base is dest AND head is already on origin/<source>
6
+ * after fetch (tip or ancestor). Name-only and label-only exemptions are not
7
+ * implemented. origin/develop is never load-bearing identity.
8
+ *
9
+ * This module is the only is-this-a-sync source for later children (#3390/#3391)
10
+ * and for core-guard.
11
+ */
12
+ import { type GitRunner } from "../session/git.js";
13
+ /** Dest-ref blob used for dest/source. Never the PR working tree (#3388 P1). */
14
+ export declare const BRANCH_SYNC_POLICY_BLOB = "xbrief/PROJECT-DEFINITION.xbrief.json";
15
+ export declare const BRANCH_SYNC_EXEMPTION_PREFIX = "sync PR detected: all commits already guard-checked on";
16
+ export type BranchSyncReason = "source-equals-dest" | "base-is-not-dest" | "fetch-failed" | "head-not-on-integration" | "sync";
17
+ export interface BranchSyncDetection {
18
+ readonly isSync: boolean;
19
+ readonly dest: string;
20
+ readonly source: string;
21
+ readonly sourceTyped: boolean;
22
+ readonly reason: BranchSyncReason;
23
+ readonly message: string;
24
+ readonly developHint: string | null;
25
+ }
26
+ export interface DetectBranchSyncInput {
27
+ readonly dest: string;
28
+ readonly source: string;
29
+ readonly sourceTyped: boolean;
30
+ readonly prBase: string;
31
+ readonly headSha: string;
32
+ readonly projectRoot: string;
33
+ readonly developHint?: string | null;
34
+ readonly runGit?: GitRunner;
35
+ }
36
+ export declare function formatBranchSyncExemptionMessage(integrationBranch: string): string;
37
+ /**
38
+ * Evidence-based sync predicate (#3388 Q3). Fetch first. Do not trust PR
39
+ * branch names or labels.
40
+ */
41
+ export declare function detectBranchSync(input: DetectBranchSyncInput): BranchSyncDetection;
42
+ export interface DestRefSyncPolicy {
43
+ readonly dest: string;
44
+ readonly source: string;
45
+ readonly sourceTyped: boolean;
46
+ readonly developHint: string | null;
47
+ }
48
+ /**
49
+ * Load dest/source from origin/<prBase>, not the PR checkout.
50
+ *
51
+ * A feature PR that rewrites working-tree baseBranch cannot become a sync.
52
+ */
53
+ export declare function resolveSyncPolicyFromDestRef(options: {
54
+ readonly projectRoot: string;
55
+ readonly prBase: string;
56
+ readonly runGit?: GitRunner;
57
+ }): DestRefSyncPolicy;
58
+ /** Load dest/source from dest-ref policy, then run {@link detectBranchSync}. */
59
+ export declare function detectBranchSyncFromProject(options: {
60
+ readonly projectRoot: string;
61
+ readonly prBase: string;
62
+ readonly headSha: string;
63
+ readonly runGit?: GitRunner;
64
+ }): BranchSyncDetection;
65
+ export interface CoreGuardSyncExemption {
66
+ readonly wouldFail: boolean;
67
+ readonly loudMessage: string | null;
68
+ }
69
+ /**
70
+ * Core-guard mix result after the shared sync predicate. Sync PRs pass
71
+ * loudly; mixed feature PRs still fail.
72
+ */
73
+ export declare function applyCoreGuardWithBranchSync(classification: {
74
+ readonly wouldFail: boolean;
75
+ }, sync: BranchSyncDetection): CoreGuardSyncExemption;
76
+ /** Compact Python body for the deposited deft-core-guard (#3388). */
77
+ export declare function coreGuardBranchSyncPythonBody(): readonly string[];
78
+ /** Indented `if` block: detector success exits 0 (loud print); else fall through. */
79
+ export declare function renderCoreGuardBranchSyncIfBlock(indent: string): string;
80
+ //# sourceMappingURL=branch-sync.d.ts.map