@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
@@ -28,6 +28,15 @@ import { z } from 'zod';
28
28
  * 4. redacts any occurrence of the token from stdout/stderr before
29
29
  * returning, the same defence execute-command.ts's redactOutput applies.
30
30
  *
31
+ * The same helper stdout also carries a `username=` line (the basic-auth
32
+ * user provision_vcs_auth wrote -- for Bitbucket, the fixed token username
33
+ * x-bitbucket-api-token-auth, never an email),
34
+ * so `{{vcs_username}}` / `{{vcs_username_inline}}` get the identical
35
+ * two-dialect treatment for a command that needs the helper's git username
36
+ * (apra-fleet-qeq1.1; Bitbucket REST itself now takes a Bearer token). The username is
37
+ * one half of a credential pair, so it is redacted on the same footing as
38
+ * the token -- under its own marker so a reader can tell the two apart.
39
+ *
31
40
  * The plaintext token therefore appears in no field of any result an
32
41
  * orchestrator-side caller can read. readMemberVcsCredentialToken is
33
42
  * deliberately left in place; retiring it is a separate task.
@@ -56,6 +65,30 @@ export declare const VCS_TOKEN_PLACEHOLDER = "{{vcs_token}}";
56
65
  * refusals. The contract is documented, not enforced (apra-fleet-3swo.7.16).
57
66
  */
58
67
  export declare const VCS_TOKEN_INLINE_PLACEHOLDER = "{{vcs_token_inline}}";
68
+ /**
69
+ * The git USERNAME half of the same credential (the helper's username=
70
+ * line). Reference this one BARE, exactly like
71
+ * {{vcs_token}}: the substituted value arrives already shell-escaped AND
72
+ * quoted for the member's shell.
73
+ *
74
+ * The value is read from the `username=` line of the SAME credential-helper
75
+ * stdout the token comes from -- provision_vcs_auth wrote it there (see
76
+ * src/services/vcs/bitbucket.ts, which always writes the fixed token
77
+ * username x-bitbucket-api-token-auth; Bitbucket REST itself is called with
78
+ * a Bearer token, so this placeholder is not needed for it). No
79
+ * extra member round trip is involved.
80
+ */
81
+ export declare const VCS_USERNAME_PLACEHOLDER = "{{vcs_username}}";
82
+ /**
83
+ * The inside-your-own-single-quotes form of {{vcs_username}}, the exact
84
+ * counterpart of {{vcs_token_inline}} (e.g.
85
+ * `-u '{{vcs_username_inline}}:{{vcs_token_inline}}'`): escaped for the
86
+ * INTERIOR of a single-quoted string in the member's shell dialect, with no
87
+ * quotes of its own. As with the token pair, placement is documented rather
88
+ * than enforced -- whether an occurrence really sits inside the caller's
89
+ * open quotes is not decidable from the command string alone.
90
+ */
91
+ export declare const VCS_USERNAME_INLINE_PLACEHOLDER = "{{vcs_username_inline}}";
59
92
  export declare const vcsCredentialExecSchema: z.ZodObject<{
60
93
  command: z.ZodString;
61
94
  label: z.ZodOptional<z.ZodString>;
@@ -89,6 +122,13 @@ export type VcsCredentialExecReason =
89
122
  | 'credential_read_failed'
90
123
  /** The helper ran but printed no usable password= line. */
91
124
  | 'credential_empty'
125
+ /**
126
+ * `command` referenced {{vcs_username}}/{{vcs_username_inline}} but the
127
+ * helper printed no usable username= line. Only reachable for a command
128
+ * that actually asks for the username -- a token-only command never
129
+ * consults it.
130
+ */
131
+ | 'username_empty'
92
132
  /** Dispatching the credential-requiring command threw. */
93
133
  | 'dispatch_failed';
94
134
  interface VcsCredentialExecFields {
@@ -103,9 +143,11 @@ interface VcsCredentialExecFields {
103
143
  /** Command stderr with every occurrence of the credential redacted. */
104
144
  stderr: string;
105
145
  /**
106
- * How many times the credential had to be redacted out of stdout+stderr.
107
- * Normally 0; a nonzero count means the dispatched command echoed its own
108
- * credential back and the redaction earned its keep.
146
+ * How many times credential material had to be redacted out of
147
+ * stdout+stderr -- the token, plus the git username when the
148
+ * command substituted one. Normally 0; a nonzero count means the
149
+ * dispatched command echoed its own credential back and the redaction
150
+ * earned its keep.
109
151
  */
110
152
  tokenRedactions: number;
111
153
  /** Credential label used, or null for the unlabelled helper. */
@@ -34,6 +34,15 @@ import { logLine } from '../utils/log-helpers.js';
34
34
  * 4. redacts any occurrence of the token from stdout/stderr before
35
35
  * returning, the same defence execute-command.ts's redactOutput applies.
36
36
  *
37
+ * The same helper stdout also carries a `username=` line (the basic-auth
38
+ * user provision_vcs_auth wrote -- for Bitbucket, the fixed token username
39
+ * x-bitbucket-api-token-auth, never an email),
40
+ * so `{{vcs_username}}` / `{{vcs_username_inline}}` get the identical
41
+ * two-dialect treatment for a command that needs the helper's git username
42
+ * (apra-fleet-qeq1.1; Bitbucket REST itself now takes a Bearer token). The username is
43
+ * one half of a credential pair, so it is redacted on the same footing as
44
+ * the token -- under its own marker so a reader can tell the two apart.
45
+ *
37
46
  * The plaintext token therefore appears in no field of any result an
38
47
  * orchestrator-side caller can read. readMemberVcsCredentialToken is
39
48
  * deliberately left in place; retiring it is a separate task.
@@ -62,6 +71,30 @@ export const VCS_TOKEN_PLACEHOLDER = '{{vcs_token}}';
62
71
  * refusals. The contract is documented, not enforced (apra-fleet-3swo.7.16).
63
72
  */
64
73
  export const VCS_TOKEN_INLINE_PLACEHOLDER = '{{vcs_token_inline}}';
74
+ /**
75
+ * The git USERNAME half of the same credential (the helper's username=
76
+ * line). Reference this one BARE, exactly like
77
+ * {{vcs_token}}: the substituted value arrives already shell-escaped AND
78
+ * quoted for the member's shell.
79
+ *
80
+ * The value is read from the `username=` line of the SAME credential-helper
81
+ * stdout the token comes from -- provision_vcs_auth wrote it there (see
82
+ * src/services/vcs/bitbucket.ts, which always writes the fixed token
83
+ * username x-bitbucket-api-token-auth; Bitbucket REST itself is called with
84
+ * a Bearer token, so this placeholder is not needed for it). No
85
+ * extra member round trip is involved.
86
+ */
87
+ export const VCS_USERNAME_PLACEHOLDER = '{{vcs_username}}';
88
+ /**
89
+ * The inside-your-own-single-quotes form of {{vcs_username}}, the exact
90
+ * counterpart of {{vcs_token_inline}} (e.g.
91
+ * `-u '{{vcs_username_inline}}:{{vcs_token_inline}}'`): escaped for the
92
+ * INTERIOR of a single-quoted string in the member's shell dialect, with no
93
+ * quotes of its own. As with the token pair, placement is documented rather
94
+ * than enforced -- whether an occurrence really sits inside the caller's
95
+ * open quotes is not decidable from the command string alone.
96
+ */
97
+ export const VCS_USERNAME_INLINE_PLACEHOLDER = '{{vcs_username_inline}}';
65
98
  export const vcsCredentialExecSchema = z.object({
66
99
  ...memberIdentifier,
67
100
  command: z.string().min(1).describe('The credential-requiring command to run on the member. MUST contain at least one of two '
@@ -71,6 +104,12 @@ export const vcsCredentialExecSchema = z.object({
71
104
  + 'server substitutes it with the value escaped for the interior of a single-quoted string, with '
72
105
  + 'no quotes of its own (use this one when the token must be interpolated into a larger quoted '
73
106
  + 'value, e.g. an Authorization header). Both may appear in the same command. '
107
+ + 'Bitbucket REST uses the token as a Bearer value (-H \'Authorization: Bearer '
108
+ + '{{vcs_token_inline}}\'), with no username and no email. The optional username '
109
+ + 'placeholders {{vcs_username}} (bare) and {{vcs_username_inline}} (inside your own single '
110
+ + 'quotes) substitute the credential helper\'s git username under the same two dialects (for '
111
+ + 'Bitbucket always x-bitbucket-api-token-auth, a git-only username, never a REST login); they '
112
+ + 'may not appear alone -- a token placeholder is still required. '
74
113
  + 'The plaintext credential never leaves the server and never appears in this tool\'s result.'),
75
114
  label: z.string().regex(/^[a-zA-Z0-9._-]{1,64}$/).optional().describe('Credential label the helper was deployed under by provision_vcs_auth (defaults to the '
76
115
  + 'provider name there, e.g. "github" or "azure-devops"). Omit to use the unlabelled helper.'),
@@ -78,7 +117,12 @@ export const vcsCredentialExecSchema = z.object({
78
117
  + 'On expiry the command\'s remote process tree is killed and the result is reason dispatch_failed '
79
118
  + 'with a "Command timed out" message.'),
80
119
  });
81
- const REDACTION = '[REDACTED:vcs_token]';
120
+ const TOKEN_REDACTION = '[REDACTED:vcs_token]';
121
+ /**
122
+ * Distinct from TOKEN_REDACTION on purpose: a reader of a redacted stream
123
+ * needs to know WHICH half of the basic-auth pair was scrubbed out of it.
124
+ */
125
+ const USERNAME_REDACTION = '[REDACTED:vcs_username]';
82
126
  function execResult(text, fields) {
83
127
  return {
84
128
  text,
@@ -96,11 +140,11 @@ function execResult(text, fields) {
96
140
  };
97
141
  }
98
142
  /** Replace every occurrence of `secret` in `output`, and report how many. */
99
- function redactToken(output, secret) {
143
+ function redactSecret(output, secret, marker) {
100
144
  if (!secret)
101
145
  return { text: output, count: 0 };
102
146
  const parts = output.split(secret);
103
- return { text: parts.join(REDACTION), count: parts.length - 1 };
147
+ return { text: parts.join(marker), count: parts.length - 1 };
104
148
  }
105
149
  export async function vcsCredentialExec(input) {
106
150
  const agentOrError = resolveMember(input.member_id, input.member_name);
@@ -117,6 +161,9 @@ export async function vcsCredentialExec(input) {
117
161
  // credential handoff rather than a second, unguarded execute_command.
118
162
  const hasBare = input.command.includes(VCS_TOKEN_PLACEHOLDER);
119
163
  const hasInline = input.command.includes(VCS_TOKEN_INLINE_PLACEHOLDER);
164
+ // A token placeholder stays mandatory even for a basic-auth command: the
165
+ // username alone is not a credential, so a username-only command is still
166
+ // an unguarded execute_command and is still refused here.
120
167
  if (!hasBare && !hasInline) {
121
168
  return execResult(`[FAIL] command must contain ${VCS_TOKEN_PLACEHOLDER} or ${VCS_TOKEN_INLINE_PLACEHOLDER} -- use execute_command for a command that needs no credential.`, { ...who, reason: 'placeholder_missing' });
122
169
  }
@@ -134,9 +181,16 @@ export async function vcsCredentialExec(input) {
134
181
  catch (err) {
135
182
  return execResult(`[FAIL] Cannot read a VCS credential on "${agent.friendlyName}" (os=${agentOs} shell=${agentShell ?? 'default'}): ${err.message}`, { ...who, reason: 'unsupported_member_os' });
136
183
  }
184
+ // Only a command that actually references a username placeholder consults
185
+ // the username= line, so every existing token-only call site (GitHub,
186
+ // Azure DevOps) keeps its exact previous behaviour and cannot reach the
187
+ // username_empty failure.
188
+ const needsUsername = input.command.includes(VCS_USERNAME_PLACEHOLDER)
189
+ || input.command.includes(VCS_USERNAME_INLINE_PLACEHOLDER);
137
190
  // STEP 1 -- read the credential SERVER-SIDE. This result is consumed
138
191
  // in-process and is never placed in the payload returned below.
139
192
  let token = '';
193
+ let username = '';
140
194
  try {
141
195
  const readRes = await strategy.execCommand(read.command, 15000);
142
196
  if (readRes.code !== 0) {
@@ -144,6 +198,8 @@ export async function vcsCredentialExec(input) {
144
198
  }
145
199
  const m = /^password=(.*)$/m.exec(readRes.stdout || '');
146
200
  token = m ? m[1].trim() : '';
201
+ const u = /^username=(.*)$/m.exec(readRes.stdout || '');
202
+ username = u ? u[1].trim() : '';
147
203
  }
148
204
  catch (err) {
149
205
  return execResult(`[FAIL] Failed to read the VCS credential for "${agent.friendlyName}" from '${read.path}': ${err.message}`, { ...who, reason: 'credential_read_failed' });
@@ -151,19 +207,42 @@ export async function vcsCredentialExec(input) {
151
207
  if (!token) {
152
208
  return execResult(`[FAIL] The VCS credential for "${agent.friendlyName}" was empty or unreadable (expected a 'password=' line from '${read.path}'). Re-run provision_vcs_auth.`, { ...who, reason: 'credential_empty' });
153
209
  }
210
+ // Substituting an empty username would silently dispatch ':<token>' and
211
+ // surface much later as a confusing 401, so this is a typed refusal that
212
+ // never dispatches anything.
213
+ if (needsUsername && !username) {
214
+ return execResult(`[FAIL] The VCS credential for "${agent.friendlyName}" carries no git username (expected a 'username=' line from '${read.path}'), but the command references ${VCS_USERNAME_PLACEHOLDER}. Re-run provision_vcs_auth for a provider that records one.`, { ...who, reason: 'username_empty' });
215
+ }
154
216
  // STEP 2 -- substitute, escaped for the member's OWN shell. A Windows
155
217
  // member registered with shell=gitbash runs bash, so it needs POSIX
156
218
  // escaping even though its OS is windows; isPosixShell owns that decision
157
219
  // for every consumer. The bare placeholder gets the fully-quoted form; the
158
220
  // inline placeholder gets the SAME dialect's interior-only escaping, with
159
221
  // no wrapping quotes of its own, so it composes inside the caller's
160
- // already-open single quotes instead of double-escaping.
222
+ // already-open single quotes instead of double-escaping. The username pair
223
+ // reuses the SAME two escapers under the SAME isPosixShell branch rather
224
+ // than adding a second dialect decision.
161
225
  const posix = isPosixShell(agentOs, agentShell);
162
- const escaped = posix ? escapeShellArg(token) : escapePowerShellArg(token);
163
- const escapedInline = posix ? escapeShellArgInner(token) : escapePowerShellArgInner(token);
226
+ const quote = (v) => (posix ? escapeShellArg(v) : escapePowerShellArg(v));
227
+ const inner = (v) => (posix ? escapeShellArgInner(v) : escapePowerShellArgInner(v));
164
228
  const finalCommand = input.command
165
- .replaceAll(VCS_TOKEN_PLACEHOLDER, escaped)
166
- .replaceAll(VCS_TOKEN_INLINE_PLACEHOLDER, escapedInline);
229
+ .replaceAll(VCS_TOKEN_PLACEHOLDER, quote(token))
230
+ .replaceAll(VCS_TOKEN_INLINE_PLACEHOLDER, inner(token))
231
+ .replaceAll(VCS_USERNAME_PLACEHOLDER, quote(username))
232
+ .replaceAll(VCS_USERNAME_INLINE_PLACEHOLDER, inner(username));
233
+ /**
234
+ * Scrub both halves of the credential. The username is only scrubbed when
235
+ * this command actually substituted one -- a token-only command must not
236
+ * start redacting an unrelated string (a GitHub helper's username is the
237
+ * very common literal 'x-access-token') out of its own output.
238
+ */
239
+ const redactCredentials = (output) => {
240
+ const t = redactSecret(output, token, TOKEN_REDACTION);
241
+ if (!needsUsername)
242
+ return t;
243
+ const u = redactSecret(t.text, username, USERNAME_REDACTION);
244
+ return { text: u.text, count: t.count + u.count };
245
+ };
167
246
  // STEP 3 -- dispatch. Only the log-safe form (placeholder still in place) is
168
247
  // ever logged; `finalCommand` is never written anywhere.
169
248
  logLine('vcs_credential_exec', `label=${input.label ?? '(default)'} command=${input.command.slice(0, 120)}`, agent);
@@ -183,14 +262,14 @@ export async function vcsCredentialExec(input) {
183
262
  catch (err) {
184
263
  // The thrown message can quote the command that failed, so it is redacted
185
264
  // on the same footing as stdout/stderr.
186
- const redactedErr = redactToken(String(err?.message ?? err), token);
265
+ const redactedErr = redactCredentials(String(err?.message ?? err));
187
266
  return execResult(`[FAIL] Command dispatch failed on "${agent.friendlyName}": ${redactedErr.text}`, { ...who, reason: 'dispatch_failed', stderr: redactedErr.text, tokenRedactions: redactedErr.count });
188
267
  }
189
268
  // STEP 4 -- defence in depth: the command itself may echo the credential
190
269
  // back (a curl -v, a git error quoting the remote URL), so scrub both
191
270
  // streams before anything is returned.
192
- const outRedacted = redactToken(stdout, token);
193
- const errRedacted = redactToken(stderr, token);
271
+ const outRedacted = redactCredentials(stdout);
272
+ const errRedacted = redactCredentials(stderr);
194
273
  return execResult(`[OK] Ran credential-requiring command on "${agent.friendlyName}" (exit ${code}).`, {
195
274
  ...who,
196
275
  reason: 'ok',
@@ -1,5 +1,6 @@
1
1
  import http from 'node:http';
2
2
  import { execFileSync } from 'node:child_process';
3
+ import { windowsExecutable } from '../os/windows-executable.js';
3
4
  export function isPidAlive(pid) {
4
5
  try {
5
6
  process.kill(pid, 0);
@@ -19,9 +20,12 @@ export function processCommandLine(pid) {
19
20
  if (!Number.isInteger(pid) || pid <= 0)
20
21
  return null;
21
22
  const opts = { encoding: 'utf8', stdio: 'pipe', windowsHide: true, timeout: 10_000 };
23
+ // powershell.exe is resolved to an absolute path (never the cwd). A missing
24
+ // PowerShell lands in the catch like any other unreadable command line:
25
+ // callers (isApraFleetProcess) then fall back to the tasklist image name.
22
26
  try {
23
27
  const out = process.platform === 'win32'
24
- ? execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command',
28
+ ? execFileSync(windowsExecutable('powershell.exe'), ['-NoProfile', '-NonInteractive', '-Command',
25
29
  `(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CommandLine`], opts)
26
30
  : execFileSync('ps', ['-p', String(pid), '-o', 'command='], opts);
27
31
  const trimmed = String(out).trim();
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Redact known credential values from free text before it is returned to a
3
+ * caller or logged.
4
+ *
5
+ * Replaces every occurrence of each secret value in its raw form, URL-encoded
6
+ * form, base64 of `user:secret` (for every username supplied), and every
7
+ * shell-escaped form the OS command builders (src/os/*) write it in, with
8
+ * ****. Those escaped forms are built with the SAME escapers the builders use
9
+ * (src/utils/shell-escape.ts), never re-implemented here, so a form actually
10
+ * sent to a member is always a form this module masks. Also redacts any `Authorization` header value (Bearer/Basic) and
11
+ * GitHub-shaped token literals (ghp_/ghs_/... and github_pat_...), which covers
12
+ * a token minted inside a provider's deploy that this module never sees.
13
+ *
14
+ * Out of scope: fragment-aware redaction of wrapped/truncated console output.
15
+ */
16
+ export declare function redactKnownSecrets(text: string, secrets: Array<string | undefined | null>, usernames?: string[]): string;
17
+ //# sourceMappingURL=redact-known-secrets.d.ts.map
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Redact known credential values from free text before it is returned to a
3
+ * caller or logged.
4
+ *
5
+ * Replaces every occurrence of each secret value in its raw form, URL-encoded
6
+ * form, base64 of `user:secret` (for every username supplied), and every
7
+ * shell-escaped form the OS command builders (src/os/*) write it in, with
8
+ * ****. Those escaped forms are built with the SAME escapers the builders use
9
+ * (src/utils/shell-escape.ts), never re-implemented here, so a form actually
10
+ * sent to a member is always a form this module masks. Also redacts any `Authorization` header value (Bearer/Basic) and
11
+ * GitHub-shaped token literals (ghp_/ghs_/... and github_pat_...), which covers
12
+ * a token minted inside a provider's deploy that this module never sees.
13
+ *
14
+ * Out of scope: fragment-aware redaction of wrapped/truncated console output.
15
+ */
16
+ import { escapeBatchMetachars, escapeDoubleQuoted, escapeForDoubleQuotes, escapePowerShellArgInner, escapeShellArgInner, escapeWindowsArg, } from './shell-escape.js';
17
+ const MASK = '****';
18
+ /** Secrets shorter than this are not redacted by value (would mangle text). */
19
+ const MIN_SECRET_LENGTH = 4;
20
+ function escapeRegExp(s) {
21
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
22
+ }
23
+ function forms(secret, usernames) {
24
+ const out = new Set();
25
+ const add = (v) => { if (v && v.length >= MIN_SECRET_LENGTH)
26
+ out.add(v); };
27
+ add(secret);
28
+ add(encodeURIComponent(secret));
29
+ // POSIX single quotes (escapeShellArg: httpGetStatusWithBearer, git-bash helper).
30
+ add(escapeShellArgInner(secret));
31
+ // POSIX double quotes (linux/macos gitCredentialHelperWrite, ghAuthLogin).
32
+ add(escapeDoubleQuoted(secret));
33
+ add(escapeForDoubleQuotes(secret, false));
34
+ // PowerShell single quotes (windows httpGetStatusWithBearer) and double quotes.
35
+ add(escapePowerShellArgInner(secret));
36
+ add(escapeForDoubleQuotes(secret, true));
37
+ // .bat helper content (windows / git-bash gitCredentialHelperWrite) and its
38
+ // PowerShell / POSIX single-quoted carriers.
39
+ add(escapeBatchMetachars(secret));
40
+ add(escapePowerShellArgInner(escapeBatchMetachars(secret)));
41
+ add(escapeShellArgInner(escapeBatchMetachars(secret)));
42
+ // cmd.exe double quotes (windows ghAuthLogin) inside PowerShell single quotes.
43
+ add(escapeWindowsArg(secret));
44
+ add(escapePowerShellArgInner(escapeWindowsArg(secret)));
45
+ for (const u of usernames) {
46
+ add(Buffer.from(`${u}:${secret}`).toString('base64'));
47
+ add(Buffer.from(`:${secret}`).toString('base64'));
48
+ }
49
+ add(Buffer.from(`:${secret}`).toString('base64'));
50
+ add(Buffer.from(secret).toString('base64'));
51
+ return [...out];
52
+ }
53
+ export function redactKnownSecrets(text, secrets, usernames = []) {
54
+ let out = text;
55
+ const all = new Set();
56
+ for (const s of secrets) {
57
+ if (typeof s === 'string' && s.length >= MIN_SECRET_LENGTH)
58
+ for (const f of forms(s, usernames))
59
+ all.add(f);
60
+ }
61
+ // Longest first so a raw value never leaves a partial of a longer form.
62
+ for (const f of [...all].sort((a, b) => b.length - a.length)) {
63
+ out = out.replace(new RegExp(escapeRegExp(f), 'g'), MASK);
64
+ }
65
+ out = out.replace(/(\bAuthorization\s*[:=]\s*['"]?\s*)(Bearer|Basic|token)(\s+)[^\s'"]+/gi, `$1$2$3${MASK}`);
66
+ out = out.replace(/\b(Bearer|Basic)(\s+)[A-Za-z0-9._~+/=-]{8,}/g, `$1$2${MASK}`);
67
+ out = out.replace(/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})/g, MASK);
68
+ return out;
69
+ }
70
+ //# sourceMappingURL=redact-known-secrets.js.map
@@ -21,7 +21,7 @@ export function getRequiredSkills(tags, vcs, project) {
21
21
  // Bitbucket tag rules
22
22
  if (vcsNorm === 'bitbucket') {
23
23
  if (tagNorm === 'devops' || tagNorm === 'code-review') {
24
- skills.add('bitbucket-devops');
24
+ skills.add('bitbucket');
25
25
  }
26
26
  }
27
27
  // Azure DevOps tag rules (future skills -- added as placeholders)
@@ -47,8 +47,8 @@
47
47
  */
48
48
  /** github.com and its ssh alias. Anchored -- see the header note on GHE. */
49
49
  const GITHUB_HOST_RE = /^(?:www\.|ssh\.)?github\.com$/i;
50
- /** bitbucket.org and its alternate-SSH host. */
51
- const BITBUCKET_HOST_RE = /^(?:www\.|altssh\.)?bitbucket\.org$/i;
50
+ /** bitbucket.org and its SSH hosts (altssh, ssh). */
51
+ const BITBUCKET_HOST_RE = /^(?:www\.|altssh\.|ssh\.)?bitbucket\.org$/i;
52
52
  /** dev.azure.com, its v3 ssh host, and the legacy <org>.visualstudio.com.
53
53
  * Kept identical to azure-devops.mjs's HOST_RE. */
54
54
  const AZURE_DEVOPS_HOST_RE = /^(?:dev\.azure\.com|ssh\.dev\.azure\.com|(?:[a-z0-9-]+\.)*visualstudio\.com)$/i;