@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.
- package/README.md +49 -4
- package/dist/agents/backlog-groomer.md +5 -0
- package/dist/agents/ci-watcher.md +5 -0
- package/dist/agents/deployer.md +20 -2
- package/dist/agents/doer.md +38 -2
- package/dist/agents/harvester.md +12 -9
- package/dist/agents/integ-test-runner.md +5 -0
- package/dist/agents/kb-reconciler.md +6 -0
- package/dist/agents/plan-reviewer.md +5 -0
- package/dist/agents/planner.md +5 -0
- package/dist/agents/regression-test-runner.md +5 -0
- package/dist/agents/reviewer.md +67 -15
- package/dist/agents/schemas/deployer-output.json +5 -0
- package/dist/agents/schemas/doer-output.json +78 -2
- package/dist/agents/schemas/reviewer-output.json +104 -2
- package/dist/cli/auth.js +5 -1
- package/dist/cli/beads-pin.js +6 -7
- package/dist/cli/claude-mod.d.ts +75 -0
- package/dist/cli/claude-mod.js +288 -0
- package/dist/cli/dolt-install.d.ts +1 -1
- package/dist/cli/dolt-install.js +5 -1
- package/dist/cli/fleet-se-guard.d.ts +8 -0
- package/dist/cli/fleet-se-guard.js +19 -3
- package/dist/cli/install-guard.d.ts +9 -0
- package/dist/cli/install-guard.js +24 -0
- package/dist/cli/install.d.ts +12 -0
- package/dist/cli/install.js +180 -20
- package/dist/cli/kb-profile.d.ts +16 -0
- package/dist/cli/kb-profile.js +81 -0
- package/dist/cli/start.js +3 -0
- package/dist/cli/uninstall.js +13 -3
- package/dist/cli/update.d.ts +4 -0
- package/dist/cli/update.js +19 -3
- package/dist/commands/kb-server.d.ts +10 -1
- package/dist/commands/kb-server.js +285 -11
- package/dist/index.js +22 -1
- package/dist/os/git-executable.d.ts +57 -0
- package/dist/os/git-executable.js +85 -0
- package/dist/os/go-concurrency.d.ts +44 -0
- package/dist/os/go-concurrency.js +53 -0
- package/dist/os/index.d.ts +1 -0
- package/dist/os/index.js +1 -0
- package/dist/os/linux.d.ts +2 -0
- package/dist/os/linux.js +10 -1
- package/dist/os/os-commands.d.ts +25 -0
- package/dist/os/os-commands.js +2 -0
- package/dist/os/windows-executable.d.ts +53 -0
- package/dist/os/windows-executable.js +185 -0
- package/dist/os/windows-gitbash.d.ts +23 -14
- package/dist/os/windows-gitbash.js +40 -16
- package/dist/os/windows.d.ts +2 -0
- package/dist/os/windows.js +37 -6
- package/dist/paths.d.ts +10 -1
- package/dist/paths.js +19 -2
- package/dist/services/agy-project.d.ts +7 -1
- package/dist/services/agy-project.js +7 -2
- package/dist/services/auth-socket.d.ts +18 -0
- package/dist/services/auth-socket.js +30 -4
- package/dist/services/credential-store.d.ts +33 -0
- package/dist/services/credential-store.js +79 -2
- package/dist/services/http-transport.d.ts +29 -0
- package/dist/services/http-transport.js +166 -37
- package/dist/services/kb-tool-profile.d.ts +36 -0
- package/dist/services/kb-tool-profile.js +88 -0
- package/dist/services/knowledge/bible-blob-id.js +10 -1
- package/dist/services/knowledge/bible-import.d.ts +108 -0
- package/dist/services/knowledge/bible-import.js +137 -4
- package/dist/services/knowledge/file-hash.js +6 -5
- package/dist/services/knowledge/http-provider.d.ts +303 -20
- package/dist/services/knowledge/http-provider.js +795 -125
- package/dist/services/knowledge/kb-config.d.ts +65 -1
- package/dist/services/knowledge/kb-config.js +143 -3
- package/dist/services/knowledge/kb-http-auth-state.d.ts +26 -0
- package/dist/services/knowledge/kb-http-auth-state.js +40 -0
- package/dist/services/knowledge/kb-providers.d.ts +9 -2
- package/dist/services/knowledge/kb-providers.js +67 -37
- package/dist/services/knowledge/kb-removed-scope-keys.js +1 -1
- package/dist/services/knowledge/kb-self.d.ts +122 -9
- package/dist/services/knowledge/kb-self.js +196 -36
- package/dist/services/knowledge/member-bible-view.js +16 -3
- package/dist/services/knowledge/path-validation.d.ts +7 -0
- package/dist/services/knowledge/path-validation.js +11 -0
- package/dist/services/knowledge/project-slug.js +3 -2
- package/dist/services/knowledge/repository-header.d.ts +77 -0
- package/dist/services/knowledge/repository-header.js +233 -0
- package/dist/services/knowledge/require-sqlite-project.d.ts +1 -1
- package/dist/services/knowledge/require-sqlite-project.js +1 -1
- package/dist/services/knowledge/sqlite-provider.d.ts +169 -0
- package/dist/services/knowledge/sqlite-provider.js +416 -4
- package/dist/services/knowledge/types.d.ts +15 -2
- package/dist/services/member-busy.d.ts +12 -0
- package/dist/services/member-busy.js +20 -0
- package/dist/services/member-config-io.d.ts +3 -2
- package/dist/services/member-config-io.js +7 -4
- package/dist/services/member-fleet-install.js +1 -0
- package/dist/services/member-tool-allowlist.d.ts +1 -1
- package/dist/services/member-tool-allowlist.js +8 -4
- package/dist/services/port-holder.js +2 -1
- package/dist/services/service-manager/types.d.ts +17 -1
- package/dist/services/service-manager/windows.d.ts +7 -2
- package/dist/services/service-manager/windows.js +28 -11
- package/dist/services/service-notice.d.ts +7 -0
- package/dist/services/service-notice.js +19 -0
- package/dist/services/session-registry.d.ts +13 -0
- package/dist/services/session-registry.js +13 -0
- package/dist/services/session-roots.d.ts +67 -0
- package/dist/services/session-roots.js +126 -0
- package/dist/services/statusline.d.ts +21 -0
- package/dist/services/statusline.js +97 -1
- package/dist/services/supervisor-service-cleanup.js +2 -1
- package/dist/services/tool-registry.js +108 -20
- package/dist/services/tool-scope.d.ts +34 -1
- package/dist/services/tool-scope.js +27 -2
- package/dist/services/vcs/azure-devops.js +10 -0
- package/dist/services/vcs/bitbucket.d.ts +22 -1
- package/dist/services/vcs/bitbucket.js +163 -17
- package/dist/services/vcs/types.d.ts +25 -2
- package/dist/services/watch/project-resolver.js +2 -1
- package/dist/skills/pm/cost.md +5 -1
- package/dist/skills/pm/index.md +9 -9
- package/dist/skills/pm/sprint.md +2 -1
- package/dist/tools/check-status.d.ts +51 -0
- package/dist/tools/check-status.js +124 -12
- package/dist/tools/code-intelligence-freshness.js +1 -1
- package/dist/tools/code-intelligence-gitnexus.d.ts +19 -0
- package/dist/tools/code-intelligence-gitnexus.js +166 -9
- package/dist/tools/code-intelligence-readiness.d.ts +58 -1
- package/dist/tools/code-intelligence-readiness.js +93 -8
- package/dist/tools/code-intelligence-reindex.d.ts +25 -1
- package/dist/tools/code-intelligence-reindex.js +76 -4
- package/dist/tools/code-intelligence.d.ts +1 -1
- package/dist/tools/code-intelligence.js +1 -1
- package/dist/tools/execute-command.js +14 -8
- package/dist/tools/execute-prompt.js +6 -2
- package/dist/tools/fleet-snapshot.d.ts +21 -0
- package/dist/tools/fleet-snapshot.js +78 -0
- package/dist/tools/kb-bible-commit.d.ts +25 -11
- package/dist/tools/kb-bible-commit.js +142 -33
- package/dist/tools/kb-capture.d.ts +2 -2
- package/dist/tools/kb-context.js +47 -27
- package/dist/tools/kb-demote.d.ts +27 -0
- package/dist/tools/kb-demote.js +37 -0
- package/dist/tools/kb-export.d.ts +35 -3
- package/dist/tools/kb-export.js +56 -13
- package/dist/tools/kb-feedback.d.ts +2 -0
- package/dist/tools/kb-feedback.js +17 -7
- package/dist/tools/kb-harvest.js +28 -9
- package/dist/tools/kb-import.d.ts +18 -2
- package/dist/tools/kb-import.js +24 -9
- package/dist/tools/kb-invalidate.d.ts +11 -3
- package/dist/tools/kb-invalidate.js +80 -7
- package/dist/tools/kb-list.js +38 -10
- package/dist/tools/kb-promote.js +6 -4
- package/dist/tools/kb-query.d.ts +3 -0
- package/dist/tools/kb-query.js +181 -37
- package/dist/tools/kb-session-prime.d.ts +4 -4
- package/dist/tools/kb-session-prime.js +89 -9
- package/dist/tools/kb-setup.d.ts +20 -0
- package/dist/tools/kb-setup.js +149 -11
- package/dist/tools/list-members.js +1 -1
- package/dist/tools/member-detail.js +7 -3
- package/dist/tools/provision-vcs-auth.d.ts +28 -3
- package/dist/tools/provision-vcs-auth.js +53 -7
- package/dist/tools/receive-files.js +7 -4
- package/dist/tools/send-files.js +5 -4
- package/dist/tools/send-message.d.ts +3 -0
- package/dist/tools/send-message.js +15 -2
- package/dist/tools/stop-prompt.js +3 -1
- package/dist/tools/vcs-credential-exec.d.ts +45 -3
- package/dist/tools/vcs-credential-exec.js +90 -11
- package/dist/utils/process-utils.js +5 -1
- package/dist/utils/redact-known-secrets.d.ts +17 -0
- package/dist/utils/redact-known-secrets.js +70 -0
- package/dist/utils/skill-matrix.js +1 -1
- package/dist/utils/vcs-provider-detect.js +2 -2
- package/dist/workflows/auto-sprint.js +245 -9
- package/package.json +10 -7
- package/packages/apra-fleet-client/package.json +1 -1
- package/packages/apra-fleet-client/src/client/api.mjs +172 -19
- package/packages/apra-fleet-client/src/client/reconnecting-transport.mjs +35 -2
- package/packages/apra-fleet-client/src/client/transport.mjs +6 -0
- package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/deployer.md +20 -2
- package/packages/apra-fleet-se/apra-pm/agents/doer.md +38 -2
- package/packages/apra-fleet-se/apra-pm/agents/harvester.md +12 -9
- package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +6 -0
- package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/planner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +67 -15
- package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-output.json +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +78 -2
- package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +104 -2
- package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +5 -1
- package/packages/apra-fleet-se/apra-pm/skills/pm/index.md +9 -9
- package/packages/apra-fleet-se/apra-pm/skills/pm/sprint.md +2 -1
- package/packages/apra-fleet-se/bin/cli.mjs +104 -31
- package/packages/apra-fleet-se/bin/serve.mjs +46 -8
- package/packages/apra-fleet-se/fleet-sprint/abort.mjs +184 -32
- package/packages/apra-fleet-se/fleet-sprint/bd-sync-command.mjs +69 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +21 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-lock-probe.mjs +176 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-reachability.mjs +126 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +158 -1
- package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +82 -2
- package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +23 -6
- package/packages/apra-fleet-se/fleet-sprint/decision-notify.mjs +338 -0
- package/packages/apra-fleet-se/fleet-sprint/decision-wait.mjs +731 -0
- package/packages/apra-fleet-se/fleet-sprint/decisions.mjs +372 -0
- package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +44 -11
- package/packages/apra-fleet-se/fleet-sprint/docs/README.md +4 -1
- package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +9 -3
- package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +314 -19
- package/packages/apra-fleet-se/fleet-sprint/errors.mjs +72 -4
- package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +7 -1
- package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +112 -1
- package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +36 -2
- package/packages/apra-fleet-se/fleet-sprint/kb.mjs +736 -101
- package/packages/apra-fleet-se/fleet-sprint/member-init-probe.mjs +1 -1
- package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +7 -1
- package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +49 -2
- package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +206 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +61 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +81 -31
- package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +7 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +39 -14
- package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +17 -1
- package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +18 -3
- package/packages/apra-fleet-se/fleet-sprint/pr-body.mjs +14 -1
- package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +32 -5
- package/packages/apra-fleet-se/fleet-sprint/runner.js +824 -98
- package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +4 -2
- package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +54 -1
- package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +29 -2
- package/packages/apra-fleet-se/fleet-sprint/set-aside.mjs +288 -0
- package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +3 -2
- package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +20 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +21 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +9 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +605 -32
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +811 -17
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +89 -1
- package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +225 -2
- package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +59 -3
- package/packages/apra-fleet-se/src/supervisor/api.mjs +148 -8
- package/packages/apra-fleet-se/src/supervisor/dashboard.mjs +6 -3
- package/packages/apra-fleet-se/src/supervisor/dolt-mutex.mjs +30 -10
- package/packages/apra-fleet-se/src/supervisor/fleet-members.mjs +17 -4
- package/packages/apra-fleet-se/src/supervisor/history.mjs +8 -1
- package/packages/apra-fleet-se/src/supervisor/id-allocator.mjs +92 -2
- package/packages/apra-fleet-se/src/supervisor/proxy.mjs +26 -1
- package/packages/apra-fleet-se/src/supervisor/server.mjs +151 -8
- package/packages/apra-fleet-se/src/supervisor/spawner.mjs +11 -9
- package/packages/apra-fleet-se/src/supervisor/watchdog.mjs +7 -1
- package/packages/apra-fleet-workflow/package.json +2 -1
- package/packages/apra-fleet-workflow/src/viewer/index.mjs +86 -5
- package/packages/apra-fleet-workflow/src/viewer/request-guard.mjs +222 -0
- package/packages/apra-fleet-workflow/src/workflow/index.mjs +34 -2
- package/plugins/claude-code/fleet-status/.claude-plugin/plugin.json +7 -0
- package/plugins/claude-code/fleet-status/hooks/hooks.json +1 -0
- package/plugins/claude-code/fleet-status/hooks/register.tsx +906 -0
- package/plugins/claude-code/fleet-status/types/index.d.ts +88 -0
- package/skills/fleet/auth-bitbucket.md +47 -20
- package/skills/fleet/onboarding.md +1 -1
- package/skills/fleet/skill-matrix.md +3 -3
- package/version.json +1 -1
|
@@ -71,35 +71,120 @@ export async function persistNewTaskBestEffort({ createFn, command, member, pare
|
|
|
71
71
|
const SAFE_DESCRIPTION_RE = /^[\t\n\r\x20-\x7E]+$/;
|
|
72
72
|
const SAFE_PRIORITY_RE = /^P[0-4]$/;
|
|
73
73
|
|
|
74
|
+
// Unicode arrow code points the newTask sanitisers recognise (kept as \u
|
|
75
|
+
// escapes so this source stays ASCII-only):
|
|
76
|
+
// right: U+2192, U+27F6, U+21A6, U+2794, U+279C, U+27A1, U+2B62, U+21E8
|
|
77
|
+
// double right: U+21D2, U+27F9
|
|
78
|
+
// left: U+2190, U+27F5 double left: U+21D0, U+27F8
|
|
79
|
+
// both: U+2194, U+27F7 double both: U+21D4, U+27FA
|
|
80
|
+
const UNICODE_RIGHT_ARROW_RE = /[\u2192\u27F6\u21A6\u2794\u279C\u27A1\u2B62\u21E8]/g;
|
|
81
|
+
const UNICODE_DOUBLE_RIGHT_ARROW_RE = /[\u21D2\u27F9]/g;
|
|
82
|
+
const UNICODE_LEFT_ARROW_RE = /[\u2190\u27F5]/g;
|
|
83
|
+
const UNICODE_DOUBLE_LEFT_ARROW_RE = /[\u21D0\u27F8]/g;
|
|
84
|
+
const UNICODE_BOTH_ARROW_RE = /[\u2194\u27F7]/g;
|
|
85
|
+
const UNICODE_DOUBLE_BOTH_ARROW_RE = /[\u21D4\u27FA]/g;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Fixed substitution table for newTask DESCRIPTIONS. Description only has to
|
|
89
|
+
* pass SAFE_DESCRIPTION_RE (printable ASCII), so every entry maps to its
|
|
90
|
+
* plain-ASCII spelling: Unicode arrows become `->` / `=>` / `<-` / `<=` /
|
|
91
|
+
* `<->` / `<=>`, Unicode comparison signs become `>=` / `<=` / `!=`.
|
|
92
|
+
*/
|
|
93
|
+
const DESCRIPTION_SUBSTITUTIONS = [
|
|
94
|
+
[/[\u2014\u2013]/g, '--'], // em dash (\u2014), en dash (\u2013)
|
|
95
|
+
[/[\u2018\u2019]/g, "'"], // curly single quotes (\u2018 \u2019)
|
|
96
|
+
[/[\u201C\u201D]/g, '"'], // curly double quotes (\u201C \u201D)
|
|
97
|
+
[/\u2026/g, '...'], // horizontal ellipsis (\u2026)
|
|
98
|
+
[UNICODE_DOUBLE_BOTH_ARROW_RE, '<=>'],
|
|
99
|
+
[UNICODE_BOTH_ARROW_RE, '<->'],
|
|
100
|
+
[UNICODE_DOUBLE_RIGHT_ARROW_RE, '=>'],
|
|
101
|
+
[UNICODE_RIGHT_ARROW_RE, '->'],
|
|
102
|
+
[UNICODE_DOUBLE_LEFT_ARROW_RE, '<='],
|
|
103
|
+
[UNICODE_LEFT_ARROW_RE, '<-'],
|
|
104
|
+
[/\u2265/g, '>='], // greater-than or equal (\u2265)
|
|
105
|
+
[/\u2264/g, '<='], // less-than or equal (\u2264)
|
|
106
|
+
[/\u2260/g, '!='], // not equal (\u2260)
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Fixed substitution table for newTask TITLES. Title must pass SAFE_TEXT_RE,
|
|
111
|
+
* which admits none of `>`, `<`, `=`, `&`, so arrows and comparison operators
|
|
112
|
+
* are spelled out as words. ORDER MATTERS: multi-character tokens come before
|
|
113
|
+
* the single characters they contain (`<=>` before `<=` before `<`, `->`
|
|
114
|
+
* before a lone `>`, `>=` before `=`), and the Unicode dash rewrite runs
|
|
115
|
+
* first so an em-dash arrow (U+2014 followed by `>`) is caught by the `->`
|
|
116
|
+
* entry. Every replacement is space-padded; sanitizeNewTaskTitle() collapses
|
|
117
|
+
* runs of spaces and trims afterwards.
|
|
118
|
+
*/
|
|
119
|
+
const TITLE_SUBSTITUTIONS = [
|
|
120
|
+
[/[\u2014\u2013]/g, '--'], // em dash (\u2014), en dash (\u2013)
|
|
121
|
+
[/[\u2018\u2019]/g, "'"], // curly single quotes (\u2018 \u2019)
|
|
122
|
+
[/[\u201C\u201D]/g, "'"], // curly double quotes -> single quote (a literal `"` stays disallowed in title, unlike description)
|
|
123
|
+
[/\u2026/g, '...'], // horizontal ellipsis (\u2026)
|
|
124
|
+
[/`/g, "'"], // backtick (Markdown inline-code marker) -> single quote
|
|
125
|
+
// Bidirectional arrows first (they contain both `<` and `>`).
|
|
126
|
+
[UNICODE_DOUBLE_BOTH_ARROW_RE, ' to/from '],
|
|
127
|
+
[UNICODE_BOTH_ARROW_RE, ' to/from '],
|
|
128
|
+
[/<=+>|<-+>/g, ' to/from '],
|
|
129
|
+
// Right arrows.
|
|
130
|
+
[UNICODE_DOUBLE_RIGHT_ARROW_RE, ' to '],
|
|
131
|
+
[UNICODE_RIGHT_ARROW_RE, ' to '],
|
|
132
|
+
[/-+>|=+>/g, ' to '],
|
|
133
|
+
// Unicode left arrows. An ASCII `<-` is deliberately NOT treated as an
|
|
134
|
+
// arrow (`x<-1` is more often a comparison), so it falls through to ` lt `.
|
|
135
|
+
[UNICODE_DOUBLE_LEFT_ARROW_RE, ' from '],
|
|
136
|
+
[UNICODE_LEFT_ARROW_RE, ' from '],
|
|
137
|
+
// Comparison operators, multi-character before single.
|
|
138
|
+
[/\u2265/g, ' at least '], // greater-than or equal (\u2265)
|
|
139
|
+
[/\u2264/g, ' at most '], // less-than or equal (\u2264)
|
|
140
|
+
[/\u2260/g, ' ne '], // not equal (\u2260)
|
|
141
|
+
[/>=/g, ' at least '],
|
|
142
|
+
[/<=/g, ' at most '],
|
|
143
|
+
[/!=/g, ' ne '],
|
|
144
|
+
[/==+/g, ' eq '],
|
|
145
|
+
[/&&/g, ' and '],
|
|
146
|
+
[/>/g, ' gt '],
|
|
147
|
+
[/</g, ' lt '],
|
|
148
|
+
[/=/g, ' eq '],
|
|
149
|
+
[/&/g, ' and '],
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
function applySubstitutions(text, table) {
|
|
153
|
+
let out = text;
|
|
154
|
+
for (const [re, replacement] of table) out = out.replace(re, replacement);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
74
158
|
/**
|
|
75
|
-
* Rewrites
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* validation, so a description is not rejected wholesale
|
|
79
|
-
* lose no meaning when normalized. This is a
|
|
80
|
-
*
|
|
81
|
-
* still
|
|
82
|
-
* stricter table.
|
|
159
|
+
* Rewrites common non-ASCII punctuation LLM reviewers routinely emit in
|
|
160
|
+
* newTask descriptions -- em/en dashes, curly quotes, ellipsis, Unicode
|
|
161
|
+
* arrows and comparison signs -- to ASCII equivalents before
|
|
162
|
+
* SAFE_DESCRIPTION_RE validation, so a description is not rejected wholesale
|
|
163
|
+
* over characters that lose no meaning when normalized. This is a FIXED
|
|
164
|
+
* substitution table (DESCRIPTION_SUBSTITUTIONS), not a general Unicode
|
|
165
|
+
* stripper: anything still outside the allowlist afterwards is still a hard
|
|
166
|
+
* rejection. See sanitizeNewTaskTitle() below for title's own, stricter table.
|
|
83
167
|
* @param {string} description
|
|
84
168
|
* @returns {string}
|
|
85
169
|
*/
|
|
86
170
|
export function sanitizeNewTaskDescription(description) {
|
|
87
|
-
return String(description ?? '')
|
|
88
|
-
.replace(/[\u2014\u2013]/g, '--') // em dash (\u2014), en dash (\u2013)
|
|
89
|
-
.replace(/[\u2018\u2019]/g, "'") // curly single quotes (\u2018 \u2019)
|
|
90
|
-
.replace(/[\u201C\u201D]/g, '"') // curly double quotes (\u201C \u201D)
|
|
91
|
-
.replace(/\u2026/g, '...'); // horizontal ellipsis (\u2026)
|
|
171
|
+
return applySubstitutions(String(description ?? ''), DESCRIPTION_SUBSTITUTIONS);
|
|
92
172
|
}
|
|
93
173
|
|
|
94
174
|
/**
|
|
95
175
|
* Same idea as sanitizeNewTaskDescription() above, for title -- but with a
|
|
96
|
-
* STRICTER substitution table, since title still has
|
|
97
|
-
* SAFE_TEXT_RE shell-safety allowlist afterwards (it is
|
|
98
|
-
* into a `bd create "..."` command; description is not).
|
|
99
|
-
* here maps to
|
|
100
|
-
* reopens the injection surface that allowlist exists to close --
|
|
101
|
-
* rescues titles that would otherwise be needlessly rejected over
|
|
102
|
-
* common LLM punctuation choices
|
|
176
|
+
* STRICTER substitution table (TITLE_SUBSTITUTIONS), since title still has
|
|
177
|
+
* to pass the tighter SAFE_TEXT_RE shell-safety allowlist afterwards (it is
|
|
178
|
+
* interpolated inline into a `bd create "..."` command; description is not).
|
|
179
|
+
* Every substitution here maps to characters SAFE_TEXT_RE already admits, so
|
|
180
|
+
* this never reopens the injection surface that allowlist exists to close --
|
|
181
|
+
* it only rescues titles that would otherwise be needlessly rejected over
|
|
182
|
+
* benign, common LLM punctuation choices:
|
|
183
|
+
* - arrows (`->`, `=>`, Unicode right arrows) -> " to ", Unicode left
|
|
184
|
+
* arrows -> " from ", bidirectional arrows -> " to/from ";
|
|
185
|
+
* - `>=` / `<=` -> " at least " / " at most ", `!=` -> " ne ", lone `>` /
|
|
186
|
+
* `<` -> " gt " / " lt ", `=` -> " eq ", `&` -> " and ";
|
|
187
|
+
* then runs of spaces are collapsed and the result is trimmed. Observed live (apra-fleet-vk0a's sibling
|
|
103
188
|
* finding): a reviewer wrote a title referencing a CLI command in backticks
|
|
104
189
|
* (`` `apra-fleet status` ``, ordinary Markdown inline-code style), which
|
|
105
190
|
* SAFE_TEXT_RE rejects outright (backtick is excluded as a POSIX
|
|
@@ -115,12 +200,64 @@ export function sanitizeNewTaskDescription(description) {
|
|
|
115
200
|
* @returns {string}
|
|
116
201
|
*/
|
|
117
202
|
export function sanitizeNewTaskTitle(title) {
|
|
118
|
-
return String(title ?? '')
|
|
119
|
-
.replace(/
|
|
120
|
-
.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
203
|
+
return applySubstitutions(String(title ?? ''), TITLE_SUBSTITUTIONS)
|
|
204
|
+
.replace(/ {2,}/g, ' ')
|
|
205
|
+
.trim();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Escapes a value to pure printable ASCII: JSON.stringify (quotes, control
|
|
210
|
+
* characters, backslashes) plus \uXXXX for every remaining non-ASCII UTF-16
|
|
211
|
+
* code unit. The result always passes SAFE_DESCRIPTION_RE and JSON.parse
|
|
212
|
+
* decodes it back to the original string.
|
|
213
|
+
* @param {unknown} value
|
|
214
|
+
* @returns {string}
|
|
215
|
+
*/
|
|
216
|
+
export function escapeToAsciiJson(value) {
|
|
217
|
+
return JSON.stringify(String(value ?? '')).replace(
|
|
218
|
+
/[^\x20-\x7E]/g,
|
|
219
|
+
(ch) => `\\u${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')}`,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const FALLBACK_TITLE_PLACEHOLDER = 'Follow-up finding (original title not shell-safe)';
|
|
224
|
+
|
|
225
|
+
// Prefix of the description line that preserves a reviewer's original title
|
|
226
|
+
// whenever the filed title differs from it (mapped, dash-stripped, or a
|
|
227
|
+
// fallback). Shared by validateNewTask() and buildFallbackNewTask().
|
|
228
|
+
const ORIGINAL_TITLE_LABEL = 'Original title (JSON-escaped, non-ASCII as \\uXXXX): ';
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Builds a filable variant of a newTask whose TITLE still fails
|
|
232
|
+
* validateNewTask() after sanitizeNewTaskTitle(). The catch-all strip applies
|
|
233
|
+
* ONLY here, to this fallback title: every character SAFE_TEXT_RE does not
|
|
234
|
+
* admit becomes a space (spaces collapsed, trimmed; a fixed placeholder when
|
|
235
|
+
* nothing survives). The ORIGINAL title is preserved at the top of the
|
|
236
|
+
* description, escaped by escapeToAsciiJson() so SAFE_DESCRIPTION_RE passes.
|
|
237
|
+
* The result is re-validated through validateNewTask(); a priority or
|
|
238
|
+
* description failure is NOT rescued -- null is returned and the caller keeps
|
|
239
|
+
* its normal rejection path.
|
|
240
|
+
* @param {{ title: unknown, description: unknown, priority: unknown }} newTask
|
|
241
|
+
* @returns {{ ok: true, title: string, description: string, priority: string } | null}
|
|
242
|
+
*/
|
|
243
|
+
export function buildFallbackNewTask(newTask) {
|
|
244
|
+
// Only a TITLE failure is rescued: priority and description must already
|
|
245
|
+
// pass on their own (checked with a known-safe stand-in title).
|
|
246
|
+
if (!validateNewTask({ ...(newTask || {}), title: FALLBACK_TITLE_PLACEHOLDER }).ok) return null;
|
|
247
|
+
const originalTitle = newTask && newTask.title;
|
|
248
|
+
const stripped = sanitizeNewTaskTitle(originalTitle)
|
|
249
|
+
.replace(/[^A-Za-z0-9 .,:;!?()'_/+[\]-]/g, ' ')
|
|
250
|
+
.replace(/ {2,}/g, ' ')
|
|
251
|
+
.trim()
|
|
252
|
+
// Strip leading dashes here too, so validateNewTask() receives a
|
|
253
|
+
// title it will not change and does not prepend a second
|
|
254
|
+
// original-title line quoting this intermediate fallback title.
|
|
255
|
+
.replace(/^[-\s]+/, '');
|
|
256
|
+
const fallbackTitle = stripped && SAFE_TEXT_RE.test(stripped) ? stripped : FALLBACK_TITLE_PLACEHOLDER;
|
|
257
|
+
const originalDescription = String((newTask && newTask.description) ?? '');
|
|
258
|
+
const description = `${ORIGINAL_TITLE_LABEL}${escapeToAsciiJson(originalTitle)}\n\n${originalDescription}`;
|
|
259
|
+
const result = validateNewTask({ title: fallbackTitle, description, priority: newTask && newTask.priority });
|
|
260
|
+
return result.ok ? result : null;
|
|
124
261
|
}
|
|
125
262
|
|
|
126
263
|
/**
|
|
@@ -146,17 +283,24 @@ export function validateNewTask(newTask) {
|
|
|
146
283
|
}
|
|
147
284
|
// The title is the first positional argument of `bd create`, so a leading
|
|
148
285
|
// '-' would be parsed as a flag. Strip leading dashes (and the whitespace
|
|
149
|
-
// after them) shell-independently
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
// rejected below, falling through to the parent-notes fallback.
|
|
286
|
+
// after them) shell-independently. A title that is only dashes becomes
|
|
287
|
+
// empty and is rejected below, falling through to the parent-notes
|
|
288
|
+
// fallback.
|
|
153
289
|
const title = sanitizedTitle.replace(/^[-\s]+/, '');
|
|
154
290
|
if (!title) {
|
|
155
291
|
return { ok: false, reason: `title is empty after removing leading dashes: ${JSON.stringify(sanitizedTitle)}` };
|
|
156
292
|
}
|
|
293
|
+
// Whenever the filed title differs from the reviewer's original -- mapped
|
|
294
|
+
// by sanitizeNewTaskTitle() (`Map<K, V>` -> `Map lt K, V gt`,
|
|
295
|
+
// `--flag=value` -> `--flag eq value`) or dash-stripped above -- keep the
|
|
296
|
+
// ORIGINAL title, escaped to ASCII by escapeToAsciiJson(), at the top of
|
|
297
|
+
// the description so nothing is lost. Whitespace-only differences
|
|
298
|
+
// (trimming, collapsed runs of spaces) lose no information and do not
|
|
299
|
+
// count as a change.
|
|
300
|
+
const rawTitle = String((newTask && newTask.title) ?? '');
|
|
157
301
|
let description = sanitizeNewTaskDescription(newTask && newTask.description);
|
|
158
|
-
if (description && title !==
|
|
159
|
-
description =
|
|
302
|
+
if (description && title !== rawTitle.replace(/ {2,}/g, ' ').trim()) {
|
|
303
|
+
description = `${ORIGINAL_TITLE_LABEL}${escapeToAsciiJson(rawTitle)}\n\n${description}`;
|
|
160
304
|
}
|
|
161
305
|
if (!description || !SAFE_DESCRIPTION_RE.test(description)) {
|
|
162
306
|
return { ok: false, reason: `description fails ASCII-printable validation ${SAFE_DESCRIPTION_RE} (or is empty): ${JSON.stringify(description)}` };
|
|
@@ -441,6 +585,10 @@ export async function finalizeAbort({ error, branch, baseBranch, member, command
|
|
|
441
585
|
safeMessage ? `- Error message: ${safeMessage}` : null,
|
|
442
586
|
safeDetails ? `- Error details: ${safeDetails}` : null,
|
|
443
587
|
].filter((line) => line !== null).join('\n'),
|
|
588
|
+
// A set-aside stall (StalledSprintError) carries the run's set-aside
|
|
589
|
+
// records; rendered as the "Set aside this run" section.
|
|
590
|
+
setAside: error && Array.isArray(error.setAside) ? error.setAside : [],
|
|
591
|
+
waited: error && Array.isArray(error.waited) ? error.waited : [],
|
|
444
592
|
previousBody,
|
|
445
593
|
});
|
|
446
594
|
const prBody = buildAbortBody();
|
|
@@ -484,6 +632,10 @@ export async function finalizeAbort({ error, branch, baseBranch, member, command
|
|
|
484
632
|
});
|
|
485
633
|
|
|
486
634
|
if (!prResult.ok) {
|
|
635
|
+
if (prResult.credentialAbsent) {
|
|
636
|
+
log(`finalizeAbort: [Publish Abort PR] NO [ABORTED] pull request was opened for branch '${branch}' -> '${baseBranch}': no PR credential is deployed (branch is pushed). Deploy a credential to get PRs: ${prResult.error}`);
|
|
637
|
+
return { prUrl: null, reason: 'pr-auth-failed', pushed: true, commitCount };
|
|
638
|
+
}
|
|
487
639
|
if (prResult.authFailure) {
|
|
488
640
|
// apra-fleet-647.1.1.1: a PR auth failure survives the reactive
|
|
489
641
|
// one-shot self-heal+retry inside raiseVcsPrForMember (i.e. the
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// bd-sync-command.mjs -- the member-bound command string for a `bd dolt pull`
|
|
2
|
+
// / `bd dolt push`, built per member OS/shell.
|
|
3
|
+
//
|
|
4
|
+
// WHY: on a Windows member, bd's embedded Dolt starts one git.exe per remote
|
|
5
|
+
// chunk concurrently (bounded only by GOMAXPROCS), and Windows refuses the
|
|
6
|
+
// burst with CreateProcess ERROR_NOT_ENOUGH_MEMORY (upstream:
|
|
7
|
+
// https://github.com/gastownhall/beads/issues/7082). Running bd with
|
|
8
|
+
// GOMAXPROCS=1 serializes those spawns -- 1 is the value evidenced on the
|
|
9
|
+
// failing members (precedent: scripts/rekey-beads-memories.mjs defaults
|
|
10
|
+
// GOMAXPROCS to 1).
|
|
11
|
+
//
|
|
12
|
+
// The value is FIXED, never read from the member's environment: honoring an
|
|
13
|
+
// operator-set value would need shell variable expansion in a member-bound
|
|
14
|
+
// command, which is forbidden (the member's shell may be PowerShell or bash
|
|
15
|
+
// and the string is built here, in JS). The assignment is scoped to the one
|
|
16
|
+
// command string: execute_command starts a fresh shell process per call, and
|
|
17
|
+
// on bash the `NAME=value cmd` form scopes it to that single process.
|
|
18
|
+
//
|
|
19
|
+
// POSIX (linux/macOS) members are left byte-identical: they have no
|
|
20
|
+
// per-process spawn limit of this kind.
|
|
21
|
+
//
|
|
22
|
+
// Kept in its own module (not dolt-sync.mjs) because dolt-settle.mjs issues
|
|
23
|
+
// its own post-resolve `bd dolt pull`/`bd dolt push` and is imported BY
|
|
24
|
+
// dolt-sync.mjs -- importing dolt-sync.mjs back would be circular.
|
|
25
|
+
//
|
|
26
|
+
// ASCII only.
|
|
27
|
+
|
|
28
|
+
/** GOMAXPROCS for a bd sync process on a Windows member. */
|
|
29
|
+
export const WINDOWS_BD_GOMAXPROCS = '1';
|
|
30
|
+
|
|
31
|
+
/** The POSIX target an unresolved member degrades to (pre-existing behavior). */
|
|
32
|
+
export const POSIX_MEMBER_TARGET = Object.freeze({ os: 'linux', shell: '' });
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Normalize a member target to { os, shell }. Accepts the member_detail shape
|
|
36
|
+
* ({ os, shell }) or a bare OS / Node platform string ('win32' is folded into
|
|
37
|
+
* 'windows' so dolt-settle's platform strings work unchanged).
|
|
38
|
+
*
|
|
39
|
+
* @param {{ os?: string, shell?: string }|string|null|undefined} target
|
|
40
|
+
* @returns {{ os: string, shell: string }}
|
|
41
|
+
*/
|
|
42
|
+
export function normalizeMemberTarget(target) {
|
|
43
|
+
const raw = typeof target === 'string' ? { os: target, shell: '' } : (target || {});
|
|
44
|
+
let os = String(raw.os || '').trim().toLowerCase();
|
|
45
|
+
if (os === 'win32') os = 'windows';
|
|
46
|
+
const shell = String(raw.shell || '').trim().toLowerCase();
|
|
47
|
+
return { os, shell };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The command string to issue for a bd sync command on a member.
|
|
52
|
+
*
|
|
53
|
+
* linux / macOS / unresolved -> `cmd`, unchanged
|
|
54
|
+
* windows + gitbash -> `GOMAXPROCS=1 cmd`
|
|
55
|
+
* windows + PowerShell (any other) -> `$env:GOMAXPROCS='1'; cmd`
|
|
56
|
+
*
|
|
57
|
+
* The PowerShell form is an ASSIGNMENT statement, not an expansion: nothing is
|
|
58
|
+
* read from the member's environment.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} cmd - the logical command, e.g. 'bd dolt pull'
|
|
61
|
+
* @param {{ os?: string, shell?: string }|string|null|undefined} target
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*/
|
|
64
|
+
export function bdSyncCommandFor(cmd, target) {
|
|
65
|
+
const { os, shell } = normalizeMemberTarget(target);
|
|
66
|
+
if (os !== 'windows') return cmd;
|
|
67
|
+
if (shell === 'gitbash') return `GOMAXPROCS=${WINDOWS_BD_GOMAXPROCS} ${cmd}`;
|
|
68
|
+
return `$env:GOMAXPROCS='${WINDOWS_BD_GOMAXPROCS}'; ${cmd}`;
|
|
69
|
+
}
|
|
@@ -366,6 +366,27 @@ async function adoptLandedChild(opts, childId) {
|
|
|
366
366
|
* How many `bd create` dispatches createChildBeadWithAllocatedId makes for one
|
|
367
367
|
* newTask before giving up -- each with a freshly allocated id (GitHub #615).
|
|
368
368
|
*/
|
|
369
|
+
/**
|
|
370
|
+
* Files an operator DECISION bead (decisions.mjs recordPendingDecision):
|
|
371
|
+
* a top-level bead -- no parent, no `--id`, so bd mints the id and there is
|
|
372
|
+
* no allocator id to probe -- of type `decision`, labelled for `bd human`,
|
|
373
|
+
* created `deferred` so it is never sprint work, and linked to the work bead
|
|
374
|
+
* by a `discovered-from` edge (never a blocks edge). The body is a
|
|
375
|
+
* member-local file staged by the caller; only the bead id and the fixed
|
|
376
|
+
* title shape are inline. Lives here because this module is the single
|
|
377
|
+
* permitted bead-creation surface (explicit-id-create-guard.mjs).
|
|
378
|
+
*
|
|
379
|
+
* @param {{ command: Function, member: string, workBeadId: string, title: string, bodyFile: string, priority: number, label: string, labelName?: string }} opts
|
|
380
|
+
* @returns {Promise<string>} bd's raw output (the new id, from --silent)
|
|
381
|
+
*/
|
|
382
|
+
export async function createDecisionBead({ command, member, workBeadId, title, bodyFile, priority, label, labelName = 'human' }) {
|
|
383
|
+
return command(
|
|
384
|
+
`bd create "${title}" --body-file "${bodyFile}" -p ${priority} -t decision ` +
|
|
385
|
+
`-l ${labelName} -s deferred --deps "discovered-from:${workBeadId}" --silent`,
|
|
386
|
+
{ member_name: member, silent: true, label },
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
369
390
|
export const CHILD_CREATE_MAX_ATTEMPTS = 3;
|
|
370
391
|
|
|
371
392
|
/**
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// beads-lock-probe.mjs -- who holds the beads locks on a member?
|
|
2
|
+
//
|
|
3
|
+
// A `bd dolt pull`/`bd dolt push` that waits on a beads lock prints nothing
|
|
4
|
+
// until it gets the lock, so a lock held by some other, long-lived process
|
|
5
|
+
// (observed: something left behind by an agent session that had just ended on
|
|
6
|
+
// that member) used to look like a silent ~10 minute hang ending in the
|
|
7
|
+
// inactivity kill. runDoltStep (dolt-sync.mjs) runs the probe built here once
|
|
8
|
+
// per attempt that is still in flight after a watchdog delay, logs the result,
|
|
9
|
+
// and fails fast with a typed error naming a FOREIGN holder.
|
|
10
|
+
//
|
|
11
|
+
// The probe is a separate, short execute_command on the same member while the
|
|
12
|
+
// sync command is still in flight. That is allowed: the fleet server takes no
|
|
13
|
+
// per-member lock for execute_command (its busy marker only drives the
|
|
14
|
+
// statusline), and the workflow engine's command() has no per-member queue.
|
|
15
|
+
//
|
|
16
|
+
// Probe output is line based and tab separated, the same on every OS:
|
|
17
|
+
// HOLDER<TAB><pid><TAB><age><TAB><lock path><TAB><command line>
|
|
18
|
+
// CANDIDATE<TAB><pid><TAB><age><TAB>-<TAB><command line>
|
|
19
|
+
// NOLOOKUP<TAB><why holders cannot be listed on this member>
|
|
20
|
+
// <age> is seconds, or a ps(1) etime string ([[dd-]hh:]mm:ss).
|
|
21
|
+
//
|
|
22
|
+
// ASCII only.
|
|
23
|
+
|
|
24
|
+
import { getSeCommands } from './se-os-commands.mjs';
|
|
25
|
+
import { normalizeMemberTarget } from './bd-sync-command.mjs';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The beads lock files, relative to the member's work folder (where the
|
|
29
|
+
* beads workspace lives). These names are bd implementation details: keep
|
|
30
|
+
* them HERE, in one place, so a bd upgrade that renames them is a one-line
|
|
31
|
+
* change. A `*` segment is a shell glob (the embedded Dolt database
|
|
32
|
+
* directory is named per clone).
|
|
33
|
+
*/
|
|
34
|
+
export const BEADS_LOCK_FILES = Object.freeze([
|
|
35
|
+
'.beads/embeddeddolt.gate.lock',
|
|
36
|
+
'.beads/dolt.gate.lock',
|
|
37
|
+
'.beads/embeddeddolt/*/.dolt/noms/LOCK',
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
/** Process image names a Windows candidate listing looks for. */
|
|
41
|
+
export const BEADS_LOCK_CANDIDATE_IMAGES = Object.freeze(['bd.exe', 'dolt.exe']);
|
|
42
|
+
|
|
43
|
+
const POSIX_LOCK_LIST = BEADS_LOCK_FILES.join(' ');
|
|
44
|
+
|
|
45
|
+
/** Every open file descriptor of the member user's processes (Linux /proc).
|
|
46
|
+
* A plain string, not inlined in a template: keeps the glob's slash-star
|
|
47
|
+
* sequences out of template text. */
|
|
48
|
+
const PROC_FD_GLOB = '/proc/[0-9]*/fd/*';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Linux: walk /proc/<pid>/fd for links to each lock file (no extra package
|
|
52
|
+
* needed; the member's own user's processes are visible, which is the user bd
|
|
53
|
+
* runs as), falling back to lsof when /proc is not readable. Uses only
|
|
54
|
+
* script-local shell variables -- nothing is read from the environment.
|
|
55
|
+
*/
|
|
56
|
+
function linuxProbe() {
|
|
57
|
+
return [
|
|
58
|
+
`if [ -d /proc/self/fd ]; then`,
|
|
59
|
+
` for f in ${POSIX_LOCK_LIST}; do [ -e "$f" ] || continue; a=$(readlink -f "$f");`,
|
|
60
|
+
` for d in ${PROC_FD_GLOB}; do [ "$(readlink "$d" 2>/dev/null)" = "$a" ] || continue; p=$(echo "$d" | cut -d/ -f3);`,
|
|
61
|
+
` printf 'HOLDER\\t%s\\t%s\\t%s\\t%s\\n' "$p" "$(ps -o etime= -p "$p" | tr -d ' ')" "$f" "$(tr '\\0' ' ' < /proc/$p/cmdline 2>/dev/null)";`,
|
|
62
|
+
` done; done | sort -u;`,
|
|
63
|
+
`elif command -v lsof >/dev/null 2>&1; then`,
|
|
64
|
+
` for f in ${POSIX_LOCK_LIST}; do [ -e "$f" ] || continue;`,
|
|
65
|
+
` for p in $(lsof -t -- "$f" 2>/dev/null | sort -u); do printf 'HOLDER\\t%s\\t%s\\t%s\\t%s\\n' "$p" "$(ps -o etime= -p "$p" | tr -d ' ')" "$f" "$(ps -o args= -p "$p")"; done;`,
|
|
66
|
+
` done;`,
|
|
67
|
+
`else printf 'NOLOOKUP\\tneither /proc nor lsof is available on this member\\n'; fi`,
|
|
68
|
+
].join('');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** macOS: lsof ships with the OS; ps etime/command for age and command line. */
|
|
72
|
+
function macosProbe() {
|
|
73
|
+
return [
|
|
74
|
+
`if command -v lsof >/dev/null 2>&1; then`,
|
|
75
|
+
` for f in ${POSIX_LOCK_LIST}; do [ -e "$f" ] || continue;`,
|
|
76
|
+
` for p in $(lsof -t -- "$f" 2>/dev/null | sort -u); do printf 'HOLDER\\t%s\\t%s\\t%s\\t%s\\n' "$p" "$(ps -o etime= -p "$p" | tr -d ' ')" "$f" "$(ps -o command= -p "$p")"; done;`,
|
|
77
|
+
` done;`,
|
|
78
|
+
`else printf 'NOLOOKUP\\tlsof is not available on this member\\n'; fi`,
|
|
79
|
+
].join('');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Windows: there is no built-in way to ask which process holds a file lock
|
|
84
|
+
* (that needs a handle-enumeration tool that is not part of Windows), so the
|
|
85
|
+
* probe says so explicitly and lists the running bd/dolt processes -- with
|
|
86
|
+
* pid, age and command line -- as CANDIDATES. Run as PowerShell on every
|
|
87
|
+
* Windows member; a Git Bash member gets it through -EncodedCommand (its
|
|
88
|
+
* MSYS `ps` pids are not native Windows pids).
|
|
89
|
+
*/
|
|
90
|
+
function windowsProbeScript() {
|
|
91
|
+
const filter = BEADS_LOCK_CANDIDATE_IMAGES.map((n) => `Name='${n}'`).join(' OR ');
|
|
92
|
+
return [
|
|
93
|
+
// Progress records (e.g. "Preparing modules for first use") would
|
|
94
|
+
// otherwise be serialized onto the output stream of an encoded run.
|
|
95
|
+
`$ProgressPreference = 'SilentlyContinue';`,
|
|
96
|
+
`Write-Output (@('NOLOOKUP', 'Windows has no built-in lookup of the process holding a file lock; listing running bd/dolt processes as candidates') -join [char]9);`,
|
|
97
|
+
`Get-CimInstance Win32_Process -Filter "${filter}" | ForEach-Object { Write-Output (@('CANDIDATE', $_.ProcessId, [int]((Get-Date) - $_.CreationDate).TotalSeconds, '-', $_.CommandLine) -join [char]9) }`,
|
|
98
|
+
].join(' ');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The member-bound lock-holder probe command for a member's OS/shell.
|
|
103
|
+
*
|
|
104
|
+
* @param {{ os?: string, shell?: string }|string|null|undefined} target
|
|
105
|
+
* @returns {string}
|
|
106
|
+
*/
|
|
107
|
+
export function buildLockHolderProbe(target) {
|
|
108
|
+
const { os, shell } = normalizeMemberTarget(target);
|
|
109
|
+
if (os === 'windows') {
|
|
110
|
+
return getSeCommands({ os, shell }).wrapPowerShellScript(windowsProbeScript(), 'beads lock-holder probe');
|
|
111
|
+
}
|
|
112
|
+
if (os === 'darwin' || os === 'macos') return macosProbe();
|
|
113
|
+
return linuxProbe();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Seconds from a probe age field: plain seconds, or a ps(1) etime string
|
|
118
|
+
* ([[dd-]hh:]mm:ss). Null when unparseable.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} text
|
|
121
|
+
* @returns {number|null}
|
|
122
|
+
*/
|
|
123
|
+
export function parseProbeAgeSeconds(text) {
|
|
124
|
+
const t = String(text == null ? '' : text).trim();
|
|
125
|
+
if (/^\d+$/.test(t)) return Number(t);
|
|
126
|
+
const m = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/.exec(t);
|
|
127
|
+
if (!m) return null;
|
|
128
|
+
const [, d, h, mi, s] = m;
|
|
129
|
+
return (Number(d || 0) * 86400) + (Number(h || 0) * 3600) + (Number(mi) * 60) + Number(s);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Parse a probe's output.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} output
|
|
136
|
+
* @returns {{ holders: Array<{ pid: number, ageS: number|null, lock: string, commandLine: string }>, candidates: Array<{ pid: number, ageS: number|null, lock: string, commandLine: string }>, noLookup: string|null }}
|
|
137
|
+
*/
|
|
138
|
+
export function parseLockHolderProbe(output) {
|
|
139
|
+
const holders = [];
|
|
140
|
+
const candidates = [];
|
|
141
|
+
let noLookup = null;
|
|
142
|
+
const seen = new Set();
|
|
143
|
+
for (const line of String(output == null ? '' : output).split(/\r?\n/)) {
|
|
144
|
+
// A tag is found anywhere on the line: a transport that merges
|
|
145
|
+
// stderr into stdout can glue stray shell output in front of it.
|
|
146
|
+
const at = line.search(/(?:HOLDER|CANDIDATE|NOLOOKUP)\t/);
|
|
147
|
+
if (at < 0) continue;
|
|
148
|
+
const parts = line.slice(at).split('\t');
|
|
149
|
+
const tag = parts[0];
|
|
150
|
+
if (tag === 'NOLOOKUP') {
|
|
151
|
+
noLookup = parts.slice(1).join(' ').trim() || 'holders cannot be listed on this member';
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (tag !== 'HOLDER' && tag !== 'CANDIDATE') continue;
|
|
155
|
+
const pid = Number(String(parts[1] || '').trim());
|
|
156
|
+
if (!Number.isInteger(pid) || pid <= 0) continue;
|
|
157
|
+
const entry = {
|
|
158
|
+
pid,
|
|
159
|
+
ageS: parseProbeAgeSeconds(parts[2]),
|
|
160
|
+
lock: String(parts[3] || '').trim(),
|
|
161
|
+
commandLine: parts.slice(4).join('\t').trim(),
|
|
162
|
+
};
|
|
163
|
+
const key = `${tag}:${pid}:${entry.lock}`;
|
|
164
|
+
if (seen.has(key)) continue;
|
|
165
|
+
seen.add(key);
|
|
166
|
+
(tag === 'HOLDER' ? holders : candidates).push(entry);
|
|
167
|
+
}
|
|
168
|
+
return { holders, candidates, noLookup };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** One human-readable line per process. */
|
|
172
|
+
export function describeLockProcess(p) {
|
|
173
|
+
const age = p.ageS == null ? 'age unknown' : `age ${p.ageS}s`;
|
|
174
|
+
const lock = p.lock && p.lock !== '-' ? ` on ${p.lock}` : '';
|
|
175
|
+
return `pid ${p.pid} (${age})${lock}: ${p.commandLine || '(command line unavailable)'}`;
|
|
176
|
+
}
|