@kontourai/flow-agents 0.1.2 → 0.3.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 (117) hide show
  1. package/.github/dependabot.yml +23 -0
  2. package/.github/workflows/release-please.yml +31 -0
  3. package/.github/workflows/runtime-compat.yml +118 -0
  4. package/CHANGELOG.md +46 -0
  5. package/CONTRIBUTING.md +4 -0
  6. package/README.md +80 -18
  7. package/build/src/cli/flow-kit.js +9 -4
  8. package/build/src/cli/init.js +215 -5
  9. package/build/src/cli/runtime-adapter.js +9 -5
  10. package/build/src/cli/telemetry-doctor.js +4 -1
  11. package/build/src/cli/utterance-check.js +65 -1
  12. package/build/src/runtime-adapters.js +34 -0
  13. package/build/src/tools/build-universal-bundles.js +285 -0
  14. package/build/src/tools/filter-installed-packs.js +3 -0
  15. package/build/src/tools/validate-source-tree.js +5 -1
  16. package/console.telemetry.json +115 -20
  17. package/context/scripts/telemetry/lib/config.sh +5 -1
  18. package/context/settings/flow-agents-settings.json +7 -0
  19. package/docs/_layouts/default.html +2 -0
  20. package/docs/context-map.md +1 -0
  21. package/docs/index.md +53 -4
  22. package/docs/integrations/conformance.md +246 -0
  23. package/docs/integrations/framework-adapter.md +275 -0
  24. package/docs/integrations/harness-install.md +213 -0
  25. package/docs/integrations/index.md +58 -0
  26. package/docs/integrations/knowledge-kit-live.md +211 -0
  27. package/docs/kit-authoring-guide.md +169 -0
  28. package/docs/north-star.md +2 -2
  29. package/docs/spec/runtime-hook-surface.md +525 -0
  30. package/docs/survey-utterance-check.md +211 -94
  31. package/docs/vision.md +45 -0
  32. package/evals/acceptance/run.sh +13 -2
  33. package/evals/acceptance/test_knowledge_kit_live.sh +221 -0
  34. package/evals/acceptance/test_opencode_harness.sh +121 -0
  35. package/evals/acceptance/test_pi_harness.sh +113 -0
  36. package/evals/integration/test_bundle_install.sh +226 -1
  37. package/evals/integration/test_bundle_lifecycle.sh +641 -0
  38. package/evals/integration/test_runtime_adapter_activation.sh +113 -1
  39. package/evals/integration/test_utterance_check.sh +291 -44
  40. package/evals/run.sh +2 -0
  41. package/evals/static/test_universal_bundles.sh +137 -2
  42. package/integrations/strands/README.md +256 -0
  43. package/integrations/strands/example.py +74 -0
  44. package/integrations/strands/examples/knowledge_kit_live.py +461 -0
  45. package/integrations/strands/flow_agents_strands/__init__.py +27 -0
  46. package/integrations/strands/flow_agents_strands/hooks.py +194 -0
  47. package/integrations/strands/flow_agents_strands/policy.py +348 -0
  48. package/integrations/strands/flow_agents_strands/steering.py +225 -0
  49. package/integrations/strands/flow_agents_strands/telemetry.py +238 -0
  50. package/integrations/strands/pyproject.toml +38 -0
  51. package/integrations/strands/tests/__init__.py +0 -0
  52. package/integrations/strands/tests/test_hooks.py +392 -0
  53. package/integrations/strands/tests/test_policy.py +315 -0
  54. package/integrations/strands/tests/test_telemetry.py +184 -0
  55. package/integrations/strands-ts/README.md +224 -0
  56. package/integrations/strands-ts/bin/conformance-shim.mjs +257 -0
  57. package/integrations/strands-ts/package.json +53 -0
  58. package/integrations/strands-ts/src/hooks.ts +312 -0
  59. package/integrations/strands-ts/src/index.ts +22 -0
  60. package/integrations/strands-ts/src/policy.ts +345 -0
  61. package/integrations/strands-ts/src/telemetry.ts +251 -0
  62. package/integrations/strands-ts/test/test-policy.ts +322 -0
  63. package/integrations/strands-ts/test/test-steering.ts +159 -0
  64. package/integrations/strands-ts/test/test-telemetry.ts +226 -0
  65. package/integrations/strands-ts/tsconfig.json +20 -0
  66. package/kits/catalog.json +6 -0
  67. package/kits/knowledge/adapters/default-store/index.js +821 -0
  68. package/kits/knowledge/adapters/flow-runner/index.js +1179 -0
  69. package/kits/knowledge/adapters/flow-runner/telemetry.js +174 -0
  70. package/kits/knowledge/docs/README.md +135 -0
  71. package/kits/knowledge/docs/store-contract.md +526 -0
  72. package/kits/knowledge/evals/consolidation/suite.test.js +1234 -0
  73. package/kits/knowledge/evals/contract-suite/suite.test.js +670 -0
  74. package/kits/knowledge/evals/ingest-compile/suite.test.js +574 -0
  75. package/kits/knowledge/evals/synthesis/suite.test.js +909 -0
  76. package/kits/knowledge/flows/compile.flow.json +60 -0
  77. package/kits/knowledge/flows/consolidate.flow.json +77 -0
  78. package/kits/knowledge/flows/ingest.flow.json +60 -0
  79. package/kits/knowledge/flows/store-contract.flow.json +48 -0
  80. package/kits/knowledge/flows/synthesize.flow.json +77 -0
  81. package/kits/knowledge/kit.json +78 -0
  82. package/package.json +7 -2
  83. package/packaging/conformance/README.md +142 -0
  84. package/packaging/conformance/fixtures/config-protection--allow-no-path.json +18 -0
  85. package/packaging/conformance/fixtures/config-protection--allow-safe-file.json +20 -0
  86. package/packaging/conformance/fixtures/config-protection--block-biome.json +20 -0
  87. package/packaging/conformance/fixtures/config-protection--block-eslintrc.json +20 -0
  88. package/packaging/conformance/fixtures/quality-gate--allow-no-path.json +17 -0
  89. package/packaging/conformance/fixtures/quality-gate--allow-nonexistent-file.json +19 -0
  90. package/packaging/conformance/fixtures/stop-goal-fit--allow-clean-cwd.json +17 -0
  91. package/packaging/conformance/fixtures/stop-goal-fit--block-strict-mode.json +23 -0
  92. package/packaging/conformance/fixtures/stop-goal-fit--warn-active-delivery.json +21 -0
  93. package/packaging/conformance/fixtures/workflow-steering--allow-no-state.json +16 -0
  94. package/packaging/conformance/fixtures/workflow-steering--inject-active-state.json +29 -0
  95. package/packaging/conformance/fixtures/workflow-steering--inject-subagent-steering.json +25 -0
  96. package/packaging/conformance/package.json +4 -0
  97. package/packaging/conformance/run-conformance.js +322 -0
  98. package/packaging/manifest.json +59 -0
  99. package/schemas/flow-agents-settings.schema.json +48 -0
  100. package/scripts/README.md +4 -0
  101. package/scripts/dogfood.js +16 -0
  102. package/scripts/hooks/opencode-hook-adapter.js +123 -0
  103. package/scripts/hooks/opencode-telemetry-hook.js +101 -0
  104. package/scripts/hooks/pi-hook-adapter.js +123 -0
  105. package/scripts/hooks/pi-telemetry-hook.js +105 -0
  106. package/scripts/hooks/run-hook.js +8 -0
  107. package/scripts/hooks/utterance-check.js +124 -22
  108. package/scripts/telemetry/lib/config.sh +5 -1
  109. package/src/cli/flow-kit.ts +10 -4
  110. package/src/cli/init.ts +219 -6
  111. package/src/cli/runtime-adapter.ts +10 -5
  112. package/src/cli/telemetry-doctor.ts +4 -1
  113. package/src/cli/utterance-check.ts +71 -1
  114. package/src/runtime-adapters.ts +35 -0
  115. package/src/tools/build-universal-bundles.ts +283 -0
  116. package/src/tools/filter-installed-packs.ts +3 -0
  117. package/src/tools/validate-source-tree.ts +5 -1
@@ -6,7 +6,11 @@ TELEMETRY_CONFIG_FILE="${TELEMETRY_CONFIG_FILE:-${TELEMETRY_DIR}/telemetry.conf}
6
6
 
7
7
  # Defaults
8
8
  TELEMETRY_ENABLED="${TELEMETRY_ENABLED:-true}"
9
- TELEMETRY_DATA_DIR="${TELEMETRY_DATA_DIR:-$(cd "${TELEMETRY_DIR}/../../.." && pwd)/.telemetry}"
9
+ # TELEMETRY_DIR is <workspace>/scripts/telemetry, so the workspace root is
10
+ # two levels up. Three levels escaped into the workspace's PARENT directory
11
+ # (caught by live acceptance smoke 2026-06-11: events landed in /tmp/.telemetry
12
+ # instead of the installed workspace).
13
+ TELEMETRY_DATA_DIR="${TELEMETRY_DATA_DIR:-$(cd "${TELEMETRY_DIR}/../.." && pwd)/.telemetry}"
10
14
  TELEMETRY_SESSION_DIR="${TELEMETRY_SESSION_DIR:-${TELEMETRY_DATA_DIR}/sessions}"
11
15
  TELEMETRY_ENRICH_SYSTEM="${TELEMETRY_ENRICH_SYSTEM:-true}"
12
16
  TELEMETRY_ENRICH_WORKSPACE="${TELEMETRY_ENRICH_WORKSPACE:-true}"
@@ -4,7 +4,7 @@ import * as path from "node:path";
4
4
  import { parseArgs, flagBool, flagString } from "../lib/args.js";
5
5
  import { assertPathContained, copyDir, isoNow, readJson, walkFiles, writeJson } from "../lib/fs.js";
6
6
  import { assertKitRepository } from "../flow-kit/validate.js";
7
- import { activateCodexLocal } from "../runtime-adapters.js";
7
+ import { activateCodexLocal, activateStrandsLocal } from "../runtime-adapters.js";
8
8
 
9
9
  const REGISTRY_REL = path.join("kits", "local", "installed-kits.json");
10
10
  const REPOSITORIES_REL = path.join("kits", "local", "repositories");
@@ -112,16 +112,22 @@ function status(argv: string[]): number {
112
112
  return 0;
113
113
  }
114
114
 
115
+ // Available adapters for the activate subcommand (Issue #32: added strands-local).
116
+ const AVAILABLE_ADAPTERS = ["codex-local", "strands-local"];
117
+
115
118
  function activate(argv: string[]): number {
116
119
  const args = parseArgs(argv);
117
120
  const dest = path.resolve(flagString(args.flags, "dest", ".") ?? ".");
118
121
  const sourceRoot = path.resolve(flagString(args.flags, "source-root", path.resolve(path.dirname(process.argv[1]), "..")) ?? ".");
119
122
  const adapter = flagString(args.flags, "adapter");
120
- if (adapter && adapter !== "codex-local") {
121
- console.log(JSON.stringify({ selected_adapter: null, available_adapters: ["codex-local"], supported_asset_classes: [], generated_runtime_files: [], skipped_assets: [], warnings: [], errors: [`unknown runtime adapter '${adapter}'; available adapters: codex-local`] }, null, 2));
123
+ if (adapter && !AVAILABLE_ADAPTERS.includes(adapter)) {
124
+ console.log(JSON.stringify({ selected_adapter: null, available_adapters: AVAILABLE_ADAPTERS, supported_asset_classes: [], generated_runtime_files: [], skipped_assets: [], warnings: [], errors: [`unknown runtime adapter '${adapter}'; available adapters: ${AVAILABLE_ADAPTERS.join(", ")}`] }, null, 2));
122
125
  return 2;
123
126
  }
124
- const result = activateCodexLocal(sourceRoot, dest);
127
+ // Default to codex-local for backward compatibility; strands-local is opt-in via --adapter.
128
+ const result = adapter === "strands-local"
129
+ ? activateStrandsLocal(sourceRoot, dest)
130
+ : activateCodexLocal(sourceRoot, dest);
125
131
  console.log(JSON.stringify(result, null, 2));
126
132
  return Array.isArray(result.errors) && result.errors.length ? 1 : 0;
127
133
  }
package/src/cli/init.ts CHANGED
@@ -9,7 +9,7 @@ import { activateCodexLocal } from "../runtime-adapters.js";
9
9
  import { main as buildBundles } from "../tools/build-universal-bundles.js";
10
10
  import { root } from "../tools/common.js";
11
11
 
12
- type Runtime = "base" | "codex" | "claude-code" | "kiro";
12
+ type Runtime = "base" | "codex" | "claude-code" | "kiro" | "opencode" | "pi";
13
13
  type TelemetrySink = "local-files" | "local-kontour-console" | "kontour-hosted-console" | "user-hosted-console" | "kontour-cloud" | "hosted-kontour-console";
14
14
 
15
15
  type InitOptions = {
@@ -30,13 +30,69 @@ const runtimeBundles: Record<Runtime, string> = {
30
30
  codex: "codex",
31
31
  "claude-code": "claude-code",
32
32
  kiro: "kiro",
33
+ opencode: "opencode",
34
+ pi: "pi",
33
35
  };
34
36
 
37
+ // Stable marker present in every Flow Agents claude-code hook command.
38
+ // Used by scope-collision detection to identify an existing flow-agents install.
39
+ // Marker must be distinctive to Flow Agents generated settings. Sibling
40
+ // products from the same lineage ship identically named hook scripts such
41
+ // as claude-hook-adapter.js, so script filenames are NOT a safe marker.
42
+ export const COLLISION_MARKER = "Recording Flow Agents telemetry";
43
+
44
+ /**
45
+ * Check whether a user-level Claude Code settings file already contains
46
+ * Flow Agents hook commands. If it does, print a WARNING explaining that
47
+ * Claude Code merges user-level and project-level settings and runs ALL
48
+ * matching hooks, so having flow-agents in both places causes duplicate
49
+ * hook execution (double telemetry, double policy enforcement).
50
+ *
51
+ * The check does NOT block the install; it is advisory only.
52
+ *
53
+ * @param userSettingsFile Path to inspect (defaults to $HOME/.claude/settings.json;
54
+ * overridable via FLOW_AGENTS_USER_CLAUDE_SETTINGS env var for testability).
55
+ * @returns true if a collision was detected, false otherwise.
56
+ */
57
+ export function checkScopeCollision(userSettingsFile?: string): boolean {
58
+ const filePath = userSettingsFile
59
+ ?? process.env["FLOW_AGENTS_USER_CLAUDE_SETTINGS"]
60
+ ?? path.join(os.homedir(), ".claude", "settings.json");
61
+ if (!fs.existsSync(filePath)) return false;
62
+ let text: string;
63
+ try {
64
+ text = fs.readFileSync(filePath, "utf8");
65
+ } catch {
66
+ return false;
67
+ }
68
+ if (!text.includes(COLLISION_MARKER)) return false;
69
+ console.warn(
70
+ `\nWARNING: Flow Agents scope collision detected.\n` +
71
+ ` ${filePath}\n` +
72
+ `already contains Flow Agents hook commands (marker: ${COLLISION_MARKER}).\n` +
73
+ `\n` +
74
+ `Claude Code merges user-level (~/.claude/settings.json) and project-level\n` +
75
+ `(.claude/settings.json) settings, then runs ALL matching hooks from both files.\n` +
76
+ `Installing Flow Agents at the project level while it is also present at the\n` +
77
+ `user level will cause duplicate hook execution: telemetry events are recorded\n` +
78
+ `twice and policy hooks (workflow-steering, config-protection, quality-gate,\n` +
79
+ `stop-goal-fit) run twice per event.\n` +
80
+ `\n` +
81
+ `To resolve:\n` +
82
+ ` - Remove the hooks section from ${filePath} and rely solely on the\n` +
83
+ ` project-level .claude/settings.json installed by flow-agents init, OR\n` +
84
+ ` - Remove the project-level install and keep only the user-level one.\n` +
85
+ `\n` +
86
+ `The install will continue; resolve the collision before running Claude Code.\n`
87
+ );
88
+ return true;
89
+ }
90
+
35
91
  function usage(): void {
36
92
  console.error(`usage: flow-agents init [options]
37
93
 
38
94
  Options:
39
- --runtime base|codex|claude-code|kiro
95
+ --runtime base|codex|claude-code|kiro|opencode|pi
40
96
  --dest PATH
41
97
  --telemetry-sink local-files|local-kontour-console|kontour-hosted-console|user-hosted-console
42
98
  --console-url URL
@@ -52,8 +108,8 @@ Options:
52
108
  function normalizeRuntime(value: string | undefined): Runtime | undefined {
53
109
  if (!value) return undefined;
54
110
  if (value === "claude") return "claude-code";
55
- if (value === "base" || value === "codex" || value === "claude-code" || value === "kiro") return value;
56
- throw new Error(`unknown runtime '${value}'; expected base, codex, claude-code, or kiro`);
111
+ if (value === "base" || value === "codex" || value === "claude-code" || value === "kiro" || value === "opencode" || value === "pi") return value;
112
+ throw new Error(`unknown runtime '${value}'; expected base, codex, claude-code, kiro, opencode, or pi`);
57
113
  }
58
114
 
59
115
  function normalizeTelemetrySink(value: string): TelemetrySink {
@@ -86,7 +142,7 @@ async function questionHidden(prompt: string): Promise<string> {
86
142
  let value = "";
87
143
  const onData = (buffer: Buffer) => {
88
144
  const text = buffer.toString("utf8");
89
- if (text === "\u0003") {
145
+ if (text === "") {
90
146
  stdout.write("\n");
91
147
  process.exit(130);
92
148
  }
@@ -97,7 +153,7 @@ async function questionHidden(prompt: string): Promise<string> {
97
153
  resolve(value);
98
154
  return;
99
155
  }
100
- if (text === "\u007f") {
156
+ if (text === "") {
101
157
  value = value.slice(0, -1);
102
158
  return;
103
159
  }
@@ -235,6 +291,18 @@ export async function main(argv = process.argv.slice(2)): Promise<number> {
235
291
  const headless = argv.includes("--yes") || argv.includes("--headless") || !process.stdin.isTTY;
236
292
  try {
237
293
  const options = headless ? headlessOptions(argv) : await interactiveOptions(argv);
294
+ // Scope-collision check for claude-code: Claude Code merges user-level
295
+ // (~/.claude/settings.json) and project-level (.claude/settings.json) settings
296
+ // and runs ALL matching hooks from both files. If a user-level settings file
297
+ // already contains flow-agents hooks, installing at the project level will
298
+ // cause duplicate hook execution. We warn but do not block.
299
+ //
300
+ // Codex note: Codex hooks live in .codex/hooks.json (project-level only).
301
+ // There is no well-known user-level codex hooks file in our install paths,
302
+ // so no collision check is needed for codex.
303
+ if (options.runtime === "claude-code") {
304
+ checkScopeCollision();
305
+ }
238
306
  const bundle = ensureBundle(options.runtime);
239
307
  const installed = installBundle(bundle, options);
240
308
  if (installed !== 0) return installed;
@@ -245,4 +313,149 @@ export async function main(argv = process.argv.slice(2)): Promise<number> {
245
313
  }
246
314
  }
247
315
 
316
+ // ---------------------------------------------------------------------------
317
+ // Dogfood subcommand
318
+ //
319
+ // `flow-agents dogfood --runtime claude-code [--dest PATH]`
320
+ //
321
+ // Writes only the hook-wiring artifacts for the specified runtime into the
322
+ // target directory (default: cwd). Unlike a full install, dogfood:
323
+ // - Does NOT rsync the full bundle (no agents/skills duplication).
324
+ // - Reads the generated settings/config from dist/<runtime>/ so the output
325
+ // cannot drift from what the bundle generates (DRY guarantee).
326
+ // - For claude-code: OMITS permissions.defaultMode and
327
+ // skipDangerousModePermissionPrompt (permissive defaults are for installed
328
+ // workspaces, not source repos).
329
+ // - Runs the same scope-collision warning as init.
330
+ // ---------------------------------------------------------------------------
331
+
332
+ function dogfoodUsage(): void {
333
+ console.error(`usage: flow-agents dogfood [options]
334
+
335
+ Options:
336
+ --runtime claude-code|codex|opencode|pi (required)
337
+ --dest PATH (default: cwd)
338
+ --yes, --headless
339
+ `);
340
+ }
341
+
342
+ type DogfoodRuntime = "claude-code" | "codex" | "opencode" | "pi";
343
+
344
+ function normalizeDogfoodRuntime(value: string | undefined): DogfoodRuntime | undefined {
345
+ if (!value) return undefined;
346
+ if (value === "claude" || value === "claude-code") return "claude-code";
347
+ if (value === "codex" || value === "opencode" || value === "pi") return value;
348
+ throw new Error(`dogfood: unsupported runtime '${value}'; expected claude-code, codex, opencode, or pi`);
349
+ }
350
+
351
+ /**
352
+ * Write the claude-code hook-wiring artifacts into dest.
353
+ * Reads dist/claude-code/.claude/settings.json (generated by build-bundles),
354
+ * strips the permissive-mode permission keys (defaultMode, skipDangerousModePermissionPrompt),
355
+ * and writes .claude/settings.json to dest.
356
+ */
357
+ function dogfoodClaudeCode(bundleRoot: string, dest: string): void {
358
+ const sourcePath = path.join(bundleRoot, ".claude", "settings.json");
359
+ if (!fs.existsSync(sourcePath)) throw new Error(`dogfood: bundle settings missing: ${sourcePath}`);
360
+ const settings = JSON.parse(fs.readFileSync(sourcePath, "utf8")) as Record<string, unknown>;
361
+ // Remove permissive defaults that are only appropriate for installed workspaces.
362
+ // These keys must not be present in the source repo's .claude/settings.json.
363
+ delete settings["permissions"];
364
+ delete settings["skipDangerousModePermissionPrompt"];
365
+ const outDir = path.join(dest, ".claude");
366
+ fs.mkdirSync(outDir, { recursive: true });
367
+ fs.writeFileSync(path.join(outDir, "settings.json"), `${JSON.stringify(settings, null, 2)}\n`, "utf8");
368
+ }
369
+
370
+ /**
371
+ * Write the codex hook-wiring artifacts into dest.
372
+ * Reads dist/codex/.codex/hooks.json and writes .codex/hooks.json to dest.
373
+ * The monolithic .codex/config.toml is not written here because it contains
374
+ * workspace settings (approvals_reviewer, features) that would override the
375
+ * developer's existing codex configuration. Only the hooks file is written.
376
+ */
377
+ function dogfoodCodex(bundleRoot: string, dest: string): void {
378
+ const sourcePath = path.join(bundleRoot, ".codex", "hooks.json");
379
+ if (!fs.existsSync(sourcePath)) throw new Error(`dogfood: bundle hooks.json missing: ${sourcePath}`);
380
+ const hooks = fs.readFileSync(sourcePath, "utf8");
381
+ const outDir = path.join(dest, ".codex");
382
+ fs.mkdirSync(outDir, { recursive: true });
383
+ fs.writeFileSync(path.join(outDir, "hooks.json"), hooks, "utf8");
384
+ }
385
+
386
+ /**
387
+ * Write the opencode hook-wiring artifacts into dest.
388
+ * Reads dist/opencode/.opencode/plugins/flow-agents.js and opencode.json,
389
+ * and writes them into dest. These are the minimal hook-wiring files; the
390
+ * full skill/agent tree is not copied.
391
+ */
392
+ function dogfoodOpencode(bundleRoot: string, dest: string): void {
393
+ const pluginSource = path.join(bundleRoot, ".opencode", "plugins", "flow-agents.js");
394
+ const configSource = path.join(bundleRoot, "opencode.json");
395
+ if (!fs.existsSync(pluginSource)) throw new Error(`dogfood: bundle plugin missing: ${pluginSource}`);
396
+ const pluginDir = path.join(dest, ".opencode", "plugins");
397
+ fs.mkdirSync(pluginDir, { recursive: true });
398
+ fs.copyFileSync(pluginSource, path.join(pluginDir, "flow-agents.js"));
399
+ // Write opencode.json only if it does not already exist to avoid clobbering
400
+ // any workspace-specific opencode configuration.
401
+ const destConfig = path.join(dest, "opencode.json");
402
+ if (!fs.existsSync(destConfig) && fs.existsSync(configSource)) {
403
+ fs.copyFileSync(configSource, destConfig);
404
+ }
405
+ }
406
+
407
+ /**
408
+ * Write the pi hook-wiring artifacts into dest.
409
+ * Reads dist/pi/.pi/extensions/flow-agents.ts and writes it to dest.
410
+ * The extension is the only hook-wiring file needed for pi.
411
+ */
412
+ function dogfoodPi(bundleRoot: string, dest: string): void {
413
+ const extSource = path.join(bundleRoot, ".pi", "extensions", "flow-agents.ts");
414
+ if (!fs.existsSync(extSource)) throw new Error(`dogfood: bundle extension missing: ${extSource}`);
415
+ const extDir = path.join(dest, ".pi", "extensions");
416
+ fs.mkdirSync(extDir, { recursive: true });
417
+ fs.copyFileSync(extSource, path.join(extDir, "flow-agents.ts"));
418
+ }
419
+
420
+ export async function mainDogfood(argv = process.argv.slice(2)): Promise<number> {
421
+ if (argv.includes("--help") || argv.includes("-h")) {
422
+ dogfoodUsage();
423
+ return 0;
424
+ }
425
+ const args = parseArgs(argv);
426
+ try {
427
+ const runtimeRaw = flagString(args.flags, "runtime");
428
+ const runtime = normalizeDogfoodRuntime(runtimeRaw);
429
+ if (!runtime) {
430
+ console.error("dogfood: --runtime is required (claude-code, codex, opencode, or pi)");
431
+ dogfoodUsage();
432
+ return 2;
433
+ }
434
+ const dest = path.resolve(flagString(args.flags, "dest") ?? process.cwd());
435
+
436
+ // Ensure the bundle for the requested runtime is built.
437
+ const bundleRuntime: Runtime = runtime as Runtime;
438
+ const bundleRoot = ensureBundle(bundleRuntime);
439
+
440
+ // Scope-collision check: warn if user-level claude settings already has flow-agents.
441
+ // Codex: no user-level hooks file in our install paths — skip with note above.
442
+ if (runtime === "claude-code") {
443
+ checkScopeCollision();
444
+ }
445
+
446
+ // Write only the hook-wiring artifacts, not the full bundle.
447
+ fs.mkdirSync(dest, { recursive: true });
448
+ if (runtime === "claude-code") dogfoodClaudeCode(bundleRoot, dest);
449
+ else if (runtime === "codex") dogfoodCodex(bundleRoot, dest);
450
+ else if (runtime === "opencode") dogfoodOpencode(bundleRoot, dest);
451
+ else if (runtime === "pi") dogfoodPi(bundleRoot, dest);
452
+
453
+ console.log(`Flow Agents dogfood hooks wired for ${runtime} in ${dest}`);
454
+ return 0;
455
+ } catch (error) {
456
+ console.error(`flow-agents dogfood: ${(error as Error).message}`);
457
+ return 2;
458
+ }
459
+ }
460
+
248
461
  if (import.meta.url === `file://${process.argv[1]}`) process.exit(await main());
@@ -1,22 +1,27 @@
1
1
  import * as path from "node:path";
2
2
  import { parseArgs, flagString } from "../lib/args.js";
3
- import { activateCodexLocal } from "../runtime-adapters.js";
3
+ import { activateCodexLocal, activateStrandsLocal } from "../runtime-adapters.js";
4
+
5
+ const AVAILABLE_ADAPTERS = ["codex-local", "strands-local"];
4
6
 
5
7
  export function main(argv = process.argv.slice(2)): number {
6
8
  const [command, ...rest] = argv;
7
9
  if (command !== "activate") {
8
- console.error("usage: runtime-adapter activate [--dest DIR] [--source-root DIR] [--adapter codex-local]");
10
+ console.error("usage: runtime-adapter activate [--dest DIR] [--source-root DIR] [--adapter codex-local|strands-local]");
9
11
  return 2;
10
12
  }
11
13
  const args = parseArgs(rest);
12
14
  const dest = path.resolve(flagString(args.flags, "dest", ".") ?? ".");
13
15
  const sourceRoot = path.resolve(flagString(args.flags, "source-root", path.resolve(path.dirname(process.argv[1]), "..")) ?? ".");
14
16
  const adapter = flagString(args.flags, "adapter");
15
- if (adapter && adapter !== "codex-local") {
16
- console.log(JSON.stringify({ selected_adapter: null, available_adapters: ["codex-local"], supported_asset_classes: [], generated_runtime_files: [], skipped_assets: [], warnings: [], errors: [`unknown runtime adapter '${adapter}'; available adapters: codex-local`] }, null, 2));
17
+ if (adapter && !AVAILABLE_ADAPTERS.includes(adapter)) {
18
+ console.log(JSON.stringify({ selected_adapter: null, available_adapters: AVAILABLE_ADAPTERS, supported_asset_classes: [], generated_runtime_files: [], skipped_assets: [], warnings: [], errors: [`unknown runtime adapter '${adapter}'; available adapters: ${AVAILABLE_ADAPTERS.join(", ")}`] }, null, 2));
17
19
  return 2;
18
20
  }
19
- const result = activateCodexLocal(sourceRoot, dest);
21
+ // Default to codex-local for backward compatibility; strands-local is opt-in via --adapter.
22
+ const result = adapter === "strands-local"
23
+ ? activateStrandsLocal(sourceRoot, dest)
24
+ : activateCodexLocal(sourceRoot, dest);
20
25
  console.log(JSON.stringify(result, null, 2));
21
26
  return Array.isArray(result.errors) && result.errors.length ? 1 : 0;
22
27
  }
@@ -82,7 +82,10 @@ function channelConfigValue(config: Config, channel: string, key: string, fallba
82
82
 
83
83
  function telemetryDataDir(dest: string): string {
84
84
  const configured = process.env.TELEMETRY_DATA_DIR;
85
- return configured ? path.resolve(dest, configured) : path.resolve(dest, "..", ".telemetry");
85
+ // Must mirror scripts/telemetry/lib/config.sh: the sink lives INSIDE the
86
+ // workspace at <dest>/.telemetry. The previous "../.telemetry" duplicated
87
+ // the parent-escape bug fixed in config.sh on 2026-06-11.
88
+ return configured ? path.resolve(dest, configured) : path.resolve(dest, ".telemetry");
86
89
  }
87
90
 
88
91
  function deriveConsoleEndpoint(consoleUrl: string, explicitEndpoint: string): string {
@@ -60,6 +60,10 @@ interface SurveyMod {
60
60
  referenceUtteranceExtractor: SurveyExtractor;
61
61
  }
62
62
 
63
+ interface AnthropicSurveyMod {
64
+ createAnthropicUtteranceExtractor: (options?: { model?: string; apiKey?: string }) => SurveyExtractor;
65
+ }
66
+
63
67
  // ---------------------------------------------------------------------------
64
68
  // Helpers
65
69
  // ---------------------------------------------------------------------------
@@ -76,6 +80,9 @@ function usage(): void {
76
80
  " --utterance TEXT Utterance text to check (required unless --not-configured).",
77
81
  " --bundle-path FILE Trust bundle JSON file. Omit for an empty bundle (all unsupported).",
78
82
  " --agent-id ID Agent identifier for provenance (default: flow-agents-utterance-check).",
83
+ " --extractor NAME Extractor to use: 'reference' (default, pattern-based) or 'anthropic'",
84
+ " (model-backed, requires ANTHROPIC_API_KEY and @kontourai/survey/anthropic).",
85
+ " --model MODEL Model for the anthropic extractor (e.g. claude-haiku-4-5).",
79
86
  " --not-configured Skip survey call; output not_configured without error.",
80
87
  " --strict Exit non-zero when any badge is disputed, rejected, or unsupported.",
81
88
  " --help Show this help.",
@@ -116,6 +123,45 @@ async function loadSurvey(): Promise<SurveyMod | undefined> {
116
123
  }
117
124
  }
118
125
 
126
+ /**
127
+ * Dynamically import @kontourai/survey/anthropic and create the Anthropic extractor.
128
+ * Fails open with a clear not_configured message when the key or peer dep is missing.
129
+ */
130
+ async function loadAnthropicExtractor(model?: string): Promise<SurveyExtractor | { notConfigured: true; reason: string }> {
131
+ const apiKey = process.env.ANTHROPIC_API_KEY;
132
+ if (!apiKey) {
133
+ return {
134
+ notConfigured: true,
135
+ reason:
136
+ "anthropic extractor requires ANTHROPIC_API_KEY to be set. " +
137
+ "Set the environment variable or switch extractor to 'reference'.",
138
+ };
139
+ }
140
+ try {
141
+ const pkg = "@kontourai/survey/anthropic";
142
+ const mod = await (Function("m", "return import(m)")(pkg) as Promise<unknown>) as AnthropicSurveyMod;
143
+ if (typeof mod.createAnthropicUtteranceExtractor !== "function") {
144
+ return {
145
+ notConfigured: true,
146
+ reason:
147
+ "@kontourai/survey/anthropic does not export createAnthropicUtteranceExtractor. " +
148
+ "Update @kontourai/survey to a version that supports the anthropic extractor.",
149
+ };
150
+ }
151
+ const opts: { model?: string; apiKey?: string } = { apiKey };
152
+ if (model) opts.model = model;
153
+ return mod.createAnthropicUtteranceExtractor(opts);
154
+ } catch (err) {
155
+ const msg = err instanceof Error ? err.message : String(err);
156
+ return {
157
+ notConfigured: true,
158
+ reason:
159
+ `@kontourai/survey/anthropic is not available: ${msg}. ` +
160
+ "Install @kontourai/survey with the anthropic subpath export, or switch extractor to 'reference'.",
161
+ };
162
+ }
163
+ }
164
+
119
165
  // ---------------------------------------------------------------------------
120
166
  // Core check logic
121
167
  // ---------------------------------------------------------------------------
@@ -131,6 +177,8 @@ async function runCheck(argv: string[]): Promise<number> {
131
177
  const agentId = flagString(flags, "agent-id") ?? "flow-agents-utterance-check";
132
178
  const notConfigured = flagBool(flags, "not-configured");
133
179
  const strict = flagBool(flags, "strict");
180
+ const extractorName = flagString(flags, "extractor") ?? "reference";
181
+ const model = flagString(flags, "model");
134
182
 
135
183
  if (notConfigured) {
136
184
  const report: UtteranceReport = {
@@ -181,9 +229,31 @@ async function runCheck(argv: string[]): Promise<number> {
181
229
 
182
230
  const { surveyAgentUtterance, referenceUtteranceExtractor } = survey;
183
231
 
232
+ // Resolve which extractor to use.
233
+ let extractor: SurveyExtractor;
234
+ if (extractorName === "anthropic") {
235
+ const anthropicResult = await loadAnthropicExtractor(model);
236
+ if ("notConfigured" in anthropicResult) {
237
+ // Fail open: emit not_configured with a clear reason rather than erroring.
238
+ const report: UtteranceReport = {
239
+ status: "not_configured",
240
+ agent_id: agentId,
241
+ utterance_excerpt: excerptText(utterance),
242
+ statements: [],
243
+ summary: anthropicResult.reason,
244
+ };
245
+ process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
246
+ process.stderr.write(`[UtteranceCheck] not_configured: ${anthropicResult.reason}\n`);
247
+ return 0;
248
+ }
249
+ extractor = anthropicResult;
250
+ } else {
251
+ extractor = referenceUtteranceExtractor;
252
+ }
253
+
184
254
  let trustReport: SurveyTrustReport;
185
255
  try {
186
- trustReport = await surveyAgentUtterance(utterance, referenceUtteranceExtractor, {
256
+ trustReport = await surveyAgentUtterance(utterance, extractor, {
187
257
  bundle,
188
258
  agentId,
189
259
  });
@@ -152,3 +152,38 @@ export function activateCodexLocal(sourceRoot: string, dest: string): Record<str
152
152
  generated.push({ asset_class: "activation-manifest", path: relPath(dest, manifestPath), kit_id: "runtime", asset_id: "codex-local.activation", source_path: manifestPath.split(path.sep).join("/") });
153
153
  return { selected_adapter: "codex-local", supported_asset_classes: ["flows"], generated_runtime_files: generated, skipped_assets: skipped, warnings: inventory.warnings, errors: inventory.errors };
154
154
  }
155
+
156
+ // Decision Q3 (Issue #32): Option (a) — new adapter id "strands-local" rather than
157
+ // loading kit flows inside FlowAgentsHooks. Rationale: activation is a workspace-prep
158
+ // concern (reads catalog + installed kits, writes runtime files, produces diagnostics).
159
+ // Keeping it in the CLI adapter layer maximises reuse of readKitInventory and safeSegment,
160
+ // mirrors the codex-local pattern exactly, and keeps framework adapters free of catalog-
161
+ // layout knowledge. The Strands steering layer then reads the written runtime files.
162
+ export function activateStrandsLocal(sourceRoot: string, dest: string): Record<string, unknown> {
163
+ const inventory = readKitInventory(sourceRoot, dest);
164
+ // Runtime flows land at .flow-agents/runtime/strands/flows/<kit-id>/<asset-id>.flow.json
165
+ // so the Strands steering context can glob for *.flow.json under this path.
166
+ const runtimeDir = path.join(dest, ".flow-agents", "runtime", "strands");
167
+ const generated: Record<string, string>[] = [];
168
+ const skipped: Record<string, string | null>[] = [];
169
+ for (const asset of inventory.assets) {
170
+ if (asset.asset_class !== "flows") {
171
+ skipped.push({ asset_class: asset.asset_class, path: asset.relative_path, kit_id: asset.kit_id, asset_id: asset.asset_id, reason: "asset class is diagnostic-only for strands-local" });
172
+ continue;
173
+ }
174
+ if (!asset.asset_id) {
175
+ skipped.push({ asset_class: asset.asset_class, path: asset.relative_path, kit_id: asset.kit_id, asset_id: null, reason: "flow asset is missing an id" });
176
+ continue;
177
+ }
178
+ const output = path.join(runtimeDir, "flows", safeSegment(asset.kit_id), `${safeSegment(asset.asset_id)}.flow.json`);
179
+ fs.mkdirSync(path.dirname(output), { recursive: true });
180
+ fs.copyFileSync(asset.source_path, output);
181
+ generated.push({ asset_class: asset.asset_class, path: relPath(dest, output), kit_id: asset.kit_id, asset_id: asset.asset_id, source_path: asset.source_path.split(path.sep).join("/") });
182
+ }
183
+ fs.mkdirSync(runtimeDir, { recursive: true });
184
+ const manifest = { schema_version: "1.0", adapter: "strands-local", supported_asset_classes: ["flows"], generated_runtime_files: generated, skipped_assets: skipped, warnings: inventory.warnings, errors: inventory.errors };
185
+ const manifestPath = path.join(runtimeDir, "activation.json");
186
+ writeJson(manifestPath, manifest);
187
+ generated.push({ asset_class: "activation-manifest", path: relPath(dest, manifestPath), kit_id: "runtime", asset_id: "strands-local.activation", source_path: manifestPath.split(path.sep).join("/") });
188
+ return { selected_adapter: "strands-local", supported_asset_classes: ["flows"], generated_runtime_files: generated, skipped_assets: skipped, warnings: inventory.warnings, errors: inventory.errors };
189
+ }