@kontourai/flow-agents 4.1.0 → 4.2.1

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 (108) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/src/builder-flow-runtime.js +10 -5
  3. package/context/contracts/verification-contract.md +6 -0
  4. package/context/scripts/telemetry/lib/config.sh +29 -0
  5. package/dist/base/build/package.json +1 -1
  6. package/dist/base/build/src/builder-flow-runtime.js +10 -5
  7. package/dist/base/context/contracts/verification-contract.md +6 -0
  8. package/dist/base/context/scripts/telemetry/lib/config.sh +29 -0
  9. package/dist/base/evals/acceptance/prove-capture-teeth.sh +24 -0
  10. package/dist/base/evals/integration/test_effective_backlog_settings.sh +118 -15
  11. package/dist/base/evals/integration/test_liveness_console_relay.sh +91 -1
  12. package/dist/base/evals/integration/test_liveness_heartbeat.sh +66 -0
  13. package/dist/base/install.sh +1 -1
  14. package/dist/base/scripts/hooks/claude-telemetry-hook.js +6 -0
  15. package/dist/base/scripts/hooks/lib/codex-exit-code.js +75 -23
  16. package/dist/base/scripts/hooks/lib/liveness-heartbeat.js +42 -1
  17. package/dist/base/scripts/hooks/lib/liveness-write.js +109 -9
  18. package/dist/base/scripts/liveness/relay.sh +23 -11
  19. package/dist/base/scripts/telemetry/lib/config.sh +29 -0
  20. package/dist/claude-code/build/package.json +1 -1
  21. package/dist/claude-code/build/src/builder-flow-runtime.js +10 -5
  22. package/dist/claude-code/context/contracts/verification-contract.md +6 -0
  23. package/dist/claude-code/context/scripts/telemetry/lib/config.sh +29 -0
  24. package/dist/claude-code/evals/acceptance/prove-capture-teeth.sh +24 -0
  25. package/dist/claude-code/evals/integration/test_effective_backlog_settings.sh +118 -15
  26. package/dist/claude-code/evals/integration/test_liveness_console_relay.sh +91 -1
  27. package/dist/claude-code/evals/integration/test_liveness_heartbeat.sh +66 -0
  28. package/dist/claude-code/install.sh +1 -1
  29. package/dist/claude-code/scripts/hooks/claude-telemetry-hook.js +6 -0
  30. package/dist/claude-code/scripts/hooks/lib/codex-exit-code.js +75 -23
  31. package/dist/claude-code/scripts/hooks/lib/liveness-heartbeat.js +42 -1
  32. package/dist/claude-code/scripts/hooks/lib/liveness-write.js +109 -9
  33. package/dist/claude-code/scripts/liveness/relay.sh +23 -11
  34. package/dist/claude-code/scripts/telemetry/lib/config.sh +29 -0
  35. package/dist/codex/build/package.json +1 -1
  36. package/dist/codex/build/src/builder-flow-runtime.js +10 -5
  37. package/dist/codex/context/contracts/verification-contract.md +6 -0
  38. package/dist/codex/context/scripts/telemetry/lib/config.sh +29 -0
  39. package/dist/codex/evals/acceptance/prove-capture-teeth.sh +24 -0
  40. package/dist/codex/evals/integration/test_effective_backlog_settings.sh +118 -15
  41. package/dist/codex/evals/integration/test_liveness_console_relay.sh +91 -1
  42. package/dist/codex/evals/integration/test_liveness_heartbeat.sh +66 -0
  43. package/dist/codex/install.sh +1 -1
  44. package/dist/codex/scripts/hooks/claude-telemetry-hook.js +6 -0
  45. package/dist/codex/scripts/hooks/lib/codex-exit-code.js +75 -23
  46. package/dist/codex/scripts/hooks/lib/liveness-heartbeat.js +42 -1
  47. package/dist/codex/scripts/hooks/lib/liveness-write.js +109 -9
  48. package/dist/codex/scripts/liveness/relay.sh +23 -11
  49. package/dist/codex/scripts/telemetry/lib/config.sh +29 -0
  50. package/dist/kiro/build/package.json +1 -1
  51. package/dist/kiro/build/src/builder-flow-runtime.js +10 -5
  52. package/dist/kiro/context/contracts/verification-contract.md +6 -0
  53. package/dist/kiro/context/scripts/telemetry/lib/config.sh +29 -0
  54. package/dist/kiro/evals/acceptance/prove-capture-teeth.sh +24 -0
  55. package/dist/kiro/evals/integration/test_effective_backlog_settings.sh +118 -15
  56. package/dist/kiro/evals/integration/test_liveness_console_relay.sh +91 -1
  57. package/dist/kiro/evals/integration/test_liveness_heartbeat.sh +66 -0
  58. package/dist/kiro/install.sh +1 -1
  59. package/dist/kiro/scripts/hooks/claude-telemetry-hook.js +6 -0
  60. package/dist/kiro/scripts/hooks/lib/codex-exit-code.js +75 -23
  61. package/dist/kiro/scripts/hooks/lib/liveness-heartbeat.js +42 -1
  62. package/dist/kiro/scripts/hooks/lib/liveness-write.js +109 -9
  63. package/dist/kiro/scripts/liveness/relay.sh +23 -11
  64. package/dist/kiro/scripts/telemetry/lib/config.sh +29 -0
  65. package/dist/opencode/build/package.json +1 -1
  66. package/dist/opencode/build/src/builder-flow-runtime.js +10 -5
  67. package/dist/opencode/context/contracts/verification-contract.md +6 -0
  68. package/dist/opencode/context/scripts/telemetry/lib/config.sh +29 -0
  69. package/dist/opencode/evals/acceptance/prove-capture-teeth.sh +24 -0
  70. package/dist/opencode/evals/integration/test_effective_backlog_settings.sh +118 -15
  71. package/dist/opencode/evals/integration/test_liveness_console_relay.sh +91 -1
  72. package/dist/opencode/evals/integration/test_liveness_heartbeat.sh +66 -0
  73. package/dist/opencode/install.sh +1 -1
  74. package/dist/opencode/scripts/hooks/claude-telemetry-hook.js +6 -0
  75. package/dist/opencode/scripts/hooks/lib/codex-exit-code.js +75 -23
  76. package/dist/opencode/scripts/hooks/lib/liveness-heartbeat.js +42 -1
  77. package/dist/opencode/scripts/hooks/lib/liveness-write.js +109 -9
  78. package/dist/opencode/scripts/liveness/relay.sh +23 -11
  79. package/dist/opencode/scripts/telemetry/lib/config.sh +29 -0
  80. package/dist/pi/build/package.json +1 -1
  81. package/dist/pi/build/src/builder-flow-runtime.js +10 -5
  82. package/dist/pi/context/contracts/verification-contract.md +6 -0
  83. package/dist/pi/context/scripts/telemetry/lib/config.sh +29 -0
  84. package/dist/pi/evals/acceptance/prove-capture-teeth.sh +24 -0
  85. package/dist/pi/evals/integration/test_effective_backlog_settings.sh +118 -15
  86. package/dist/pi/evals/integration/test_liveness_console_relay.sh +91 -1
  87. package/dist/pi/evals/integration/test_liveness_heartbeat.sh +66 -0
  88. package/dist/pi/install.sh +1 -1
  89. package/dist/pi/scripts/hooks/claude-telemetry-hook.js +6 -0
  90. package/dist/pi/scripts/hooks/lib/codex-exit-code.js +75 -23
  91. package/dist/pi/scripts/hooks/lib/liveness-heartbeat.js +42 -1
  92. package/dist/pi/scripts/hooks/lib/liveness-write.js +109 -9
  93. package/dist/pi/scripts/liveness/relay.sh +23 -11
  94. package/dist/pi/scripts/telemetry/lib/config.sh +29 -0
  95. package/evals/acceptance/prove-capture-teeth.sh +24 -0
  96. package/evals/integration/test_effective_backlog_settings.sh +118 -15
  97. package/evals/integration/test_liveness_console_relay.sh +91 -1
  98. package/evals/integration/test_liveness_heartbeat.sh +66 -0
  99. package/package.json +2 -1
  100. package/scripts/hooks/claude-telemetry-hook.js +6 -0
  101. package/scripts/hooks/lib/codex-exit-code.js +75 -23
  102. package/scripts/hooks/lib/liveness-heartbeat.js +42 -1
  103. package/scripts/hooks/lib/liveness-write.js +109 -9
  104. package/scripts/liveness/relay.sh +23 -11
  105. package/scripts/telemetry/lib/config.sh +29 -0
  106. package/src/builder-flow-runtime.ts +10 -5
  107. package/src/cli/builder-flow-runtime.test.mjs +55 -2
  108. package/src/cli/codex-exit-code.test.mjs +217 -2
@@ -18,27 +18,127 @@
18
18
  */
19
19
 
20
20
  const fs = require('fs');
21
+ const os = require('os');
21
22
  const path = require('path');
22
23
  const { spawn } = require('child_process');
23
24
 
25
+ const TRUTHY = new Set(['1', 'true', 'yes', 'on']);
26
+ const FALSY = new Set(['0', 'false', 'no', 'off']);
27
+ // Cheap per-process memo keyed by the exact env inputs, so a throttled hot path does at most one
28
+ // conf read per (env flag, conf path) signature. Keyed inputs make unit tests that vary
29
+ // TELEMETRY_CONFIG_FILE independent.
30
+ const relayEnabledCache = new Map();
31
+
32
+ /**
33
+ * The console-conf resolution chain, mirroring scripts/telemetry/lib/config.sh's slot order:
34
+ * 1. TELEMETRY_CONFIG_FILE (env) if set + readable
35
+ * 2. per-workspace override: <workspace-root>/.kontourai/telemetry-console.conf
36
+ * 3. user-global durable override: <bundle-root>/telemetry-console.conf
37
+ * 4. the shipped default: scripts/telemetry/telemetry.conf (relative to this file)
38
+ * Slot 4's path is <this file>/../../telemetry/telemetry.conf; the workspace root for slot 2 is
39
+ * three levels up from scripts/hooks/lib. This resolver is only the SPAWN pre-gate — it is
40
+ * intentionally lenient (no mode-600 trust gate). relay.sh re-sources config.sh, which applies the
41
+ * trust gate and is the authoritative decision for both enablement and the POST endpoint, so a
42
+ * lenient "enabled" here at worst spawns a relay.sh that then trust-gates itself to a no-op.
43
+ *
44
+ * ACCEPTED, BY DESIGN (security review LOW, A04): because this pre-gate does NOT re-apply
45
+ * config.sh's mode-600/owner gate, it can read an explicit key from an UNtrusted default-path conf
46
+ * (a mode-644 .kontourai/telemetry-console.conf a local tool dropped) that config.sh would skip.
47
+ * This is fail-toward-no-op, never fail-toward-exfil: the only divergence is (a) we spawn a
48
+ * relay.sh that config.sh then no-ops (harmless), or (b) an untrusted `=0` here suppresses a spawn
49
+ * that a trusted conf would have enabled (a missed pulse — availability only, requiring local FS
50
+ * write access). The pre-gate deliberately does not guarantee relay AVAILABILITY — only that we
51
+ * avoid spawning when nothing plausibly enables it. It NEVER weakens the exfil defense, which lives
52
+ * entirely in relay.sh's authoritative, trust-gated re-resolution.
53
+ * @returns {string|null} first readable conf path, or null
54
+ */
55
+ function resolveConsoleConfPath(env) {
56
+ const candidates = [
57
+ env.TELEMETRY_CONFIG_FILE,
58
+ path.join(__dirname, '..', '..', '..', '.kontourai', 'telemetry-console.conf'),
59
+ path.join(os.homedir(), '.flow-agents', 'telemetry-console.conf'),
60
+ path.join(__dirname, '..', '..', 'telemetry', 'telemetry.conf'),
61
+ ];
62
+ for (const c of candidates) {
63
+ try {
64
+ if (c && fs.existsSync(c) && fs.statSync(c).isFile()) return c;
65
+ } catch {
66
+ /* keep scanning */
67
+ }
68
+ }
69
+ return null;
70
+ }
71
+
72
+ /**
73
+ * Conf-driven liveness relay enablement (#567 — parity with the economics relay #469, so an
74
+ * operator enables via `console_liveness_relay=1` in the console conf, NOT an env var/.profile).
75
+ * Precedence mirrors config.sh's economics rule EXACTLY (config.sh:182-204): an explicit
76
+ * `console_liveness_relay` conf key wins over the env var; absent a key, a pre-set env var is
77
+ * honored; absent both, default ON once a console sink is configured (any console_*url key present)
78
+ * — opt-out, not silent-off. Best-effort and cheap: any FS/parse failure falls back to the env-only
79
+ * decision; never throws. This is the spawn pre-gate; relay.sh+config.sh is authoritative.
80
+ */
81
+ function resolveLivenessRelayEnabled(env) {
82
+ const envFlag = String(env.FLOW_AGENTS_CONSOLE_LIVENESS_RELAY || '').toLowerCase();
83
+ const envDecision = TRUTHY.has(envFlag) ? true : FALSY.has(envFlag) ? false : null;
84
+ const cacheKey = `${envFlag}|${env.TELEMETRY_CONFIG_FILE || ''}`;
85
+ if (relayEnabledCache.has(cacheKey)) return relayEnabledCache.get(cacheKey);
86
+ let enabled;
87
+ try {
88
+ let explicit = null;
89
+ let hasConsoleUrl = false;
90
+ const confPath = resolveConsoleConfPath(env);
91
+ if (confPath) {
92
+ for (const raw of fs.readFileSync(confPath, 'utf8').split('\n')) {
93
+ const line = raw.trim();
94
+ if (!line || line.startsWith('#')) continue;
95
+ const eq = line.indexOf('=');
96
+ if (eq < 0) continue;
97
+ const key = line.slice(0, eq).trim();
98
+ const value = line.slice(eq + 1).trim().toLowerCase();
99
+ if (key === 'console_liveness_relay') {
100
+ if (TRUTHY.has(value)) explicit = true;
101
+ else if (FALSY.has(value)) explicit = false;
102
+ } else if (key === 'console_telemetry_url' || key === 'console_url' || key === 'console_telemetry_endpoint_url') {
103
+ if (value) hasConsoleUrl = true;
104
+ }
105
+ }
106
+ }
107
+ // config.sh precedence: explicit conf key > pre-set env var > default-on when a console url resolves.
108
+ enabled = explicit !== null ? explicit : envDecision !== null ? envDecision : hasConsoleUrl;
109
+ } catch {
110
+ enabled = envDecision === true; // best-effort: honor only an explicit env-on if the conf read failed
111
+ }
112
+ relayEnabledCache.set(cacheKey, enabled);
113
+ return enabled;
114
+ }
115
+
24
116
  /**
25
- * OPTIONAL console liveness relay (#295, ADR 0021 §4/§7). Best-effort, FULLY detached mirror of a
26
- * liveness event to the hosted Console via `scripts/liveness/relay.sh`. Local-first is sacred: this
27
- * runs AFTER the durable local append and can never block, throw, or affect it — gated on
28
- * `FLOW_AGENTS_CONSOLE_LIVENESS_RELAY`, the whole thing wrapped so any failure (missing script,
29
- * spawn error) is swallowed. No flag ⇒ a single cheap env read and return (true no-op).
117
+ * OPTIONAL console liveness relay (#295, ADR 0021 §4/§7; conf-driven per #567). Best-effort, FULLY
118
+ * detached mirror of a liveness event to the hosted Console via `scripts/liveness/relay.sh`.
119
+ * Local-first is sacred: this runs AFTER the durable local append and can never block, throw, or
120
+ * affect it — gated on `resolveLivenessRelayEnabled`, the whole thing wrapped so any failure
121
+ * (missing script, spawn error) is swallowed. Not enabled ⇒ a cheap resolve and return (true no-op).
30
122
  *
31
123
  * @param {object} evt The liveness event just written locally.
32
124
  * @returns {void}
33
125
  */
34
126
  function relayLivenessEvent(evt) {
35
127
  try {
36
- const flag = String(process.env.FLOW_AGENTS_CONSOLE_LIVENESS_RELAY || '').toLowerCase();
37
- if (flag !== '1' && flag !== 'true' && flag !== 'yes' && flag !== 'on') return;
128
+ if (!resolveLivenessRelayEnabled(process.env)) return;
38
129
  // scripts/hooks/lib/ -> scripts/liveness/relay.sh (same relative layout in dist/* bundles).
39
130
  const relay = path.join(__dirname, '..', '..', 'liveness', 'relay.sh');
40
131
  if (!fs.existsSync(relay)) return;
41
- const child = spawn('bash', [relay, JSON.stringify(evt)], { detached: true, stdio: 'ignore' });
132
+ // Pass the environment through UNCHANGED do not force the enable flag. relay.sh re-sources
133
+ // config.sh, which is the authoritative, trust-gated decision for both enablement (conf key >
134
+ // env > default-on) and the POST endpoint. Our resolve above is only a lenient spawn pre-gate:
135
+ // if we enabled from an untrusted default-path conf, config.sh trust-gates relay.sh to a no-op
136
+ // rather than us bypassing it by forcing the flag on.
137
+ const child = spawn('bash', [relay, JSON.stringify(evt)], {
138
+ detached: true,
139
+ stdio: 'ignore',
140
+ env: process.env,
141
+ });
42
142
  child.on('error', () => {}); // never surface a spawn failure
43
143
  child.unref(); // fully detach — the parent never waits on the relay
44
144
  } catch {
@@ -70,4 +170,4 @@ function appendLivenessEvent(root, evt) {
70
170
  relayLivenessEvent(evt); // then optionally mirror to the Console — best-effort, detached, off by default
71
171
  }
72
172
 
73
- module.exports = { livenessStreamFile, appendLivenessEvent };
173
+ module.exports = { livenessStreamFile, appendLivenessEvent, resolveLivenessRelayEnabled };
@@ -7,26 +7,36 @@
7
7
  # never forked). The Console side ingests this record type and projects the fleet view + runs the
8
8
  # janitor (console repo #125); this script is only the flow-agents EMIT half.
9
9
  #
10
- # STRICTLY OPTIONAL and local-first (ADR 0012 §5): a no-op unless FLOW_AGENTS_CONSOLE_LIVENESS_RELAY
11
- # is enabled AND a console endpoint is configured. Best-effort throughout it must NEVER block, slow,
12
- # or fail the local liveness write that already happened before this was invoked. Every failure path
13
- # is a quiet `exit 0`.
10
+ # STRICTLY OPTIONAL and local-first (ADR 0012 §5): a no-op unless the liveness relay is enabled AND a
11
+ # console endpoint is configured. Enablement is conf-driven (#567, parity with economics #469): an
12
+ # operator sets `console_liveness_relay=1` in the console conf (or it defaults on once a console url
13
+ # resolves) — NOT an env var. config.sh (sourced below) is the authoritative, trust-gated decision
14
+ # and also supplies the endpoint/token/tenant from the conf. Best-effort throughout — it must NEVER
15
+ # block, slow, or fail the local liveness write that already happened before this was invoked. Every
16
+ # failure path is a quiet `exit 0`.
14
17
  #
15
18
  # Invoked (fully detached, best-effort) from scripts/hooks/lib/liveness-write.js after the durable
16
19
  # local append. Usage: relay.sh '<liveness-event-json>'
17
20
  set -uo pipefail
18
21
 
19
- # Opt-in gate — off by default.
20
- case "${FLOW_AGENTS_CONSOLE_LIVENESS_RELAY:-}" in
21
- 1 | true | TRUE | yes | on) ;;
22
- *) exit 0 ;;
23
- esac
24
-
25
22
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit 0
26
23
 
27
24
  # transport.sh sources ${TELEMETRY_DIR}/lib/redact.sh at load — point it at the telemetry lib dir,
28
25
  # then reuse the SAME console POST core the telemetry mirror uses.
29
26
  export TELEMETRY_DIR="${TELEMETRY_DIR:-$SCRIPT_DIR/../telemetry}"
27
+
28
+ # Source config.sh FIRST (best-effort, like economics-record.sh) so the conf resolves enablement
29
+ # (FLOW_AGENTS_CONSOLE_LIVENESS_RELAY) and the endpoint/token/tenant — trust-gated for default-path
30
+ # confs. This is what makes conf-only operation work with NO env var set.
31
+ # shellcheck source=/dev/null
32
+ [[ -f "$TELEMETRY_DIR/lib/config.sh" ]] && source "$TELEMETRY_DIR/lib/config.sh" 2>/dev/null || true
33
+
34
+ # Opt-in gate — off by default, now honoring the conf-derived value config.sh just resolved.
35
+ case "${FLOW_AGENTS_CONSOLE_LIVENESS_RELAY:-}" in
36
+ 1 | true | TRUE | yes | on) ;;
37
+ *) exit 0 ;;
38
+ esac
39
+
30
40
  [[ -f "$TELEMETRY_DIR/lib/transport.sh" ]] || exit 0
31
41
  # shellcheck source=/dev/null
32
42
  source "$TELEMETRY_DIR/lib/transport.sh" 2>/dev/null || exit 0
@@ -73,7 +83,9 @@ record="$(printf '%s' "$event_json" | jq -c '{
73
83
  ttlSeconds: (.ttlSeconds // null),
74
84
  host: (.host // null),
75
85
  branch: (.branch // null),
76
- artifact_dir: (.artifact_dir // .artifactDir // null)
86
+ artifact_dir: (.artifact_dir // .artifactDir // null),
87
+ source: (.source // null),
88
+ activity: (.activity // null)
77
89
  }' 2>/dev/null)" || exit 0
78
90
  [[ -z "$record" || "$record" == "null" ]] && exit 0
79
91
 
@@ -109,6 +109,13 @@ FLOW_AGENTS_CONSOLE_ECONOMICS_ENDPOINT_URL="${FLOW_AGENTS_CONSOLE_ECONOMICS_ENDP
109
109
  # Set (non-empty) only when the config file carries an explicit console_economics_relay key —
110
110
  # distinguishes "operator said 0/1" from "key absent" for the default-on rule below.
111
111
  console_economics_relay_raw=""
112
+ # Liveness relay (#567): same conf-driven, opt-out-not-silent-off shape as economics (#469) so an
113
+ # operator enables the hosted liveness mirror via console_liveness_relay=1 in the conf, NOT an env
114
+ # var/.profile. A caller-pre-set env var is the starting point; the config key overrides it; absent
115
+ # any key the default-on rule below turns it on once a console telemetry sink resolves.
116
+ FLOW_AGENTS_CONSOLE_LIVENESS_RELAY="${FLOW_AGENTS_CONSOLE_LIVENESS_RELAY:-}"
117
+ FLOW_AGENTS_CONSOLE_LIVENESS_ENDPOINT_URL="${FLOW_AGENTS_CONSOLE_LIVENESS_ENDPOINT_URL:-}"
118
+ console_liveness_relay_raw=""
112
119
  # Pricing registry source (consumed by lib/pricing.sh). Explicit file/URL win;
113
120
  # otherwise lib/pricing.sh uses the bundled pricing.json offline.
114
121
  TELEMETRY_PRICING_FILE="${TELEMETRY_PRICING_FILE:-${FLOW_AGENTS_PRICING_FILE:-}}"
@@ -164,6 +171,17 @@ if [[ -f "$TELEMETRY_CONFIG_FILE" ]]; then
164
171
  esac
165
172
  ;;
166
173
  console_economics_endpoint_url) FLOW_AGENTS_CONSOLE_ECONOMICS_ENDPOINT_URL="$value" ;;
174
+ console_liveness_relay)
175
+ case "$(echo "$value" | tr '[:upper:]' '[:lower:]')" in
176
+ 1|true|yes|on) console_liveness_relay_raw="1" ;;
177
+ 0|false|no|off) console_liveness_relay_raw="0" ;;
178
+ *)
179
+ printf 'warning: config.sh: unrecognized console_liveness_relay value %q; treating as off\n' "$value" >&2
180
+ console_liveness_relay_raw="$value"
181
+ ;;
182
+ esac
183
+ ;;
184
+ console_liveness_endpoint_url) FLOW_AGENTS_CONSOLE_LIVENESS_ENDPOINT_URL="$value" ;;
167
185
  console_pricing_url) TELEMETRY_PRICING_URL="$value" ;;
168
186
  pricing_url) TELEMETRY_PRICING_URL="$value" ;;
169
187
  pricing_file) TELEMETRY_PRICING_FILE="$value" ;;
@@ -186,6 +204,17 @@ elif [[ -z "$FLOW_AGENTS_CONSOLE_ECONOMICS_RELAY" \
186
204
  FLOW_AGENTS_CONSOLE_ECONOMICS_RELAY=1
187
205
  fi
188
206
 
207
+ # Liveness relay default-on rule (#567), identical shape to economics above: an explicit
208
+ # console_liveness_relay config key always wins; otherwise, once a console telemetry sink resolves,
209
+ # the relay defaults ON unless a caller already pre-set FLOW_AGENTS_CONSOLE_LIVENESS_RELAY in the
210
+ # environment. relay.sh's own opt-in gate reads this exact variable.
211
+ if [[ -n "$console_liveness_relay_raw" ]]; then
212
+ FLOW_AGENTS_CONSOLE_LIVENESS_RELAY="$console_liveness_relay_raw"
213
+ elif [[ -z "$FLOW_AGENTS_CONSOLE_LIVENESS_RELAY" \
214
+ && ( -n "${CONSOLE_TELEMETRY_URL:-}" || -n "${CONSOLE_TELEMETRY_ENDPOINT_URL:-}" ) ]]; then
215
+ FLOW_AGENTS_CONSOLE_LIVENESS_RELAY=1
216
+ fi
217
+
189
218
  # Pricing URL is explicit-only (env or config). Do not derive the console
190
219
  # pricing endpoint by default; the bundled registry is the reliable offline floor.
191
220
 
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@kontourai/flow-agents",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "type": "module"
5
5
  }
@@ -572,7 +572,7 @@ async function bundleGateEvidence(bundle, gate, state, subject, projectRoot, man
572
572
  throw new BuilderBuildRunInputError("evidence.claims.metadata.gate_claim.route_reason", `is not declared by gate ${String(gate.id ?? "<unknown>")}`);
573
573
  }
574
574
  if (String(gate.id) === "verify-gate" && relevant.some((claim) => claim.claimType === "builder.verify.tests" && claim.value === "pass")) {
575
- await assertVerifiedTestsTrust(bundle.claims, projectRoot);
575
+ await assertVerifiedTestsTrust(relevant, projectRoot);
576
576
  }
577
577
  return { failed, routeReason, expectationIds, visitEnteredAt: enteredAt };
578
578
  }
@@ -602,8 +602,8 @@ function timestampAtOrAfter(value, boundary) {
602
602
  const parsed = parseTimestamp(value);
603
603
  return parsed !== null && parsed >= boundary;
604
604
  }
605
- async function assertVerifiedTestsTrust(claims, projectRoot) {
606
- const testClaims = claims.filter((claim) => isRecord(claim)
605
+ async function assertVerifiedTestsTrust(currentGateClaims, projectRoot) {
606
+ const testClaims = currentGateClaims.filter((claim) => isRecord(claim)
607
607
  && claim.claimType === "builder.verify.tests"
608
608
  && claim.value === "pass"
609
609
  && isRecord(claim.metadata)
@@ -611,7 +611,12 @@ async function assertVerifiedTestsTrust(claims, projectRoot) {
611
611
  && claim.metadata.gate_claim.expectation_id === "tests-evidence");
612
612
  if (testClaims.length === 0)
613
613
  throw new BuilderBuildRunInputError("evidence.tests", "is missing a passing tests-evidence claim");
614
- const liveCritiques = claims.filter((claim) => isRecord(claim)
614
+ // A route-back starts a new gate visit and therefore a new critique generation. Historical
615
+ // reviewer slices remain in the bundle and manifest for audit, but only critiques acquired
616
+ // during this visit describe the implementation snapshot currently being verified. Within a
617
+ // visit every live reviewer slice still participates, so changing reviewers cannot bury a
618
+ // disputed finding.
619
+ const liveCritiques = currentGateClaims.filter((claim) => isRecord(claim)
615
620
  && isRecord(claim.metadata)
616
621
  && claim.metadata.origin === "critique"
617
622
  && typeof claim.metadata.superseded_by !== "string");
@@ -627,7 +632,7 @@ async function assertVerifiedTestsTrust(claims, projectRoot) {
627
632
  await Promise.all(artifacts.map((artifact) => assertReviewedArtifactDigest(artifact, projectRoot)));
628
633
  assertReviewedWorkspaceSnapshot(claim, artifacts, projectRoot);
629
634
  }));
630
- const criteria = claims.filter((claim) => isRecord(claim) && isRecord(claim.metadata) && claim.metadata.origin === "acceptance");
635
+ const criteria = currentGateClaims.filter((claim) => isRecord(claim) && isRecord(claim.metadata) && claim.metadata.origin === "acceptance");
631
636
  if (criteria.length === 0 || criteria.some((claim) => {
632
637
  const criterion = isRecord(claim.metadata.criterion) ? claim.metadata.criterion : null;
633
638
  return claim.value !== "pass" || !criterion || !Array.isArray(criterion.evidence_refs) || criterion.evidence_refs.length === 0;
@@ -20,6 +20,12 @@ Verifiers and reviewers do not modify source code. They may run commands, inspec
20
20
 
21
21
  Verifiers write evidence and acceptance status **through** `record-evidence` (directly, or via the orchestrating skill), never by hand-authoring `evidence.json`, `acceptance.json`, or `trust.bundle`. Those bespoke sidecars were retired as the source of truth by ADR 0010 Phase 4c; the `trust.bundle` is the sole verification artifact, and only the sidecar writer performs the evidence classification (`evidenceType`/`method` derivation and manifest reconciliation) the CI trust anchor depends on (ADR 0020). `config-protection.js` blocks direct tool writes to these gate files by design. If the sidecar writer is unavailable, record the exact gap instead of writing the files by hand.
22
22
 
23
+ ### Critique Generations Across Route-Backs
24
+
25
+ Each visit to a verification gate establishes a critique generation. Critiques acquired during that visit must target the current implementation snapshot, and every live reviewer slice in the generation participates in the gate decision. A disputed finding therefore cannot be hidden by adding a different reviewer.
26
+
27
+ When Flow routes back and later re-enters verification, a fresh critique generation is required. Older reviewer slices remain immutable audit history in the trust bundle and evidence manifest, but their prior snapshot hashes are not reinterpreted as reviews of the new implementation. A reviewer handoff must use the public critique writer; it must never require actor impersonation or direct trust-bundle edits.
28
+
23
29
  ## Mutation Testing Runs In A Scratch Copy
24
30
 
25
31
  Mutation-testing tools (Stryker or equivalent) **must** run against a scratch/throwaway copy of the working tree, never the live working tree. They deliberately introduce defects to measure test-suite sensitivity; running them in place risks leaving mutated source, corrupting the checkout, or tripping the gate/anchor on injected failures. Copy the tree to a temporary directory (or a git worktree/clone) and run the mutation tool there; discard it afterward.
@@ -109,6 +109,13 @@ FLOW_AGENTS_CONSOLE_ECONOMICS_ENDPOINT_URL="${FLOW_AGENTS_CONSOLE_ECONOMICS_ENDP
109
109
  # Set (non-empty) only when the config file carries an explicit console_economics_relay key —
110
110
  # distinguishes "operator said 0/1" from "key absent" for the default-on rule below.
111
111
  console_economics_relay_raw=""
112
+ # Liveness relay (#567): same conf-driven, opt-out-not-silent-off shape as economics (#469) so an
113
+ # operator enables the hosted liveness mirror via console_liveness_relay=1 in the conf, NOT an env
114
+ # var/.profile. A caller-pre-set env var is the starting point; the config key overrides it; absent
115
+ # any key the default-on rule below turns it on once a console telemetry sink resolves.
116
+ FLOW_AGENTS_CONSOLE_LIVENESS_RELAY="${FLOW_AGENTS_CONSOLE_LIVENESS_RELAY:-}"
117
+ FLOW_AGENTS_CONSOLE_LIVENESS_ENDPOINT_URL="${FLOW_AGENTS_CONSOLE_LIVENESS_ENDPOINT_URL:-}"
118
+ console_liveness_relay_raw=""
112
119
  # Pricing registry source (consumed by lib/pricing.sh). Explicit file/URL win;
113
120
  # otherwise lib/pricing.sh uses the bundled pricing.json offline.
114
121
  TELEMETRY_PRICING_FILE="${TELEMETRY_PRICING_FILE:-${FLOW_AGENTS_PRICING_FILE:-}}"
@@ -164,6 +171,17 @@ if [[ -f "$TELEMETRY_CONFIG_FILE" ]]; then
164
171
  esac
165
172
  ;;
166
173
  console_economics_endpoint_url) FLOW_AGENTS_CONSOLE_ECONOMICS_ENDPOINT_URL="$value" ;;
174
+ console_liveness_relay)
175
+ case "$(echo "$value" | tr '[:upper:]' '[:lower:]')" in
176
+ 1|true|yes|on) console_liveness_relay_raw="1" ;;
177
+ 0|false|no|off) console_liveness_relay_raw="0" ;;
178
+ *)
179
+ printf 'warning: config.sh: unrecognized console_liveness_relay value %q; treating as off\n' "$value" >&2
180
+ console_liveness_relay_raw="$value"
181
+ ;;
182
+ esac
183
+ ;;
184
+ console_liveness_endpoint_url) FLOW_AGENTS_CONSOLE_LIVENESS_ENDPOINT_URL="$value" ;;
167
185
  console_pricing_url) TELEMETRY_PRICING_URL="$value" ;;
168
186
  pricing_url) TELEMETRY_PRICING_URL="$value" ;;
169
187
  pricing_file) TELEMETRY_PRICING_FILE="$value" ;;
@@ -186,6 +204,17 @@ elif [[ -z "$FLOW_AGENTS_CONSOLE_ECONOMICS_RELAY" \
186
204
  FLOW_AGENTS_CONSOLE_ECONOMICS_RELAY=1
187
205
  fi
188
206
 
207
+ # Liveness relay default-on rule (#567), identical shape to economics above: an explicit
208
+ # console_liveness_relay config key always wins; otherwise, once a console telemetry sink resolves,
209
+ # the relay defaults ON unless a caller already pre-set FLOW_AGENTS_CONSOLE_LIVENESS_RELAY in the
210
+ # environment. relay.sh's own opt-in gate reads this exact variable.
211
+ if [[ -n "$console_liveness_relay_raw" ]]; then
212
+ FLOW_AGENTS_CONSOLE_LIVENESS_RELAY="$console_liveness_relay_raw"
213
+ elif [[ -z "$FLOW_AGENTS_CONSOLE_LIVENESS_RELAY" \
214
+ && ( -n "${CONSOLE_TELEMETRY_URL:-}" || -n "${CONSOLE_TELEMETRY_ENDPOINT_URL:-}" ) ]]; then
215
+ FLOW_AGENTS_CONSOLE_LIVENESS_RELAY=1
216
+ fi
217
+
189
218
  # Pricing URL is explicit-only (env or config). Do not derive the console
190
219
  # pricing endpoint by default; the bundled registry is the reliable offline floor.
191
220
 
@@ -246,6 +246,30 @@ codex_banner_teeth(){
246
246
  else
247
247
  _f "Codex banner CALL_ID: did not record pass/exitCode:0 for the call_id-matched entry: $(cat "$log_callid" 2>/dev/null)"
248
248
  fi
249
+
250
+ # --- PARALLEL command correlation (#644): current Codex exec_command calls
251
+ # store arguments under `cmd`. With no hook call_id, each PostToolUse event
252
+ # must resolve its exact function_call/output pair by normalized command.
253
+ local proj_parallel; proj_parallel="$(mktemp -d)"
254
+ mkdir -p "$proj_parallel/.kontourai/flow-agents/cap-codex-parallel"
255
+ printf '# Repo\n' > "$proj_parallel/AGENTS.md"
256
+ printf '%s' '{"schema_version":"1.0","task_slug":"cap-codex-parallel","status":"in_progress","phase":"verification","updated_at":"2026-06-23T00:00:00Z"}' > "$proj_parallel/.kontourai/flow-agents/cap-codex-parallel/state.json"
257
+ local rollout_parallel="$proj_parallel/rollout-parallel.jsonl"
258
+ printf '%s\n' '{"timestamp":"2026-06-23T00:00:00Z","type":"response_item","payload":{"type":"function_call","call_id":"call_pass","name":"exec_command","arguments":"{\"cmd\":\"find seed -type f\"}"}}' > "$rollout_parallel"
259
+ printf '%s\n' '{"timestamp":"2026-06-23T00:00:01Z","type":"response_item","payload":{"type":"function_call","call_id":"call_fail","name":"exec_command","arguments":"{\"cmd\":\"cat seed/src/window.js\"}"}}' >> "$rollout_parallel"
260
+ printf '%s\n' '{"timestamp":"2026-06-23T00:00:02Z","type":"response_item","payload":{"type":"function_call_output","call_id":"call_pass","output":"Process exited with code 0\nOutput:\n..."}}' >> "$rollout_parallel"
261
+ printf '%s\n' '{"timestamp":"2026-06-23T00:00:03Z","type":"response_item","payload":{"type":"function_call_output","call_id":"call_fail","output":"Process exited with code 1\nOutput:\n..."}}' >> "$rollout_parallel"
262
+ printf '{"hook_event_name":"PostToolUse","tool_name":"Bash","cwd":"%s","tool_input":{"command":"find seed -type f"},"transcript_path":"%s"}' "$proj_parallel" "$rollout_parallel" \
263
+ | env CODEX_HOME="$home" CLAUDE_PROJECT_DIR="$home" bash -c "$capcmd" >/dev/null 2>&1 || true
264
+ printf '{"hook_event_name":"PostToolUse","tool_name":"Bash","cwd":"%s","tool_input":{"command":"cat seed/src/window.js"},"transcript_path":"%s"}' "$proj_parallel" "$rollout_parallel" \
265
+ | env CODEX_HOME="$home" CLAUDE_PROJECT_DIR="$home" bash -c "$capcmd" >/dev/null 2>&1 || true
266
+ local log_parallel="$proj_parallel/.kontourai/flow-agents/cap-codex-parallel/command-log.jsonl"
267
+ if rg -q '"command":"find seed -type f","observedResult":"pass","exitCode":0' "$log_parallel" 2>/dev/null \
268
+ && rg -q '"command":"cat seed/src/window.js","observedResult":"fail","exitCode":1' "$log_parallel" 2>/dev/null; then
269
+ _p "Codex banner PARALLEL: cmd correlation keeps each command attached to its own exit code"
270
+ else
271
+ _f "Codex banner PARALLEL: command/result attribution crossed or stayed unresolved: $(cat "$log_parallel" 2>/dev/null)"
272
+ fi
249
273
  }
250
274
 
251
275
  run_bundle "Claude Code" "$ROOT/dist/claude-code/install.sh" ".claude/settings.json" "CLAUDE_PROJECT_DIR"
@@ -2,13 +2,18 @@
2
2
  set -uo pipefail
3
3
 
4
4
  ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
5
- SCRIPT="$ROOT/scripts/effective-backlog-settings.js"
6
- PROJECT="$ROOT/context/settings/backlog-provider-settings.json"
7
- GLOBAL="$ROOT/evals/fixtures/backlog-provider-settings/global-default.json"
8
- OVERRIDE="$ROOT/evals/fixtures/backlog-provider-settings/project-override.json"
9
- EMPTY="$(mktemp)"
10
- trap 'rm -f "$EMPTY"' EXIT
11
- printf '{"schema_version":"1.0","projects":[]}\n' > "$EMPTY"
5
+ CLI="$ROOT/build/src/cli.js"
6
+ BACKLOG_SETTINGS="$ROOT/context/settings/backlog-provider-settings.json"
7
+ ASSIGNMENT_SETTINGS="$ROOT/context/settings/assignment-provider-settings.json"
8
+ BACKLOG_GLOBAL="$ROOT/evals/fixtures/backlog-provider-settings/global-default.json"
9
+ BACKLOG_OVERRIDE="$ROOT/evals/fixtures/backlog-provider-settings/project-override.json"
10
+ TMPDIR_EVAL="$(mktemp -d)"
11
+ EMPTY_BACKLOG="$TMPDIR_EVAL/empty-backlog-settings.json"
12
+ EMPTY_ASSIGNMENT="$TMPDIR_EVAL/empty-assignment-settings.json"
13
+ trap 'rm -rf "$TMPDIR_EVAL"' EXIT
14
+
15
+ printf '{"schema_version":"1.0","projects":[]}\n' > "$EMPTY_BACKLOG"
16
+ printf '{"schema_version":"1.0","projects":[]}\n' > "$EMPTY_ASSIGNMENT"
12
17
 
13
18
  errors=0
14
19
  pass() { echo " ✓ $1"; }
@@ -18,17 +23,32 @@ json_value() {
18
23
  NO_COLOR=1 FORCE_COLOR=0 node -e 'const fs=require("fs"); let cur=JSON.parse(fs.readFileSync(0,"utf8")); for (const part of process.argv[1].split(".")) cur=Array.isArray(cur) ? cur[Number(part)] : cur[part]; console.log(cur);' "$1"
19
24
  }
20
25
 
21
- echo "=== Effective Backlog Settings ==="
26
+ echo "=== Effective provider settings ==="
27
+
28
+ # Build exactly once before calling the actual compiled CLI commands below.
29
+ if (cd "$ROOT" && npm run build --silent); then
30
+ pass "compiled CLI build succeeds"
31
+ else
32
+ fail "compiled CLI build succeeds"
33
+ fi
22
34
 
23
- default_result="$(cd "$ROOT" && npm run --silent effective-backlog-settings -- --repo-path . --json)"
24
- [[ "$(printf '%s' "$default_result" | json_value status)" == "configured" ]] && pass "default project settings resolve through npm command" || fail "default project settings resolve through npm command"
35
+ if [[ ! -f "$CLI" ]]; then
36
+ fail "compiled CLI is available"
37
+ else
38
+ pass "compiled CLI is available"
39
+ fi
40
+
41
+ echo "--- existing backlog precedence and ask-user behavior ---"
42
+
43
+ default_result="$(node "$CLI" effective-backlog-settings --repo-path "$ROOT" --json 2>/dev/null)"
44
+ [[ "$(printf '%s' "$default_result" | json_value status)" == "configured" ]] && pass "default project settings resolve through compiled CLI" || fail "default project settings resolve through compiled CLI"
25
45
  [[ "$(printf '%s' "$default_result" | json_value settings.work_item_provider.kind)" == "github" ]] && pass "default provider kind is github" || fail "default provider kind is github"
26
46
  [[ "$(printf '%s' "$default_result" | json_value settings.work_item_provider.repo.owner)" == "kontourai" ]] && pass "default repo owner is kontourai" || fail "default repo owner is kontourai"
27
47
  [[ "$(printf '%s' "$default_result" | json_value settings.work_item_provider.repo.name)" == "flow-agents" ]] && pass "default repo name is flow-agents" || fail "default repo name is flow-agents"
28
48
  [[ "$(printf '%s' "$default_result" | json_value settings.board_provider.board.number)" == "1" ]] && pass "default project number is 1" || fail "default project number is 1"
29
49
  ! printf '%s' "$default_result" | rg -q '/build/context/settings/backlog-provider-settings.json' && pass "default settings path is not build-relative" || fail "default settings path is not build-relative"
30
50
 
31
- configured="$(node "$SCRIPT" --repo-path "$ROOT" --project-settings "$PROJECT" --global-settings "$EMPTY" --json)"
51
+ configured="$(node "$CLI" effective-backlog-settings --repo-path "$ROOT" --project-settings "$BACKLOG_SETTINGS" --global-settings "$EMPTY_BACKLOG" --json)"
32
52
  [[ "$(printf '%s' "$configured" | json_value status)" == "configured" ]] && pass "configured repo resolves" || fail "configured repo resolves"
33
53
  [[ "$(printf '%s' "$configured" | json_value settings.work_item_provider.kind)" == "github" ]] && pass "provider kind is github" || fail "provider kind is github"
34
54
  [[ "$(printf '%s' "$configured" | json_value settings.work_item_provider.repo.owner)" == "kontourai" ]] && pass "repo owner is kontourai" || fail "repo owner is kontourai"
@@ -38,21 +58,104 @@ printf '%s' "$configured" | rg -F -q '"ready_statuses": [' && pass "filters incl
38
58
  printf '%s' "$configured" | rg -F -q '"include_labels": []' && pass "filters do not require labels by default" || fail "filters do not require labels by default"
39
59
  printf '%s' "$configured" | rg -q '"prefer_finishing_active_work": true' && pass "WIP policy prefers finishing active work" || fail "WIP policy prefers finishing active work"
40
60
 
41
- override_result="$(node "$SCRIPT" --repo-path "$ROOT" --project-settings "$OVERRIDE" --global-settings "$GLOBAL" --json)"
61
+ override_result="$(node "$CLI" effective-backlog-settings --repo-path "$ROOT" --project-settings "$BACKLOG_OVERRIDE" --global-settings "$BACKLOG_GLOBAL" --json)"
42
62
  [[ "$(printf '%s' "$override_result" | json_value source)" == "project" ]] && pass "project settings override global defaults" || fail "project settings override global defaults"
43
63
  [[ "$(printf '%s' "$override_result" | json_value settings.board_provider.board.number)" == "1" ]] && pass "project override keeps Project 1" || fail "project override keeps Project 1"
44
64
  ! printf '%s' "$override_result" | rg -q 'global-ready' && pass "project override replaces global filters" || fail "project override replaces global filters"
45
65
 
46
- missing_output="$(node "$SCRIPT" --repo-path "$ROOT" --project-settings "$EMPTY" --global-settings "$EMPTY" --json 2>/dev/null)"
66
+ missing_output="$(node "$CLI" effective-backlog-settings --repo-path "$ROOT" --project-settings "$EMPTY_BACKLOG" --global-settings "$EMPTY_BACKLOG" --json 2>/dev/null)"
47
67
  missing_status=$?
48
68
  [[ "$missing_status" -eq 2 ]] && pass "missing settings exits with ask-user status" || fail "missing settings exits with ask-user status"
49
69
  [[ "$(printf '%s' "$missing_output" | json_value status)" == "ask_user" ]] && pass "missing settings reports ask_user" || fail "missing settings reports ask_user"
50
70
  printf '%s' "$missing_output" | rg -q 'WorkItemProvider and BoardProvider' && pass "missing settings names provider roles" || fail "missing settings names provider roles"
51
71
 
72
+ echo "--- public self-configuration and external multi-repository settings ---"
73
+
74
+ # Product-specific fleet routing belongs in consumer-owned settings. The public package proves
75
+ # that an external settings file can configure multiple repositories without embedding those
76
+ # consumer mappings in Flow Agents source.
77
+ if node --input-type=module - "$ROOT" "$CLI" "$TMPDIR_EVAL/repos" "$BACKLOG_SETTINGS" "$ASSIGNMENT_SETTINGS" "$EMPTY_BACKLOG" "$EMPTY_ASSIGNMENT" <<'NODE'
78
+ import { execFileSync } from "node:child_process";
79
+ import fs from "node:fs";
80
+ import path from "node:path";
81
+ import Ajv2020 from "ajv/dist/2020.js";
82
+
83
+ const [root, cli, reposRoot, publicBacklogPath, publicAssignmentPath, emptyBacklog, emptyAssignment] = process.argv.slice(2);
84
+ const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
85
+ const assert = (condition, message) => {
86
+ if (!condition) throw new Error(message);
87
+ };
88
+
89
+ const backlogSchema = readJson(path.join(root, "schemas/backlog-provider-settings.schema.json"));
90
+ const assignmentSchema = readJson(path.join(root, "schemas/assignment-provider-settings.schema.json"));
91
+ const ajv = new Ajv2020({ allErrors: true });
92
+ const validateBacklog = ajv.compile(backlogSchema);
93
+ const validateAssignment = ajv.compile(assignmentSchema);
94
+
95
+ const publicBacklog = readJson(publicBacklogPath);
96
+ const publicAssignment = readJson(publicAssignmentPath);
97
+ assert(validateBacklog(publicBacklog), `public backlog settings schema validation failed: ${ajv.errorsText(validateBacklog.errors)}`);
98
+ assert(validateAssignment(publicAssignment), `public assignment settings schema validation failed: ${ajv.errorsText(validateAssignment.errors)}`);
99
+ assert(publicBacklog.projects.length === 1 && publicBacklog.projects[0]?.project?.repo?.name === "flow-agents", "public backlog settings must remain self-only");
100
+ assert(publicAssignment.projects.length === 1 && publicAssignment.projects[0]?.project?.repo?.name === "flow-agents", "public assignment settings must remain self-only");
101
+
102
+ const owner = "example-org";
103
+ const targets = ["alpha", "beta"];
104
+ const projectNumber = 42;
105
+ const repoRef = (name) => ({ owner, name, url: `https://github.com/${owner}/${name}` });
106
+ const externalBacklog = {
107
+ schema_version: "1.0",
108
+ projects: targets.map((name) => ({
109
+ project: { repo: repoRef(name) },
110
+ work_item_provider: { role: "WorkItemProvider", kind: "github", repo: repoRef(name), capabilities: ["issues", "labels", "assignees", "pr_links", "comments"] },
111
+ board_provider: { role: "BoardProvider", kind: "github", repo: repoRef(name), board: { type: "github_project", owner, number: projectNumber, url: `https://github.com/orgs/${owner}/projects/${projectNumber}` }, capabilities: ["projects_boards", "status_fields", "custom_fields"] },
112
+ selection: { filters: { issue_state: "open", include_labels: [], ready_statuses: ["ready"], exclude_statuses: ["triage", "in_progress", "blocked", "review", "verification", "done"] }, wip_policy: { prefer_finishing_active_work: true, active_statuses: ["in_progress", "review", "verification"], block_new_work_when_active_count_exceeds: 0 } },
113
+ })),
114
+ };
115
+ const externalAssignment = {
116
+ schema_version: "1.0",
117
+ projects: targets.map((name) => ({
118
+ project: { repo: repoRef(name) },
119
+ provider: { kind: "github", repo: repoRef(name), capabilities: ["assignees", "labels", "comments"] },
120
+ policy: { label_name: "agent:claimed", claim_comment_marker: "<!-- flow-agents:assignment-claim -->", human_assignee_policy: { behavior: "ask_first", idle_threshold_days: 3 }, comment_refresh_on_phase_transition: false },
121
+ })),
122
+ };
123
+ assert(validateBacklog(externalBacklog), `external backlog settings schema validation failed: ${ajv.errorsText(validateBacklog.errors)}`);
124
+ assert(validateAssignment(externalAssignment), `external assignment settings schema validation failed: ${ajv.errorsText(validateAssignment.errors)}`);
125
+
126
+ fs.mkdirSync(reposRoot, { recursive: true });
127
+ const externalBacklogPath = path.join(reposRoot, "backlog-provider-settings.json");
128
+ const externalAssignmentPath = path.join(reposRoot, "assignment-provider-settings.json");
129
+ fs.writeFileSync(externalBacklogPath, JSON.stringify(externalBacklog, null, 2));
130
+ fs.writeFileSync(externalAssignmentPath, JSON.stringify(externalAssignment, null, 2));
131
+
132
+ for (const name of targets) {
133
+ const repoPath = path.join(reposRoot, name);
134
+ fs.mkdirSync(repoPath, { recursive: true });
135
+ fs.writeFileSync(path.join(repoPath, "package.json"), JSON.stringify({ name: `fixture-${name}`, repository: { type: "git", url: `https://github.com/${owner}/${name}.git` } }, null, 2));
136
+ const resolve = (command, globalPath, emptyProject) => JSON.parse(execFileSync(process.execPath, [cli, command, "--repo-path", repoPath, "--project-settings", emptyProject, "--global-settings", globalPath, "--json"], { encoding: "utf8" }));
137
+ const backlogResult = resolve("effective-backlog-settings", externalBacklogPath, emptyBacklog);
138
+ const assignmentResult = resolve("effective-assignment-provider-settings", externalAssignmentPath, emptyAssignment);
139
+
140
+ assert(backlogResult.status === "configured" && backlogResult.source === "global", `${name} backlog settings must resolve from the external file`);
141
+ assert(backlogResult.settings.work_item_provider?.repo?.name === name, `${name} must select its own work item repository`);
142
+ assert(backlogResult.settings.board_provider?.board?.number === projectNumber, `${name} must select the external board`);
143
+ assert(assignmentResult.status === "configured" && assignmentResult.source === "global", `${name} assignment settings must resolve from the external file`);
144
+ assert(assignmentResult.settings.provider?.repo?.name === name, `${name} must select its own assignment repository`);
145
+ }
146
+
147
+ console.log("Public settings remain self-only and external multi-repository settings resolve through the supported global precedence layer.");
148
+ NODE
149
+ then
150
+ pass "public settings stay self-only and external multi-repository settings resolve"
151
+ else
152
+ fail "public settings stay self-only and external multi-repository settings resolve"
153
+ fi
154
+
52
155
  if [[ "$errors" -eq 0 ]]; then
53
- echo "Effective backlog settings checks passed"
156
+ echo "Effective provider settings checks passed"
54
157
  else
55
- echo "Effective backlog settings checks failed: $errors"
158
+ echo "Effective provider settings checks failed: $errors"
56
159
  fi
57
160
 
58
161
  exit "$errors"