@apralabs/apra-fleet 0.4.4 → 0.4.5

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 (268) hide show
  1. package/README.md +49 -4
  2. package/dist/agents/backlog-groomer.md +5 -0
  3. package/dist/agents/ci-watcher.md +5 -0
  4. package/dist/agents/deployer.md +20 -2
  5. package/dist/agents/doer.md +38 -2
  6. package/dist/agents/harvester.md +12 -9
  7. package/dist/agents/integ-test-runner.md +5 -0
  8. package/dist/agents/kb-reconciler.md +6 -0
  9. package/dist/agents/plan-reviewer.md +5 -0
  10. package/dist/agents/planner.md +5 -0
  11. package/dist/agents/regression-test-runner.md +5 -0
  12. package/dist/agents/reviewer.md +67 -15
  13. package/dist/agents/schemas/deployer-output.json +5 -0
  14. package/dist/agents/schemas/doer-output.json +78 -2
  15. package/dist/agents/schemas/reviewer-output.json +104 -2
  16. package/dist/cli/auth.js +5 -1
  17. package/dist/cli/beads-pin.js +6 -7
  18. package/dist/cli/claude-mod.d.ts +75 -0
  19. package/dist/cli/claude-mod.js +288 -0
  20. package/dist/cli/dolt-install.d.ts +1 -1
  21. package/dist/cli/dolt-install.js +5 -1
  22. package/dist/cli/fleet-se-guard.d.ts +8 -0
  23. package/dist/cli/fleet-se-guard.js +19 -3
  24. package/dist/cli/install-guard.d.ts +9 -0
  25. package/dist/cli/install-guard.js +24 -0
  26. package/dist/cli/install.d.ts +12 -0
  27. package/dist/cli/install.js +180 -20
  28. package/dist/cli/kb-profile.d.ts +16 -0
  29. package/dist/cli/kb-profile.js +81 -0
  30. package/dist/cli/start.js +3 -0
  31. package/dist/cli/uninstall.js +13 -3
  32. package/dist/cli/update.d.ts +4 -0
  33. package/dist/cli/update.js +19 -3
  34. package/dist/commands/kb-server.d.ts +10 -1
  35. package/dist/commands/kb-server.js +285 -11
  36. package/dist/index.js +22 -1
  37. package/dist/os/git-executable.d.ts +57 -0
  38. package/dist/os/git-executable.js +85 -0
  39. package/dist/os/go-concurrency.d.ts +44 -0
  40. package/dist/os/go-concurrency.js +53 -0
  41. package/dist/os/index.d.ts +1 -0
  42. package/dist/os/index.js +1 -0
  43. package/dist/os/linux.d.ts +2 -0
  44. package/dist/os/linux.js +10 -1
  45. package/dist/os/os-commands.d.ts +25 -0
  46. package/dist/os/os-commands.js +2 -0
  47. package/dist/os/windows-executable.d.ts +53 -0
  48. package/dist/os/windows-executable.js +185 -0
  49. package/dist/os/windows-gitbash.d.ts +23 -14
  50. package/dist/os/windows-gitbash.js +40 -16
  51. package/dist/os/windows.d.ts +2 -0
  52. package/dist/os/windows.js +37 -6
  53. package/dist/paths.d.ts +10 -1
  54. package/dist/paths.js +19 -2
  55. package/dist/services/agy-project.d.ts +7 -1
  56. package/dist/services/agy-project.js +7 -2
  57. package/dist/services/auth-socket.d.ts +18 -0
  58. package/dist/services/auth-socket.js +30 -4
  59. package/dist/services/credential-store.d.ts +33 -0
  60. package/dist/services/credential-store.js +79 -2
  61. package/dist/services/http-transport.d.ts +29 -0
  62. package/dist/services/http-transport.js +166 -37
  63. package/dist/services/kb-tool-profile.d.ts +36 -0
  64. package/dist/services/kb-tool-profile.js +88 -0
  65. package/dist/services/knowledge/bible-blob-id.js +10 -1
  66. package/dist/services/knowledge/bible-import.d.ts +108 -0
  67. package/dist/services/knowledge/bible-import.js +137 -4
  68. package/dist/services/knowledge/file-hash.js +6 -5
  69. package/dist/services/knowledge/http-provider.d.ts +303 -20
  70. package/dist/services/knowledge/http-provider.js +795 -125
  71. package/dist/services/knowledge/kb-config.d.ts +65 -1
  72. package/dist/services/knowledge/kb-config.js +143 -3
  73. package/dist/services/knowledge/kb-http-auth-state.d.ts +26 -0
  74. package/dist/services/knowledge/kb-http-auth-state.js +40 -0
  75. package/dist/services/knowledge/kb-providers.d.ts +9 -2
  76. package/dist/services/knowledge/kb-providers.js +67 -37
  77. package/dist/services/knowledge/kb-removed-scope-keys.js +1 -1
  78. package/dist/services/knowledge/kb-self.d.ts +122 -9
  79. package/dist/services/knowledge/kb-self.js +196 -36
  80. package/dist/services/knowledge/member-bible-view.js +16 -3
  81. package/dist/services/knowledge/path-validation.d.ts +7 -0
  82. package/dist/services/knowledge/path-validation.js +11 -0
  83. package/dist/services/knowledge/project-slug.js +3 -2
  84. package/dist/services/knowledge/repository-header.d.ts +77 -0
  85. package/dist/services/knowledge/repository-header.js +233 -0
  86. package/dist/services/knowledge/require-sqlite-project.d.ts +1 -1
  87. package/dist/services/knowledge/require-sqlite-project.js +1 -1
  88. package/dist/services/knowledge/sqlite-provider.d.ts +169 -0
  89. package/dist/services/knowledge/sqlite-provider.js +416 -4
  90. package/dist/services/knowledge/types.d.ts +15 -2
  91. package/dist/services/member-busy.d.ts +12 -0
  92. package/dist/services/member-busy.js +20 -0
  93. package/dist/services/member-config-io.d.ts +3 -2
  94. package/dist/services/member-config-io.js +7 -4
  95. package/dist/services/member-fleet-install.js +1 -0
  96. package/dist/services/member-tool-allowlist.d.ts +1 -1
  97. package/dist/services/member-tool-allowlist.js +8 -4
  98. package/dist/services/port-holder.js +2 -1
  99. package/dist/services/service-manager/types.d.ts +17 -1
  100. package/dist/services/service-manager/windows.d.ts +7 -2
  101. package/dist/services/service-manager/windows.js +28 -11
  102. package/dist/services/service-notice.d.ts +7 -0
  103. package/dist/services/service-notice.js +19 -0
  104. package/dist/services/session-registry.d.ts +13 -0
  105. package/dist/services/session-registry.js +13 -0
  106. package/dist/services/session-roots.d.ts +67 -0
  107. package/dist/services/session-roots.js +126 -0
  108. package/dist/services/statusline.d.ts +21 -0
  109. package/dist/services/statusline.js +97 -1
  110. package/dist/services/supervisor-service-cleanup.js +2 -1
  111. package/dist/services/tool-registry.js +108 -20
  112. package/dist/services/tool-scope.d.ts +34 -1
  113. package/dist/services/tool-scope.js +27 -2
  114. package/dist/services/vcs/azure-devops.js +10 -0
  115. package/dist/services/vcs/bitbucket.d.ts +22 -1
  116. package/dist/services/vcs/bitbucket.js +163 -17
  117. package/dist/services/vcs/types.d.ts +25 -2
  118. package/dist/services/watch/project-resolver.js +2 -1
  119. package/dist/skills/pm/cost.md +5 -1
  120. package/dist/skills/pm/index.md +9 -9
  121. package/dist/skills/pm/sprint.md +2 -1
  122. package/dist/tools/check-status.d.ts +51 -0
  123. package/dist/tools/check-status.js +124 -12
  124. package/dist/tools/code-intelligence-freshness.js +1 -1
  125. package/dist/tools/code-intelligence-gitnexus.d.ts +19 -0
  126. package/dist/tools/code-intelligence-gitnexus.js +166 -9
  127. package/dist/tools/code-intelligence-readiness.d.ts +58 -1
  128. package/dist/tools/code-intelligence-readiness.js +93 -8
  129. package/dist/tools/code-intelligence-reindex.d.ts +25 -1
  130. package/dist/tools/code-intelligence-reindex.js +76 -4
  131. package/dist/tools/code-intelligence.d.ts +1 -1
  132. package/dist/tools/code-intelligence.js +1 -1
  133. package/dist/tools/execute-command.js +14 -8
  134. package/dist/tools/execute-prompt.js +6 -2
  135. package/dist/tools/fleet-snapshot.d.ts +21 -0
  136. package/dist/tools/fleet-snapshot.js +78 -0
  137. package/dist/tools/kb-bible-commit.d.ts +25 -11
  138. package/dist/tools/kb-bible-commit.js +142 -33
  139. package/dist/tools/kb-capture.d.ts +2 -2
  140. package/dist/tools/kb-context.js +47 -27
  141. package/dist/tools/kb-demote.d.ts +27 -0
  142. package/dist/tools/kb-demote.js +37 -0
  143. package/dist/tools/kb-export.d.ts +35 -3
  144. package/dist/tools/kb-export.js +56 -13
  145. package/dist/tools/kb-feedback.d.ts +2 -0
  146. package/dist/tools/kb-feedback.js +17 -7
  147. package/dist/tools/kb-harvest.js +28 -9
  148. package/dist/tools/kb-import.d.ts +18 -2
  149. package/dist/tools/kb-import.js +24 -9
  150. package/dist/tools/kb-invalidate.d.ts +11 -3
  151. package/dist/tools/kb-invalidate.js +80 -7
  152. package/dist/tools/kb-list.js +38 -10
  153. package/dist/tools/kb-promote.js +6 -4
  154. package/dist/tools/kb-query.d.ts +3 -0
  155. package/dist/tools/kb-query.js +181 -37
  156. package/dist/tools/kb-session-prime.d.ts +4 -4
  157. package/dist/tools/kb-session-prime.js +89 -9
  158. package/dist/tools/kb-setup.d.ts +20 -0
  159. package/dist/tools/kb-setup.js +149 -11
  160. package/dist/tools/list-members.js +1 -1
  161. package/dist/tools/member-detail.js +7 -3
  162. package/dist/tools/provision-vcs-auth.d.ts +28 -3
  163. package/dist/tools/provision-vcs-auth.js +53 -7
  164. package/dist/tools/receive-files.js +7 -4
  165. package/dist/tools/send-files.js +5 -4
  166. package/dist/tools/send-message.d.ts +3 -0
  167. package/dist/tools/send-message.js +15 -2
  168. package/dist/tools/stop-prompt.js +3 -1
  169. package/dist/tools/vcs-credential-exec.d.ts +45 -3
  170. package/dist/tools/vcs-credential-exec.js +90 -11
  171. package/dist/utils/process-utils.js +5 -1
  172. package/dist/utils/redact-known-secrets.d.ts +17 -0
  173. package/dist/utils/redact-known-secrets.js +70 -0
  174. package/dist/utils/skill-matrix.js +1 -1
  175. package/dist/utils/vcs-provider-detect.js +2 -2
  176. package/dist/workflows/auto-sprint.js +245 -9
  177. package/package.json +10 -7
  178. package/packages/apra-fleet-client/package.json +1 -1
  179. package/packages/apra-fleet-client/src/client/api.mjs +172 -19
  180. package/packages/apra-fleet-client/src/client/reconnecting-transport.mjs +35 -2
  181. package/packages/apra-fleet-client/src/client/transport.mjs +6 -0
  182. package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +5 -0
  183. package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +5 -0
  184. package/packages/apra-fleet-se/apra-pm/agents/deployer.md +20 -2
  185. package/packages/apra-fleet-se/apra-pm/agents/doer.md +38 -2
  186. package/packages/apra-fleet-se/apra-pm/agents/harvester.md +12 -9
  187. package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +5 -0
  188. package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +6 -0
  189. package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +5 -0
  190. package/packages/apra-fleet-se/apra-pm/agents/planner.md +5 -0
  191. package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +5 -0
  192. package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +67 -15
  193. package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-output.json +5 -0
  194. package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +78 -2
  195. package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +104 -2
  196. package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +5 -1
  197. package/packages/apra-fleet-se/apra-pm/skills/pm/index.md +9 -9
  198. package/packages/apra-fleet-se/apra-pm/skills/pm/sprint.md +2 -1
  199. package/packages/apra-fleet-se/bin/cli.mjs +104 -31
  200. package/packages/apra-fleet-se/bin/serve.mjs +46 -8
  201. package/packages/apra-fleet-se/fleet-sprint/abort.mjs +184 -32
  202. package/packages/apra-fleet-se/fleet-sprint/bd-sync-command.mjs +69 -0
  203. package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +21 -0
  204. package/packages/apra-fleet-se/fleet-sprint/beads-lock-probe.mjs +176 -0
  205. package/packages/apra-fleet-se/fleet-sprint/beads-reachability.mjs +126 -0
  206. package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +158 -1
  207. package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +82 -2
  208. package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +23 -6
  209. package/packages/apra-fleet-se/fleet-sprint/decision-notify.mjs +338 -0
  210. package/packages/apra-fleet-se/fleet-sprint/decision-wait.mjs +731 -0
  211. package/packages/apra-fleet-se/fleet-sprint/decisions.mjs +372 -0
  212. package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +44 -11
  213. package/packages/apra-fleet-se/fleet-sprint/docs/README.md +4 -1
  214. package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +9 -3
  215. package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +314 -19
  216. package/packages/apra-fleet-se/fleet-sprint/errors.mjs +72 -4
  217. package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +7 -1
  218. package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +112 -1
  219. package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +36 -2
  220. package/packages/apra-fleet-se/fleet-sprint/kb.mjs +736 -101
  221. package/packages/apra-fleet-se/fleet-sprint/member-init-probe.mjs +1 -1
  222. package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +7 -1
  223. package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +49 -2
  224. package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +206 -3
  225. package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +61 -3
  226. package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +81 -31
  227. package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +7 -3
  228. package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +39 -14
  229. package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +17 -1
  230. package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +18 -3
  231. package/packages/apra-fleet-se/fleet-sprint/pr-body.mjs +14 -1
  232. package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +32 -5
  233. package/packages/apra-fleet-se/fleet-sprint/runner.js +824 -98
  234. package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +4 -2
  235. package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +54 -1
  236. package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +29 -2
  237. package/packages/apra-fleet-se/fleet-sprint/set-aside.mjs +288 -0
  238. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +3 -2
  239. package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +20 -0
  240. package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +21 -0
  241. package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +9 -0
  242. package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +605 -32
  243. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +811 -17
  244. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +89 -1
  245. package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +225 -2
  246. package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +59 -3
  247. package/packages/apra-fleet-se/src/supervisor/api.mjs +148 -8
  248. package/packages/apra-fleet-se/src/supervisor/dashboard.mjs +6 -3
  249. package/packages/apra-fleet-se/src/supervisor/dolt-mutex.mjs +30 -10
  250. package/packages/apra-fleet-se/src/supervisor/fleet-members.mjs +17 -4
  251. package/packages/apra-fleet-se/src/supervisor/history.mjs +8 -1
  252. package/packages/apra-fleet-se/src/supervisor/id-allocator.mjs +92 -2
  253. package/packages/apra-fleet-se/src/supervisor/proxy.mjs +26 -1
  254. package/packages/apra-fleet-se/src/supervisor/server.mjs +151 -8
  255. package/packages/apra-fleet-se/src/supervisor/spawner.mjs +11 -9
  256. package/packages/apra-fleet-se/src/supervisor/watchdog.mjs +7 -1
  257. package/packages/apra-fleet-workflow/package.json +2 -1
  258. package/packages/apra-fleet-workflow/src/viewer/index.mjs +86 -5
  259. package/packages/apra-fleet-workflow/src/viewer/request-guard.mjs +222 -0
  260. package/packages/apra-fleet-workflow/src/workflow/index.mjs +34 -2
  261. package/plugins/claude-code/fleet-status/.claude-plugin/plugin.json +7 -0
  262. package/plugins/claude-code/fleet-status/hooks/hooks.json +1 -0
  263. package/plugins/claude-code/fleet-status/hooks/register.tsx +906 -0
  264. package/plugins/claude-code/fleet-status/types/index.d.ts +88 -0
  265. package/skills/fleet/auth-bitbucket.md +47 -20
  266. package/skills/fleet/onboarding.md +1 -1
  267. package/skills/fleet/skill-matrix.md +3 -3
  268. package/version.json +1 -1
@@ -3,17 +3,26 @@ import { KB_REMOVED_SCOPE_KEYS_SHAPE } from '../services/knowledge/kb-removed-sc
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { installKbPostCommitHook } from './kb-invalidate.js';
6
- import { KB_CONFIG_PATH } from '../services/knowledge/kb-config.js';
6
+ import { KB_CONFIG_PATH, MIN_REQUEST_TIMEOUT_MS, MAX_REQUEST_TIMEOUT_MS, readKbConfigForMerge } from '../services/knowledge/kb-config.js';
7
7
  import { encryptPassword } from '../utils/crypto.js';
8
+ import { findSecretTokens, hasSecretToken, formatSecretToken, legacyTokenWarning } from '../services/secret-token.js';
9
+ import { lookupServerSecretMeta } from '../services/credential-store.js';
8
10
  import { logWarn } from '../utils/log-helpers.js';
9
11
  import { resolveKbAnchor, KbSelfError } from '../services/knowledge/kb-self.js';
12
+ import { KB_TOOL_PROFILE_NAMES, makeKbToolProfile, describeKbToolProfile } from '../services/kb-tool-profile.js';
10
13
  export const kbSetupSchema = z.object({
11
14
  provider: z.enum(['sqlite', 'http']).optional()
12
15
  .describe('KB provider type (default: sqlite)'),
13
16
  remote: z.string().optional()
14
17
  .describe('Remote KB server URL, http(s) only (required when provider=http). Use https for any non-loopback host: plain http sends the token in cleartext.'),
15
18
  token: z.string().optional()
16
- .describe('Authentication token for remote KB server (stored encrypted, never logged)'),
19
+ .describe('Authentication token for remote KB server. Either a literal token (stored encrypted, never logged) or exactly one named fleet secret placeholder of the form {{secret.NAME}} with nothing around it: then only the placeholder is stored and the server looks the secret up on each request, so rotating the secret needs no kb_setup re-run. For provider http the secret must already exist (apra-fleet secret --set NAME --persist -y).'),
20
+ request_timeout_ms: z.number().int().min(MIN_REQUEST_TIMEOUT_MS).max(MAX_REQUEST_TIMEOUT_MS).optional()
21
+ .describe('Socket idle timeout in milliseconds for each request to the remote KB server, 1000-120000 (default 5000). Not a per-request deadline: a call can wait up to about twice this when it first reads the server capabilities.'),
22
+ tool_profile: z.enum(['full', 'developer', 'custom']).optional()
23
+ .describe('Install-wide KB tool profile for interactive (non-member) sessions: full (every kb_* tool, the default), developer (kb_session_prime, kb_query, kb_context, kb_capture, kb_feedback) or custom (the kb_* names in tool_profile_tools). Member sessions and sprint roles are unaffected. Takes effect when a session reconnects. A usability control, not a security boundary; developer hides kb_setup, so switch back with the CLI: apra-fleet kb profile full. Can be set alone, without provider/remote/token.'),
24
+ tool_profile_tools: z.array(z.string()).optional()
25
+ .describe('The registered kb_* tool names the custom tool_profile serves (required with tool_profile custom, not allowed otherwise). An unknown name is refused and nothing is written.'),
17
26
  // Removed pre-redesign scope keys: declared only so a caller still passing one
18
27
  // is refused with E-SCOPE-KEY-REMOVED instead of silently re-scoped.
19
28
  ...KB_REMOVED_SCOPE_KEYS_SHAPE,
@@ -57,6 +66,111 @@ function checkRemoteUrl(remote) {
57
66
  }
58
67
  return [];
59
68
  }
69
+ /**
70
+ * Throws when request_timeout_ms is set but is not an integer in range. The
71
+ * MCP layer parses input with kbSetupSchema already; this re-check covers
72
+ * direct callers of kbSetup, which get no schema parse.
73
+ */
74
+ function checkRequestTimeout(value) {
75
+ if (kbSetupSchema.shape.request_timeout_ms.safeParse(value).success)
76
+ return;
77
+ throw new Error(`kb_setup: request_timeout_ms must be an integer between ${MIN_REQUEST_TIMEOUT_MS} and ${MAX_REQUEST_TIMEOUT_MS}, got ${value}`);
78
+ }
79
+ /**
80
+ * The tool profile the input asks for, validated before any side effect, or
81
+ * null when the input does not set one. Throws a clear Error on an invalid
82
+ * combination or an unknown custom tool name.
83
+ */
84
+ function checkToolProfile(input) {
85
+ if (input.tool_profile === undefined) {
86
+ if (input.tool_profile_tools !== undefined) {
87
+ throw new Error('kb_setup: tool_profile_tools is only valid with tool_profile "custom"');
88
+ }
89
+ return null;
90
+ }
91
+ if (!KB_TOOL_PROFILE_NAMES.includes(input.tool_profile)) {
92
+ throw new Error(`kb_setup: tool_profile must be one of ${KB_TOOL_PROFILE_NAMES.join(', ')}`);
93
+ }
94
+ if (input.tool_profile !== 'custom' && input.tool_profile_tools !== undefined) {
95
+ throw new Error('kb_setup: tool_profile_tools is only valid with tool_profile "custom"');
96
+ }
97
+ try {
98
+ return makeKbToolProfile(input.tool_profile, input.tool_profile_tools);
99
+ }
100
+ catch (err) {
101
+ throw new Error(`kb_setup: ${err.message}`);
102
+ }
103
+ }
104
+ /** Write a tool profile into a config object (only the tool_profile keys). */
105
+ function applyToolProfile(config, profile) {
106
+ config.tool_profile = profile.name;
107
+ if (profile.name === 'custom')
108
+ config.tool_profile_tools = [...profile.tools];
109
+ else
110
+ delete config.tool_profile_tools;
111
+ }
112
+ /** The step line reporting a profile change. */
113
+ function toolProfileStep(profile) {
114
+ return `Set KB tool profile to ${describeKbToolProfile(profile)}; takes effect when the session reconnects`;
115
+ }
116
+ /**
117
+ * Set the install-wide KB tool profile in the KB config, leaving every other
118
+ * key as it was (the `apra-fleet kb profile` CLI verb). Returns the steps.
119
+ * Throws KbConfigUnreadableError, writing nothing, when the existing file
120
+ * cannot be parsed: unlike kb_setup, this verb has no way to restore the remote
121
+ * url and token a rewrite would lose.
122
+ */
123
+ export function writeKbToolProfile(profile) {
124
+ const config = readKbConfigForMerge();
125
+ applyToolProfile(config, profile);
126
+ writeConfig(config);
127
+ return { steps: [toolProfileStep(profile), 'Wrote KB config to ' + KB_CONFIG_PATH] };
128
+ }
129
+ /**
130
+ * The provider the config will select once input is applied: the same rule
131
+ * as applySetupInput, so a token-only call against an existing http config
132
+ * counts as http.
133
+ */
134
+ function effectiveProvider(input, existing) {
135
+ if (input.provider || input.remote)
136
+ return input.provider || 'http';
137
+ return existing.provider === 'http' ? 'http' : 'sqlite';
138
+ }
139
+ /**
140
+ * Classify input.token. A literal returns null. A value containing a secret
141
+ * placeholder must be exactly one placeholder with nothing around it, else it
142
+ * is refused (naming the field, never echoing the value). When the resulting
143
+ * config is http the named secret must exist and be unexpired.
144
+ */
145
+ function checkTokenRef(input, provider) {
146
+ const token = input.token;
147
+ if (!token || !hasSecretToken(token))
148
+ return null;
149
+ const matches = findSecretTokens(token);
150
+ if (matches.length !== 1 || matches[0].raw !== token) {
151
+ throw new Error('kb_setup: token must be either a literal token or exactly one secret placeholder ' +
152
+ '({{secret.NAME}}) with no surrounding text, quotes or whitespace');
153
+ }
154
+ const { name, legacy } = matches[0];
155
+ if (provider === 'http') {
156
+ let found;
157
+ try {
158
+ found = lookupServerSecretMeta(name);
159
+ }
160
+ catch {
161
+ // The parser's message can quote part of credentials.json, so it is not repeated.
162
+ throw new Error(`kb_setup: token refers to secret "${name}", but the fleet credential store could not be read.`);
163
+ }
164
+ const fix = `Set it with: apra-fleet secret --set ${name} --persist -y`;
165
+ if (found.status === 'missing') {
166
+ throw new Error(`kb_setup: token refers to secret "${name}", which does not exist. ${fix}`);
167
+ }
168
+ if (found.status === 'expired') {
169
+ throw new Error(`kb_setup: token refers to secret "${name}", which has expired. Re-set it with: apra-fleet secret --set ${name} --persist -y`);
170
+ }
171
+ }
172
+ return { name, legacy };
173
+ }
60
174
  /**
61
175
  * The config kb_setup merges into. Absent -> empty. Malformed (bad JSON, or
62
176
  * not a JSON object) -> empty plus a warning: kb_setup is the tool an operator
@@ -100,7 +214,7 @@ function discardMalformed(warnings, reason) {
100
214
  * dropped with a warning: sending one server's bearer token to another
101
215
  * leaks the credential.
102
216
  */
103
- function applySetupInput(config, input, steps, warnings) {
217
+ function applySetupInput(config, input, ref, steps, warnings) {
104
218
  if (input.provider || input.remote) {
105
219
  config.provider = input.provider || 'http';
106
220
  }
@@ -110,15 +224,28 @@ function applySetupInput(config, input, steps, warnings) {
110
224
  if (input.remote) {
111
225
  const urlChanged = config.url !== input.remote;
112
226
  config.url = input.remote;
113
- if (urlChanged && !input.token && config.token_encrypted) {
227
+ if (urlChanged && !input.token && (config.token_encrypted || config.token_ref)) {
114
228
  delete config.token_encrypted;
229
+ delete config.token_ref;
115
230
  const warning = 'remote changed and no token was given: the token stored for the previous ' +
116
231
  'remote was removed rather than sent to the new one. Re-run kb_setup with a token.';
117
232
  logWarn('kb_setup', warning);
118
233
  warnings.push(warning);
119
234
  }
120
235
  }
121
- if (input.token) {
236
+ if (input.request_timeout_ms !== undefined) {
237
+ config.request_timeout_ms = input.request_timeout_ms;
238
+ steps.push('Stored request timeout');
239
+ }
240
+ if (input.token && ref) {
241
+ config.token_ref = formatSecretToken(ref.name);
242
+ delete config.token_encrypted;
243
+ steps.push(`Stored remote token as a reference to secret ${ref.name} (value is looked up per request, not stored)`);
244
+ if (ref.legacy)
245
+ warnings.push(legacyTokenWarning([ref.name]));
246
+ }
247
+ else if (input.token) {
248
+ delete config.token_ref;
122
249
  config.token_encrypted = encryptPassword(input.token);
123
250
  steps.push('Stored remote token encrypted (AES-256-GCM)');
124
251
  }
@@ -132,12 +259,18 @@ function writeConfig(config) {
132
259
  }
133
260
  export async function kbSetup(input, anchor) {
134
261
  const steps = [];
135
- // Validate before any side effect, so a bad remote installs no hook and
136
- // leaves any existing config untouched.
262
+ // Validate before any side effect, so a bad remote or timeout installs no
263
+ // hook and leaves any existing config untouched.
264
+ checkRequestTimeout(input.request_timeout_ms);
265
+ const toolProfile = checkToolProfile(input);
137
266
  const warnings = input.remote ? checkRemoteUrl(input.remote) : [];
138
267
  for (const warning of warnings) {
139
268
  logWarn('kb_setup', warning);
140
269
  }
270
+ // Read (not write) the existing config first: whether the named secret must
271
+ // exist depends on the provider the merged config ends up with.
272
+ const config = readExistingConfig(warnings);
273
+ const ref = checkTokenRef(input, effectiveProvider(input, config));
141
274
  // Install git post-commit hook into the calling session's own repo (kb-self.ts).
142
275
  // A folder that cannot carry a KB identity skips the hook with the typed
143
276
  // reason; the provider config below is machine-wide and is still written.
@@ -152,15 +285,20 @@ export async function kbSetup(input, anchor) {
152
285
  }
153
286
  if (repoPath !== null) {
154
287
  if (fs.existsSync(path.join(repoPath, '.git'))) {
155
- installKbPostCommitHook(repoPath);
156
- steps.push('Installed git post-commit hook for KB invalidation');
288
+ const hook = installKbPostCommitHook(repoPath);
289
+ steps.push(hook.installed
290
+ ? 'Installed git post-commit hook for KB invalidation'
291
+ : 'Skipped git hook: ' + hook.reason);
157
292
  }
158
293
  else {
159
294
  steps.push('Skipped git hook: no .git directory found at ' + repoPath);
160
295
  }
161
296
  }
162
- const config = readExistingConfig(warnings);
163
- applySetupInput(config, input, steps, warnings);
297
+ applySetupInput(config, input, ref, steps, warnings);
298
+ if (toolProfile) {
299
+ applyToolProfile(config, toolProfile);
300
+ steps.push(toolProfileStep(toolProfile));
301
+ }
164
302
  writeConfig(config);
165
303
  steps.push('Wrote KB config to ' + KB_CONFIG_PATH);
166
304
  return JSON.stringify({ success: true, steps, warnings });
@@ -71,7 +71,7 @@ export async function listMembers(input) {
71
71
  if (filterTags && filterTags.length > 0) {
72
72
  agents = agents.filter(a => filterTags.every(tag => a.tags?.includes(tag)));
73
73
  }
74
- if (agents.length === 0)
74
+ if (agents.length === 0 && format !== 'json')
75
75
  return 'No members registered.';
76
76
  const authStatusPromises = agents.map(getAuthStatus);
77
77
  const authStatuses = await Promise.all(authStatusPromises);
@@ -315,9 +315,13 @@ export async function memberDetail(input) {
315
315
  if (cloudSection) {
316
316
  result.cloud = cloudSection;
317
317
  }
318
- // Update statusline with observed state
319
- const slStatus = session.status === 'busy' ? 'busy' : 'idle';
320
- writeStatusline(new Map([[agent.id, slStatus]]));
318
+ // Update statusline with observed state -- idle only, as fleet_status does.
319
+ // A probed busy is NOT written: busy belongs to the dispatching call (which
320
+ // releases it) and the stall detector; a busy written from a one-off probe
321
+ // has no owner to ever clear it. A failed probe (unknown) leaves it as is.
322
+ if (String(session.status).startsWith('idle')) {
323
+ writeStatusline(new Map([[agent.id, 'idle']]));
324
+ }
321
325
  if (input.format === 'json') {
322
326
  return JSON.stringify(result);
323
327
  }
@@ -1,7 +1,19 @@
1
1
  import { z } from 'zod';
2
+ /** What each GitHub App git_access level lets a member do, in plain words (grants: mapAccessLevel). */
3
+ export declare const GIT_ACCESS_ACTIONS: {
4
+ readonly read: "clone and fetch only";
5
+ readonly push: "clone and push, including workflow files; cannot create pull requests or dispatch workflows";
6
+ readonly 'push+pr': "clone, push, create pull requests, dispatch workflows and re-run CI jobs";
7
+ readonly admin: "clone, push, change repository settings, dispatch workflows and re-run CI jobs; cannot create pull requests";
8
+ readonly issues: "manage issues and discussions and create pull requests from existing branches; cannot clone private code, push or dispatch workflows";
9
+ readonly full: "clone, push, create pull requests, dispatch workflows, re-run CI jobs, manage issues and discussions, and change repository settings";
10
+ };
11
+ /** The GitHub permissions a level requests, read from mapAccessLevel so the text cannot drift from it. */
12
+ export declare function gitAccessGrants(level: string): string;
2
13
  export declare const provisionVcsAuthSchema: z.ZodObject<{
3
14
  provider: z.ZodEnum<["github", "bitbucket", "azure-devops"]>;
4
15
  label: z.ZodOptional<z.ZodString>;
16
+ non_interactive: z.ZodOptional<z.ZodBoolean>;
5
17
  scope_url: z.ZodOptional<z.ZodString>;
6
18
  github_mode: z.ZodOptional<z.ZodEnum<["github-app", "pat"]>>;
7
19
  token: z.ZodOptional<z.ZodString>;
@@ -27,6 +39,7 @@ export declare const provisionVcsAuthSchema: z.ZodObject<{
27
39
  workspace?: string | undefined;
28
40
  email?: string | undefined;
29
41
  label?: string | undefined;
42
+ non_interactive?: boolean | undefined;
30
43
  scope_url?: string | undefined;
31
44
  github_mode?: "github-app" | "pat" | undefined;
32
45
  org_url?: string | undefined;
@@ -43,6 +56,7 @@ export declare const provisionVcsAuthSchema: z.ZodObject<{
43
56
  workspace?: string | undefined;
44
57
  email?: string | undefined;
45
58
  label?: string | undefined;
59
+ non_interactive?: boolean | undefined;
46
60
  scope_url?: string | undefined;
47
61
  github_mode?: "github-app" | "pat" | undefined;
48
62
  org_url?: string | undefined;
@@ -73,6 +87,8 @@ export type ProvisionVcsAuthReason =
73
87
  | 'secret_variable_expired'
74
88
  /** Out-of-band credential collection was cancelled or returned nothing. */
75
89
  | 'oob_cancelled'
90
+ /** non_interactive was set and the secret field is absent; nothing was prompted. */
91
+ | 'credential_missing'
76
92
  /** The resolved provider implements no buildCredentials hook (a wiring bug). */
77
93
  | 'credential_assembly_unsupported'
78
94
  /** The provider rejected the supplied fields (e.g. a required field is absent). */
@@ -101,6 +117,13 @@ interface ProvisionVcsAuthFields {
101
117
  verified: boolean;
102
118
  /** True when testConnectivity() reported it did not perform the check. */
103
119
  verificationSkipped: boolean;
120
+ /**
121
+ * The provider's machine-readable verification cause when it reports one
122
+ * (Bitbucket: 'ok', 'rest_unauthorized', 'rest_failed', 'git_auth_failed',
123
+ * 'git_failed'), naming which channel failed; null when the provider
124
+ * reports none or no check ran.
125
+ */
126
+ verificationReason: string | null;
104
127
  /**
105
128
  * The provider's own deploy metadata, filtered through
106
129
  * filterProviderMetadata()'s PROVIDER_METADATA_KEY_ALLOWLIST before it
@@ -125,9 +148,11 @@ interface ProvisionVcsAuthFields {
125
148
  * an ok result. Previously this text only ever reached the caller inside
126
149
  * `text`, so a structured-content-only caller saw nothing but the bare
127
150
  * `reason` code (e.g. 'deploy_failed') and lost the actual cause. Derived
128
- * from the same sanitized strings already rendered into `text` -- never a
129
- * new source of information -- so it carries no plaintext secret that
130
- * wasn't already caller-visible.
151
+ * from the same text rendered into `text`, after the known credential
152
+ * values in play (raw, URL-encoded, base64 user:token, quote-escaped) and
153
+ * any Authorization header value have been replaced with **** by
154
+ * redactKnownSecrets(). Provider/OS error text is NOT otherwise sanitized,
155
+ * which is why every result goes through that redaction.
131
156
  */
132
157
  message: string | null;
133
158
  }
@@ -8,11 +8,13 @@ import { credentialResolve } from '../services/credential-store.js';
8
8
  import { collectOobApiKey } from '../services/auth-socket.js';
9
9
  import { decryptPassword } from '../utils/crypto.js';
10
10
  import { githubProvider } from '../services/vcs/github.js';
11
+ import { mapAccessLevel } from '../services/github-app.js';
11
12
  import { bitbucketProvider } from '../services/vcs/bitbucket.js';
12
13
  import { azureDevOpsProvider } from '../services/vcs/azure-devops.js';
13
14
  import { scheduleCredentialCleanup, cancelCredentialCleanup } from '../services/credential-cleanup.js';
14
15
  import { PROVIDER_HOSTS } from '../services/vcs/constants.js';
15
16
  import { logLine, logWarn } from '../utils/log-helpers.js';
17
+ import { redactKnownSecrets } from '../utils/redact-known-secrets.js';
16
18
  import { findSecretTokens, legacyTokenWarning } from '../services/secret-token.js';
17
19
  function resolveSecretField(value, callingMember) {
18
20
  const tokens = findSecretTokens(value);
@@ -32,6 +34,25 @@ function resolveSecretField(value, callingMember) {
32
34
  }
33
35
  return { resolved, legacyNames };
34
36
  }
37
+ /** What each GitHub App git_access level lets a member do, in plain words (grants: mapAccessLevel). */
38
+ export const GIT_ACCESS_ACTIONS = {
39
+ read: 'clone and fetch only',
40
+ push: 'clone and push, including workflow files; cannot create pull requests or dispatch workflows',
41
+ 'push+pr': 'clone, push, create pull requests, dispatch workflows and re-run CI jobs',
42
+ admin: 'clone, push, change repository settings, dispatch workflows and re-run CI jobs; cannot create pull requests',
43
+ issues: 'manage issues and discussions and create pull requests from existing branches; cannot clone private code, push or dispatch workflows',
44
+ full: 'clone, push, create pull requests, dispatch workflows, re-run CI jobs, manage issues and discussions, and change repository settings',
45
+ };
46
+ /** The GitHub permissions a level requests, read from mapAccessLevel so the text cannot drift from it. */
47
+ export function gitAccessGrants(level) {
48
+ const permissions = Object.entries(mapAccessLevel(level));
49
+ const named = (value) => permissions.filter(([, v]) => v === value).map(([name]) => name).join(', ');
50
+ return [`write: ${named('write')}`, `read: ${named('read')}`].filter((part) => !part.endsWith(': ')).join('; ');
51
+ }
52
+ const GIT_ACCESS_DESCRIPTION = 'GitHub App mode only (ignored for a GitHub PAT, Bitbucket and Azure DevOps, whose token grants what it was created with). ' +
53
+ "The level the minted token gets, overriding the member's configured one. Pick push+pr to create pull requests or dispatch workflows. Levels: " +
54
+ Object.entries(GIT_ACCESS_ACTIONS).map(([level, actions]) => `${level} (${gitAccessGrants(level)}): ${actions}.`).join(' ') +
55
+ ' The GitHub App itself must hold these permissions, or minting fails.';
35
56
  const providers = {
36
57
  'github': githubProvider,
37
58
  'bitbucket': bitbucketProvider,
@@ -79,16 +100,17 @@ export const provisionVcsAuthSchema = z.object({
79
100
  ...memberIdentifier,
80
101
  provider: z.enum(['github', 'bitbucket', 'azure-devops']).describe('VCS provider to configure'),
81
102
  label: z.string().regex(/^[a-zA-Z0-9_-]{1,64}$/).optional().describe('Credential label (slug, e.g. "work-github"). Defaults to provider name. Enables multiple credentials per provider.'),
103
+ non_interactive: z.boolean().optional().describe('When true, never prompt out of band: a missing secret field (api_token / pat / token) returns ok=false with reason credential_missing naming the field. Use from automation that has no operator at a terminal. Default false.'),
82
104
  scope_url: z.string().optional().describe('Git credential scope URL (e.g. "https://github.com/my-org"). Defaults to "https://<host>". For an Azure DevOps repo on the legacy host, pass "https://ORG.visualstudio.com" so the PAT is bound to the host the member actually pushes to.'),
83
105
  // GitHub fields
84
106
  github_mode: z.enum(['github-app', 'pat']).optional().describe('GitHub auth mode: github-app (mint via configured app) or pat (personal access token)'),
85
107
  token: z.string().optional().describe('Personal access token (GitHub PAT or Azure DevOps PAT). Supports {{secret.NAME}} token -- value is resolved from the credential store before use.'),
86
- git_access: z.enum(['read', 'push', 'push+pr', 'admin', 'issues', 'full']).optional().describe('GitHub App access level override'),
108
+ git_access: z.enum(['read', 'push', 'push+pr', 'admin', 'issues', 'full']).optional().describe(GIT_ACCESS_DESCRIPTION),
87
109
  repos: z.array(z.string()).optional().describe('GitHub App repository list override'),
88
110
  // Bitbucket fields
89
- email: z.string().optional().describe('Bitbucket account email'),
90
- api_token: z.string().optional().describe('Bitbucket API token. Supports {{secret.NAME}} token -- value is resolved from the credential store before use.'),
91
- workspace: z.string().optional().describe('Bitbucket workspace slug'),
111
+ email: z.string().optional().describe('OPTIONAL Bitbucket account email. Ignored for authentication (git uses the fixed token username x-bitbucket-api-token-auth, REST uses a Bearer token); kept only as metadata if given.'),
112
+ api_token: z.string().optional().describe('Bitbucket API token (required for bitbucket). Store it as the fleet secret bitbucket_api_token and pass {{secret.bitbucket_api_token}} -- the value is resolved from the credential store before use.'),
113
+ workspace: z.string().optional().describe('Bitbucket workspace slug (required for bitbucket). Verification GETs the member origin repository in this workspace over REST, then runs git ls-remote against the origin.'),
92
114
  // Azure DevOps fields
93
115
  org_url: z.string().optional().describe('Azure DevOps organization URL (e.g. https://dev.azure.com/myorg, or the legacy https://myorg.visualstudio.com)'),
94
116
  pat: z.string().optional().describe('Azure DevOps personal access token. Supports {{secret.NAME}} token -- value is resolved from the credential store before use.'),
@@ -126,7 +148,16 @@ function stripResultMarker(text) {
126
148
  }
127
149
  export async function provisionVcsAuth(input) {
128
150
  const label = input.label ?? input.provider;
129
- const vcsResult = (text, fields) => {
151
+ // Secret values in play (resolved token/api_token/pat, OOB-collected value).
152
+ // Every result built below is redacted against this list so a provider or OS
153
+ // error that echoes the credential never reaches `text`, `message` or a log.
154
+ const knownSecrets = [];
155
+ const knownUsernames = ['x-bitbucket-api-token-auth', 'x-access-token', 'git', 'oauth2'];
156
+ if (input.email)
157
+ knownUsernames.push(input.email);
158
+ const redact = (t) => redactKnownSecrets(t, knownSecrets, knownUsernames);
159
+ const vcsResult = (rawText, fields) => {
160
+ const text = redact(rawText);
130
161
  const ok = fields.ok ?? VCS_OK_REASONS.includes(fields.reason);
131
162
  return {
132
163
  text,
@@ -139,11 +170,12 @@ export async function provisionVcsAuth(input) {
139
170
  expiresAt: fields.expiresAt ?? null,
140
171
  verified: fields.verified ?? false,
141
172
  verificationSkipped: fields.verificationSkipped ?? false,
173
+ verificationReason: fields.verificationReason ?? null,
142
174
  metadata: fields.metadata ?? null,
143
175
  expiryWarning: fields.expiryWarning ?? null,
144
176
  memberId: fields.memberId ?? null,
145
177
  memberName: fields.memberName ?? null,
146
- message: fields.message ?? (ok ? null : stripResultMarker(text)),
178
+ message: fields.message != null ? redact(fields.message) : (ok ? null : stripResultMarker(text)),
147
179
  },
148
180
  };
149
181
  };
@@ -167,6 +199,8 @@ export async function provisionVcsAuth(input) {
167
199
  if ('error' in r)
168
200
  return vcsResult(`[FAIL] ${r.error}`, { ...who, reason: r.code });
169
201
  resolvedInput[field] = r.resolved;
202
+ if (r.resolved)
203
+ knownSecrets.push(r.resolved);
170
204
  legacyNames.push(...r.legacyNames);
171
205
  }
172
206
  }
@@ -180,8 +214,18 @@ export async function provisionVcsAuth(input) {
180
214
  // Order is unchanged: {{secret.NAME}} resolution first, then OOB collection
181
215
  // (an OOB-collected secret is deliberately NOT re-run through
182
216
  // resolveSecretField), then credential assembly.
217
+ //
218
+ // Every required NON-secret field is validated first, so a call that would
219
+ // fail credential assembly anyway never prompts the operator for a secret.
220
+ const nonSecretError = service.validateNonSecretFields?.(resolvedInput) ?? null;
221
+ if (nonSecretError) {
222
+ return vcsResult(`[FAIL] ${nonSecretError}`, { ...who, reason: 'credential_assembly_failed' });
223
+ }
183
224
  const missing = service.missingCredential;
184
225
  if (missing && missing.isMissing(resolvedInput)) {
226
+ if (input.non_interactive) {
227
+ return vcsResult(`[FAIL] The "${missing.field}" field is missing and non_interactive is set, so it was not prompted for. Pass it (e.g. as {{secret.NAME}}).`, { ...who, reason: 'credential_missing' });
228
+ }
185
229
  const oob = await collectOobApiKey(agent.friendlyName, 'provision_vcs_auth', {
186
230
  prompt: missing.promptFor(agent.friendlyName),
187
231
  });
@@ -189,6 +233,7 @@ export async function provisionVcsAuth(input) {
189
233
  return vcsResult(oob.fallback ?? 'Error: OOB operation cancelled.', { ...who, reason: 'oob_cancelled' });
190
234
  }
191
235
  resolvedInput[missing.field] = decryptPassword(oob.password);
236
+ knownSecrets.push(resolvedInput[missing.field]);
192
237
  }
193
238
  // buildCredentials is still optional on VcsProviderService while the seam is
194
239
  // being adopted; every provider registered above implements it, so an absent
@@ -296,7 +341,7 @@ export async function provisionVcsAuth(input) {
296
341
  // Best-effort connectivity test
297
342
  let connectivity;
298
343
  try {
299
- connectivity = await service.testConnectivity(agent, exec, scopeUrl);
344
+ connectivity = await service.testConnectivity(agent, exec, scopeUrl, creds);
300
345
  }
301
346
  catch {
302
347
  connectivity = { success: false, message: 'connectivity test threw' };
@@ -346,6 +391,7 @@ export async function provisionVcsAuth(input) {
346
391
  expiresAt: deployResult.metadata?.expiresAt ?? null,
347
392
  verified: !connectivity.skipped && connectivity.success === true,
348
393
  verificationSkipped: connectivity.skipped === true,
394
+ verificationReason: connectivity.skipped ? null : (connectivity.reason ?? null),
349
395
  metadata: filteredMetadata,
350
396
  expiryWarning: expiryWarning ?? null,
351
397
  });
@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
  import { getStrategy } from '../services/strategy.js';
4
4
  import { touchAgent } from '../utils/agent-helpers.js';
5
5
  import { memberIdentifier, resolveMember } from '../utils/resolve-member.js';
6
- import { writeStatusline } from '../services/statusline.js';
6
+ import { markBusy } from '../services/member-busy.js';
7
7
  import { ensureCloudReady } from '../services/cloud/lifecycle.js';
8
8
  import { isContainedInWorkFolder } from '../utils/platform.js';
9
9
  import { LogScope } from '../utils/log-helpers.js';
@@ -47,7 +47,7 @@ export async function receiveFiles(input, extra) {
47
47
  const strategy = getStrategy(agent);
48
48
  const pathSummary = input.remote_paths[0] ?? '';
49
49
  const scope = new LogScope('receive_files', `${input.remote_paths.length} file(s) ← ${agent.friendlyName}:${pathSummary}`, agent);
50
- writeStatusline(new Map([[agent.id, 'busy']]));
50
+ const releaseBusy = markBusy(agent.id);
51
51
  try {
52
52
  const result = await strategy.receiveFiles(input.remote_paths, input.local_dest_dir, extra?.signal);
53
53
  touchAgent(agent.id);
@@ -71,14 +71,17 @@ export async function receiveFiles(input, extra) {
71
71
  scope.abort(`all ${result.failed.length} file(s) failed`);
72
72
  else
73
73
  scope.ok(`${result.success.length} file(s)`);
74
- writeStatusline();
74
+ releaseBusy();
75
75
  return output;
76
76
  }
77
77
  catch (err) {
78
78
  const isOffline = agent.agentType !== 'local' && !!(err.message && /ssh|network|econnrefused|ehostunreach|connection timed out/i.test(err.message));
79
- writeStatusline(new Map([[agent.id, isOffline ? 'offline' : 'idle']]));
79
+ releaseBusy(isOffline ? 'offline' : 'idle');
80
80
  scope.abort(err.message);
81
81
  return `Failed to download files from "${agent.friendlyName}": ${err.message}`;
82
82
  }
83
+ finally {
84
+ releaseBusy();
85
+ }
83
86
  }
84
87
  //# sourceMappingURL=receive-files.js.map
@@ -5,7 +5,7 @@ import { z } from 'zod';
5
5
  import { getStrategy } from '../services/strategy.js';
6
6
  import { touchAgent } from '../utils/agent-helpers.js';
7
7
  import { memberIdentifier, resolveMember } from '../utils/resolve-member.js';
8
- import { writeStatusline } from '../services/statusline.js';
8
+ import { markBusy } from '../services/member-busy.js';
9
9
  import { ensureCloudReady } from '../services/cloud/lifecycle.js';
10
10
  import { isContainedInWorkFolder } from '../utils/platform.js';
11
11
  import { LogScope } from '../utils/log-helpers.js';
@@ -138,7 +138,7 @@ export async function sendFiles(input, extra) {
138
138
  const strategy = getStrategy(agent);
139
139
  const dest = resolvedPath ?? agent.workFolder;
140
140
  const scope = new LogScope('send_files', `${input.local_paths.length} file(s) -> ${dest}`, agent);
141
- writeStatusline(new Map([[agent.id, 'busy']]));
141
+ const releaseBusy = markBusy(agent.id);
142
142
  try {
143
143
  const result = await strategy.transferFiles(transferPaths, input.dest_subdir, extra?.signal);
144
144
  touchAgent(agent.id); // T7: idle manager resets its timer via touchAgent
@@ -164,16 +164,17 @@ export async function sendFiles(input, extra) {
164
164
  scope.abort(`all ${result.failed.length} file(s) failed`);
165
165
  else
166
166
  scope.ok(`${result.success.length} file(s)`);
167
- writeStatusline();
167
+ releaseBusy();
168
168
  return output;
169
169
  }
170
170
  catch (err) {
171
171
  const isOffline = agent.agentType !== 'local' && !!(err.message && /ssh|network|econnrefused|ehostunreach|connection timed out/i.test(err.message));
172
- writeStatusline(new Map([[agent.id, isOffline ? 'offline' : 'idle']]));
172
+ releaseBusy(isOffline ? 'offline' : 'idle');
173
173
  scope.abort(err.message);
174
174
  return `Failed to upload files to "${agent.friendlyName}": ${err.message}`;
175
175
  }
176
176
  finally {
177
+ releaseBusy();
177
178
  if (tempDir) {
178
179
  try {
179
180
  fs.rmSync(tempDir, { recursive: true, force: true });
@@ -3,13 +3,16 @@ export declare const sendMessageSchema: z.ZodObject<{
3
3
  member_id: z.ZodString;
4
4
  content: z.ZodString;
5
5
  reply_to: z.ZodOptional<z.ZodString>;
6
+ probe: z.ZodOptional<z.ZodBoolean>;
6
7
  }, "strip", z.ZodTypeAny, {
7
8
  member_id: string;
8
9
  content: string;
10
+ probe?: boolean | undefined;
9
11
  reply_to?: string | undefined;
10
12
  }, {
11
13
  member_id: string;
12
14
  content: string;
15
+ probe?: boolean | undefined;
13
16
  reply_to?: string | undefined;
14
17
  }>;
15
18
  export type SendMessageInput = z.infer<typeof sendMessageSchema>;
@@ -4,9 +4,10 @@ import { sessionRegistry } from '../services/session-registry.js';
4
4
  import { getTokenIssuer } from '../services/token-issuer.js';
5
5
  import { logLine } from '../utils/log-helpers.js';
6
6
  export const sendMessageSchema = z.object({
7
- member_id: z.string().describe('ID (UUID) of the target member session'),
7
+ member_id: z.string().describe('ID (UUID) of the target member session, or "orchestrator" for the operator\'s own channel-capable orchestrating session'),
8
8
  content: z.string().describe('Message content to send to the member'),
9
9
  reply_to: z.string().optional().describe('Optional message ID this is in reply to'),
10
+ probe: z.boolean().optional().describe('When true, send nothing: only report whether a session holds member_id ({ probe: true, member_id, connected, channel_capable }). channel_capable is true only for a session that declared the claude/channel capability (for "orchestrator": a Claude Code session launched with --dangerously-load-development-channels), i.e. one that can actually receive a message. content is ignored.'),
10
11
  });
11
12
  /**
12
13
  * Send a message to a connected member session.
@@ -19,8 +20,20 @@ export const sendMessageSchema = z.object({
19
20
  * scoped, so cross-workspace sends cannot happen and existence is not leaked.
20
21
  */
21
22
  export async function sendMessage(input, senderWorkspaceId) {
22
- const { member_id, content, reply_to } = input;
23
+ const { member_id, content, reply_to, probe } = input;
23
24
  const workspaceId = senderWorkspaceId ?? getTokenIssuer().workspaceId();
25
+ // Read-only probe: the same workspace-scoped lookup a send makes, with no
26
+ // notification and no status change. A session counts as able to receive
27
+ // only when it is connected (has a live server) AND declared the
28
+ // claude/channel capability -- a plain connect-back without it can never
29
+ // receive notifications/claude/channel.
30
+ if (probe) {
31
+ const target = sessionRegistry.get(workspaceId, member_id);
32
+ const connected = !!(target && target.server);
33
+ const channelCapable = connected && !!target?.channelCapable;
34
+ logLine('send_message', `probe member_id=${member_id} workspace_id=${workspaceId} connected=${connected} channel_capable=${channelCapable}`);
35
+ return JSON.stringify({ probe: true, member_id, connected, channel_capable: channelCapable });
36
+ }
24
37
  const registeredKeys = sessionRegistry.list(workspaceId).map(s => s.member_id);
25
38
  logLine('send_message', `lookup member_id=${member_id} workspace_id=${workspaceId} registry_keys=[${registeredKeys.join(',')}]`);
26
39
  const session = sessionRegistry.get(workspaceId, member_id);
@@ -33,8 +33,10 @@ export async function stopPrompt(input) {
33
33
  }
34
34
  // Unconditionally clear busy state — handles pid=none case where inFlightAgents
35
35
  // still holds the agent but the process never recorded a PID.
36
+ // An explicit 'idle' -- a bare writeStatusline() only re-renders and would
37
+ // leave a stored busy in place.
36
38
  inFlightAgents.delete(agent.id);
37
- writeStatusline();
39
+ writeStatusline(new Map([[agent.id, 'idle']]));
38
40
  logLine('stop_prompt', `pid=${pid ?? 'none'}`, agent);
39
41
  if (pid !== undefined) {
40
42
  return `🛑 Agent "${agent.friendlyName}" stopped (killed PID ${pid}).`;