@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
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
// member session -- including a role agent dispatched on the maintainer
|
|
30
30
|
// member, which connects through the plain per-folder ?member= entry --
|
|
31
31
|
// does not see them.
|
|
32
|
+
// - kb_demote lowers CONFIRMED to INFERRED. It is served on the same terms
|
|
33
|
+
// as kb_promote (kb_maintainer session only): the engine applies every
|
|
34
|
+
// reviewer demotion through the maintainer session, and no role agent
|
|
35
|
+
// needs to call it directly.
|
|
32
36
|
// - kb_import is served to every member session, but an explicit `path`
|
|
33
37
|
// (a caller-named bible, equivalent in power to kb_promote) is refused in
|
|
34
38
|
// a member session without the grant (src/tools/kb-import.ts); the
|
|
@@ -43,7 +47,7 @@ export const REGISTERED_TOOL_NAMES = Object.freeze([
|
|
|
43
47
|
'update_member', 'dolt_push_mutex', 'child_id_allocator', 'member_reservation',
|
|
44
48
|
'send_files', 'receive_files', 'execute_prompt', 'execute_command',
|
|
45
49
|
'provision_llm_auth', 'setup_ssh_key', 'setup_git_app', 'provision_vcs_auth',
|
|
46
|
-
'revoke_vcs_auth', 'vcs_credential_exec', 'fleet_status', 'member_detail',
|
|
50
|
+
'revoke_vcs_auth', 'vcs_credential_exec', 'fleet_status', 'fleet_snapshot', 'member_detail',
|
|
47
51
|
'update_llm_cli', 'shutdown_server', 'version', 'session_stats', 'compose_permissions',
|
|
48
52
|
'cloud_control', 'monitor_task', 'stop_prompt', 'credential_store_set',
|
|
49
53
|
'credential_store_list', 'credential_store_delete', 'credential_store_update',
|
|
@@ -51,7 +55,7 @@ export const REGISTERED_TOOL_NAMES = Object.freeze([
|
|
|
51
55
|
'code_graph', 'code_impact', 'code_query', 'code_context', 'code_map',
|
|
52
56
|
'code_flow', 'code_tests', 'code_reindex', 'code_status',
|
|
53
57
|
'kb_capture', 'kb_invalidate', 'kb_context', 'kb_session_prime', 'kb_query',
|
|
54
|
-
'kb_list', 'kb_harvest', 'kb_promote', 'kb_freshness_sweep', 'kb_import',
|
|
58
|
+
'kb_list', 'kb_harvest', 'kb_promote', 'kb_demote', 'kb_freshness_sweep', 'kb_import',
|
|
55
59
|
'kb_resolve_contradiction', 'kb_reconcile_prefilter', 'kb_setup', 'kb_export',
|
|
56
60
|
'kb_stats', 'kb_feedback', 'kb_bible_commit',
|
|
57
61
|
]);
|
|
@@ -75,11 +79,11 @@ export const MEMBER_BASE_TOOLS = Object.freeze([
|
|
|
75
79
|
]);
|
|
76
80
|
/**
|
|
77
81
|
* Tools served ONLY to a kb_maintainer member session (the engine's grant), on
|
|
78
|
-
* top of the base allowlist. They mint CONFIRMED. Not part of
|
|
82
|
+
* top of the base allowlist. They mint CONFIRMED, or (kb_demote) withdraw it. Not part of
|
|
79
83
|
* MEMBER_ALLOWED_TOOLS, so client-side deny rules keep them denied for every
|
|
80
84
|
* agent session on a member.
|
|
81
85
|
*/
|
|
82
|
-
export const MEMBER_MAINTAINER_TOOLS = Object.freeze(['kb_promote', 'kb_resolve_contradiction', 'kb_reconcile_prefilter']);
|
|
86
|
+
export const MEMBER_MAINTAINER_TOOLS = Object.freeze(['kb_promote', 'kb_demote', 'kb_resolve_contradiction', 'kb_reconcile_prefilter']);
|
|
83
87
|
/**
|
|
84
88
|
* kb_ tools no member session is ever served, whatever its grants. Listed so
|
|
85
89
|
* the classification of every kb_ tool is explicit (and test-checked).
|
|
@@ -330,7 +330,8 @@ export function portHeldByOtherUserMessage(port, holder, installKind, me = curre
|
|
|
330
330
|
? 'Remedy: give this member install its own port -- re-run "apra-fleet install --member --port <free port>"; '
|
|
331
331
|
+ 'the fleet picks up the new port on its next fleet_install "auto" probe.'
|
|
332
332
|
: `Remedy: that user stops their apra-fleet server ("apra-fleet stop", or "apra-fleet uninstall" to remove it), then re-run the install. `
|
|
333
|
-
+ 'A full install\'s service
|
|
333
|
+
+ 'A full install\'s service binds the port its last install recorded (APRA_FLEET_PORT at install time, else the default): '
|
|
334
|
+
+ 'to change it, re-run "apra-fleet install" with APRA_FLEET_PORT set to a free port.';
|
|
334
335
|
return `${PORT_HELD_BY_OTHER_USER_CODE}: port ${port} on 127.0.0.1 is held by ${holderPhrase(holder)}, another user's process${self}. `
|
|
335
336
|
+ 'apra-fleet will not share or take over another user\'s server. '
|
|
336
337
|
+ remedy;
|
|
@@ -43,13 +43,29 @@ export interface ServiceStatus {
|
|
|
43
43
|
* autostart only, nothing restarts a server that dies mid-session).
|
|
44
44
|
*/
|
|
45
45
|
export type RegisterResult = 'created' | 'reused' | 'run-key';
|
|
46
|
+
/**
|
|
47
|
+
* Why a stop is happening. 'install' = install --force is stopping the service
|
|
48
|
+
* and owns all operator guidance (it clears the stopped marker and prints the
|
|
49
|
+
* legacy-task guidance once itself); default = a user-facing apra-fleet stop.
|
|
50
|
+
*/
|
|
51
|
+
export interface StopOptions {
|
|
52
|
+
reason?: 'install';
|
|
53
|
+
}
|
|
46
54
|
export interface ServiceManager {
|
|
47
55
|
register(binaryPath: string, args: string[], logPath: string): Promise<RegisterResult | void>;
|
|
48
56
|
unregister(): Promise<void>;
|
|
49
57
|
start(): Promise<void>;
|
|
50
58
|
/** Resolves false when the server was left running (pid not verifiable as apra-fleet). */
|
|
51
|
-
stop(): Promise<boolean | void>;
|
|
59
|
+
stop(opts?: StopOptions): Promise<boolean | void>;
|
|
52
60
|
query(): Promise<ServiceStatus>;
|
|
53
61
|
isInstalled(): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Windows only: the legacy-task upgrade guidance when the installed task is a
|
|
64
|
+
* legacy (e.g. elevated) one that install had to reuse, else null. Lets install
|
|
65
|
+
* print it instead of a start hint that would hit the same refusal.
|
|
66
|
+
*/
|
|
67
|
+
legacyGuidance?(): string | null;
|
|
68
|
+
/** Windows only: true once register() already printed the legacy-task guidance in this process, so install must not print it again. */
|
|
69
|
+
legacyGuidanceShown?(): boolean;
|
|
54
70
|
}
|
|
55
71
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RegisterResult, ServiceManager, ServiceStatus } from './types.js';
|
|
1
|
+
import type { RegisterResult, ServiceManager, ServiceStatus, StopOptions } from './types.js';
|
|
2
2
|
/** HKCU Run key used ONLY as the last-resort fallback (logon autostart, no restart). */
|
|
3
3
|
export declare const RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
4
4
|
export declare const RUN_VALUE = "ApraFleet";
|
|
@@ -175,6 +175,7 @@ export declare class WindowsServiceManager implements ServiceManager {
|
|
|
175
175
|
private readonly runSchtasks;
|
|
176
176
|
private readonly wrapperPath;
|
|
177
177
|
private reusedExistingTask;
|
|
178
|
+
private legacyReported;
|
|
178
179
|
private readonly runReg;
|
|
179
180
|
private readonly env;
|
|
180
181
|
private readonly now;
|
|
@@ -188,10 +189,14 @@ export declare class WindowsServiceManager implements ServiceManager {
|
|
|
188
189
|
register(binaryPath: string, args: string[], logPath: string): Promise<RegisterResult>;
|
|
189
190
|
/** Problems of the installed task when it is a legacy one (empty: current or unreadable). */
|
|
190
191
|
private installedLegacyProblems;
|
|
192
|
+
/** See ServiceManager.legacyGuidanceShown. */
|
|
193
|
+
legacyGuidanceShown(): boolean;
|
|
194
|
+
/** See ServiceManager.legacyGuidance: a reused legacy task refused /run because it cannot be replaced from here. */
|
|
195
|
+
legacyGuidance(): string | null;
|
|
191
196
|
private legacyProblemsOf;
|
|
192
197
|
unregister(): Promise<void>;
|
|
193
198
|
start(): Promise<void>;
|
|
194
|
-
stop(): Promise<boolean>;
|
|
199
|
+
stop(opts?: StopOptions): Promise<boolean>;
|
|
195
200
|
query(): Promise<ServiceStatus>;
|
|
196
201
|
isInstalled(): Promise<boolean>;
|
|
197
202
|
private taskExists;
|
|
@@ -377,6 +377,7 @@ export class WindowsServiceManager {
|
|
|
377
377
|
runSchtasks;
|
|
378
378
|
wrapperPath;
|
|
379
379
|
reusedExistingTask = false;
|
|
380
|
+
legacyReported = false;
|
|
380
381
|
runReg;
|
|
381
382
|
env;
|
|
382
383
|
now;
|
|
@@ -496,6 +497,7 @@ export class WindowsServiceManager {
|
|
|
496
497
|
problems.push('elevated');
|
|
497
498
|
const guidance = legacyTaskGuidance(problems);
|
|
498
499
|
console.warn(indent(guidance));
|
|
500
|
+
this.legacyReported = true;
|
|
499
501
|
// A detached install (apra-fleet update) has no console: persist it
|
|
500
502
|
// for the next service verb (already shown when this one is
|
|
501
503
|
// interactive), and leave it in the service log.
|
|
@@ -559,6 +561,17 @@ export class WindowsServiceManager {
|
|
|
559
561
|
return [];
|
|
560
562
|
}
|
|
561
563
|
}
|
|
564
|
+
/** See ServiceManager.legacyGuidanceShown. */
|
|
565
|
+
legacyGuidanceShown() { return this.legacyReported; }
|
|
566
|
+
/** See ServiceManager.legacyGuidance: a reused legacy task refused /run because it cannot be replaced from here. */
|
|
567
|
+
legacyGuidance() {
|
|
568
|
+
const problems = this.installedLegacyProblems();
|
|
569
|
+
if (problems.length === 0)
|
|
570
|
+
return null;
|
|
571
|
+
if (!problems.includes('elevated'))
|
|
572
|
+
problems.push('elevated');
|
|
573
|
+
return legacyTaskGuidance(problems);
|
|
574
|
+
}
|
|
562
575
|
legacyProblemsOf(raw) {
|
|
563
576
|
const launcherPath = launcherPathFor(this.wrapperPath);
|
|
564
577
|
// Only OUR task (wrapper, split wrapper, or wscript + our launcher) gets
|
|
@@ -643,7 +656,7 @@ export class WindowsServiceManager {
|
|
|
643
656
|
// versions it waits for the launched process).
|
|
644
657
|
this.spawnDetached('schtasks', ['/run', '/tn', WINDOWS_TASK_NAME]);
|
|
645
658
|
}
|
|
646
|
-
async stop() {
|
|
659
|
+
async stop(opts) {
|
|
647
660
|
// Disable FIRST: the task's repeating trigger would otherwise relaunch the
|
|
648
661
|
// server within one interval, undoing a deliberate stop. start/install
|
|
649
662
|
// re-enable it.
|
|
@@ -653,17 +666,21 @@ export class WindowsServiceManager {
|
|
|
653
666
|
}
|
|
654
667
|
catch (err) {
|
|
655
668
|
console.warn(`Could not disable the ${WINDOWS_TASK_NAME} task (${err.message.trim()}).`);
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
669
|
+
// install --force owns the guidance (printed once by install) and
|
|
670
|
+
// clears the stopped marker, so both lines would be wrong or doubled.
|
|
671
|
+
if (opts?.reason !== 'install') {
|
|
672
|
+
const problems = this.installedLegacyProblems();
|
|
673
|
+
if (problems.length > 0) {
|
|
674
|
+
// Disabling was just refused, whatever the XML says.
|
|
675
|
+
if (!problems.includes('elevated'))
|
|
676
|
+
problems.push('elevated');
|
|
677
|
+
console.warn(legacyTaskGuidance(problems));
|
|
678
|
+
}
|
|
679
|
+
// The stopped-by-user marker (written by apra-fleet stop) makes every
|
|
680
|
+
// service launch exit without starting the server.
|
|
681
|
+
console.warn("A stop made with 'apra-fleet stop' still holds: until 'apra-fleet start', every launch of the task " +
|
|
682
|
+
'exits without starting the server.');
|
|
662
683
|
}
|
|
663
|
-
// The stopped-by-user marker (written by apra-fleet stop) makes every
|
|
664
|
-
// service launch exit without starting the server.
|
|
665
|
-
console.warn("A stop made with 'apra-fleet stop' still holds: until 'apra-fleet start', every launch of the task " +
|
|
666
|
-
'exits without starting the server.');
|
|
667
684
|
}
|
|
668
685
|
}
|
|
669
686
|
return gracefulStopByServerJson((pid) => {
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export declare const SERVICE_NOTICE_PATH: string;
|
|
2
2
|
/** `shown`: the text was already printed to a console, so the next service verb does not repeat it. */
|
|
3
3
|
export declare function writeServiceNotice(text: string, file?: string, now?: Date, shown?: boolean): void;
|
|
4
|
+
/**
|
|
5
|
+
* Like writeServiceNotice, but never discards guidance that is still pending:
|
|
6
|
+
* when an unshown notice exists, `text` is appended to it (so the next verb
|
|
7
|
+
* prints both once). A `shown` text (already printed inline) is not added to a
|
|
8
|
+
* pending notice, since the user has seen it; a duplicate text is not repeated.
|
|
9
|
+
*/
|
|
10
|
+
export declare function appendServiceNotice(text: string, file?: string, now?: Date, shown?: boolean): void;
|
|
4
11
|
export declare function clearServiceNotice(file?: string): void;
|
|
5
12
|
/** Remove the pending notice only when its text contains `marker` (an obsolete refusal). */
|
|
6
13
|
export declare function clearServiceNoticeContaining(marker: string, file?: string): void;
|
|
@@ -19,6 +19,25 @@ export function writeServiceNotice(text, file = SERVICE_NOTICE_PATH, now = new D
|
|
|
19
19
|
}
|
|
20
20
|
catch { /* best-effort: never fail registration on the notice */ }
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Like writeServiceNotice, but never discards guidance that is still pending:
|
|
24
|
+
* when an unshown notice exists, `text` is appended to it (so the next verb
|
|
25
|
+
* prints both once). A `shown` text (already printed inline) is not added to a
|
|
26
|
+
* pending notice, since the user has seen it; a duplicate text is not repeated.
|
|
27
|
+
*/
|
|
28
|
+
export function appendServiceNotice(text, file = SERVICE_NOTICE_PATH, now = new Date(), shown = false) {
|
|
29
|
+
const existing = readNotice(file);
|
|
30
|
+
if (!existing || existing.shownAt) {
|
|
31
|
+
writeServiceNotice(text, file, now, shown);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (shown || existing.text.includes(text))
|
|
35
|
+
return;
|
|
36
|
+
try {
|
|
37
|
+
fs.writeFileSync(file, JSON.stringify({ ...existing, text: `${existing.text}\n${text}` }, null, 2));
|
|
38
|
+
}
|
|
39
|
+
catch { /* best-effort */ }
|
|
40
|
+
}
|
|
22
41
|
export function clearServiceNotice(file = SERVICE_NOTICE_PATH) {
|
|
23
42
|
try {
|
|
24
43
|
fs.unlinkSync(file);
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
export type SessionStatus = 'online' | 'busy' | 'idle';
|
|
3
|
+
/**
|
|
4
|
+
* Stable registry id of the operator's own orchestrating session.
|
|
5
|
+
*
|
|
6
|
+
* A session with no member identity (no member JWT, no ?member=) is the local
|
|
7
|
+
* orchestrator/PM session. When such a session declares the `claude/channel`
|
|
8
|
+
* capability at initialize -- i.e. it can actually receive channel pushes --
|
|
9
|
+
* http-transport registers it under this id in the local workspace, so
|
|
10
|
+
* send_message({ member_id: 'orchestrator' }) reaches it. With several such
|
|
11
|
+
* sessions open, the most recently connected one holds the id; when it closes
|
|
12
|
+
* the id moves back to the most recent one still open. Member ids are UUIDs,
|
|
13
|
+
* so this id cannot collide with a member entry.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ORCHESTRATOR_SESSION_ID = "orchestrator";
|
|
3
16
|
export interface SessionState {
|
|
4
17
|
member_id: string;
|
|
5
18
|
/** HARD security boundary -- every session belongs to exactly one workspace.
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable registry id of the operator's own orchestrating session.
|
|
3
|
+
*
|
|
4
|
+
* A session with no member identity (no member JWT, no ?member=) is the local
|
|
5
|
+
* orchestrator/PM session. When such a session declares the `claude/channel`
|
|
6
|
+
* capability at initialize -- i.e. it can actually receive channel pushes --
|
|
7
|
+
* http-transport registers it under this id in the local workspace, so
|
|
8
|
+
* send_message({ member_id: 'orchestrator' }) reaches it. With several such
|
|
9
|
+
* sessions open, the most recently connected one holds the id; when it closes
|
|
10
|
+
* the id moves back to the most recent one still open. Member ids are UUIDs,
|
|
11
|
+
* so this id cannot collide with a member entry.
|
|
12
|
+
*/
|
|
13
|
+
export const ORCHESTRATOR_SESSION_ID = 'orchestrator';
|
|
1
14
|
/**
|
|
2
15
|
* Session registry keyed on the (workspace_id, member_id) composite.
|
|
3
16
|
* A member_id can never be addressed across a workspace boundary: every
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { SessionRoots } from './tool-scope.js';
|
|
3
|
+
export type { SessionRoots } from './tool-scope.js';
|
|
4
|
+
/** Bound on one roots/list round trip. */
|
|
5
|
+
export declare const ROOTS_FETCH_TIMEOUT_MS = 5000;
|
|
6
|
+
export declare const LenientListRootsResultSchema: z.ZodObject<{
|
|
7
|
+
roots: z.ZodArray<z.ZodObject<{
|
|
8
|
+
uri: z.ZodString;
|
|
9
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
10
|
+
uri: z.ZodString;
|
|
11
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
12
|
+
uri: z.ZodString;
|
|
13
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
14
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
15
|
+
roots: z.ZodArray<z.ZodObject<{
|
|
16
|
+
uri: z.ZodString;
|
|
17
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
18
|
+
uri: z.ZodString;
|
|
19
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
20
|
+
uri: z.ZodString;
|
|
21
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
22
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
23
|
+
roots: z.ZodArray<z.ZodObject<{
|
|
24
|
+
uri: z.ZodString;
|
|
25
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
26
|
+
uri: z.ZodString;
|
|
27
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
28
|
+
uri: z.ZodString;
|
|
29
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
30
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
31
|
+
/** The extra.sendRequest a tool handler receives from the MCP SDK. */
|
|
32
|
+
export type RootsSendRequest = (request: {
|
|
33
|
+
method: 'roots/list';
|
|
34
|
+
params?: Record<string, unknown>;
|
|
35
|
+
}, schema: typeof LenientListRootsResultSchema, options?: {
|
|
36
|
+
timeout?: number;
|
|
37
|
+
}) => Promise<{
|
|
38
|
+
roots: Array<{
|
|
39
|
+
uri: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
}>;
|
|
42
|
+
}>;
|
|
43
|
+
/** Convert a roots/list answer into offered URIs plus the local folders among them. */
|
|
44
|
+
export declare function toSessionRoots(roots: ReadonlyArray<{
|
|
45
|
+
uri: string;
|
|
46
|
+
}>): SessionRoots;
|
|
47
|
+
export declare class SessionRootsCache {
|
|
48
|
+
/** True when the client declared the roots capability at initialize. */
|
|
49
|
+
private readonly clientDeclaresRoots;
|
|
50
|
+
private readonly timeoutMs;
|
|
51
|
+
private snapshot;
|
|
52
|
+
private fetched;
|
|
53
|
+
private generation;
|
|
54
|
+
private inflight;
|
|
55
|
+
constructor(
|
|
56
|
+
/** True when the client declared the roots capability at initialize. */
|
|
57
|
+
clientDeclaresRoots: () => boolean, timeoutMs?: number);
|
|
58
|
+
/** notifications/roots/list_changed: the next get() refetches. */
|
|
59
|
+
invalidate(): void;
|
|
60
|
+
/**
|
|
61
|
+
* The session's roots: undefined when the client lacks the roots capability
|
|
62
|
+
* or returned an empty list ("no roots offered"); `fetchError` set when it
|
|
63
|
+
* declared the capability but could not be asked or the fetch failed.
|
|
64
|
+
*/
|
|
65
|
+
get(sendRequest: RootsSendRequest | undefined): Promise<SessionRoots | undefined>;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=session-roots.d.ts.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Per-session MCP client roots for FULL (non-member) sessions.
|
|
2
|
+
//
|
|
3
|
+
// A FULL session's kb_* and code_* scope comes from the client's roots
|
|
4
|
+
// (MCP roots/list): the first offered root inside a git repository with an
|
|
5
|
+
// origin remote wins (src/services/knowledge/kb-self.ts). The server's working
|
|
6
|
+
// folder is used only when the client offers no roots: it lacks the capability
|
|
7
|
+
// or returns an empty list.
|
|
8
|
+
//
|
|
9
|
+
// Scope resolution is synchronous and runs inside many handlers, so the async
|
|
10
|
+
// roots/list round trip happens here, once per session, and the result is
|
|
11
|
+
// cached:
|
|
12
|
+
//
|
|
13
|
+
// - fetched lazily on the first kb_*/code_* call of the session, through
|
|
14
|
+
// that call's own request context (extra.sendRequest), so the server ->
|
|
15
|
+
// client request rides the call's response stream -- an HTTP client need
|
|
16
|
+
// not hold a standalone GET stream open for it;
|
|
17
|
+
// - only when the client declared the roots capability at initialize;
|
|
18
|
+
// - invalidated on notifications/roots/list_changed (next call refetches);
|
|
19
|
+
// - a failed or timed-out fetch is its own state, not "no roots": it is logged,
|
|
20
|
+
// never cached, and the call is refused (kb-self.ts), so unknown roots can
|
|
21
|
+
// never answer from, or write to, the server's working folder. The next call
|
|
22
|
+
// asks again, so a client that never answers costs one timeout per call.
|
|
23
|
+
//
|
|
24
|
+
// Roots are file:// URIs. Each is converted with fileURLToPath; a root that is
|
|
25
|
+
// not a file URI or does not name an existing directory on THIS host (a remote
|
|
26
|
+
// HTTP client's roots are paths on its own machine, or a path was deleted) is
|
|
27
|
+
// kept in `offered` but left out of `folders`: an unusable root, refused when
|
|
28
|
+
// nothing else is usable.
|
|
29
|
+
import fs from 'node:fs';
|
|
30
|
+
import { fileURLToPath } from 'node:url';
|
|
31
|
+
import { z } from 'zod';
|
|
32
|
+
import { logLine } from '../utils/log-helpers.js';
|
|
33
|
+
/** Bound on one roots/list round trip. */
|
|
34
|
+
export const ROOTS_FETCH_TIMEOUT_MS = 5000;
|
|
35
|
+
// Deliberately looser than the SDK's ListRootsResultSchema, which requires every
|
|
36
|
+
// uri to be file:// and so would reject the whole list over one other root.
|
|
37
|
+
// toSessionRoots skips what is not a local folder.
|
|
38
|
+
export const LenientListRootsResultSchema = z.object({
|
|
39
|
+
roots: z.array(z.object({ uri: z.string() }).passthrough()),
|
|
40
|
+
}).passthrough();
|
|
41
|
+
/** Convert a roots/list answer into offered URIs plus the local folders among them. */
|
|
42
|
+
export function toSessionRoots(roots) {
|
|
43
|
+
const offered = [];
|
|
44
|
+
const folders = [];
|
|
45
|
+
for (const r of roots) {
|
|
46
|
+
if (!r || typeof r.uri !== 'string')
|
|
47
|
+
continue;
|
|
48
|
+
offered.push(r.uri);
|
|
49
|
+
let p;
|
|
50
|
+
try {
|
|
51
|
+
if (!r.uri.startsWith('file:'))
|
|
52
|
+
continue;
|
|
53
|
+
p = fileURLToPath(r.uri);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
if (fs.statSync(p).isDirectory())
|
|
60
|
+
folders.push(p);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// not on this host
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { offered, folders };
|
|
67
|
+
}
|
|
68
|
+
function rootsFetchFailed(fetchError) {
|
|
69
|
+
return { offered: [], folders: [], fetchError };
|
|
70
|
+
}
|
|
71
|
+
export class SessionRootsCache {
|
|
72
|
+
clientDeclaresRoots;
|
|
73
|
+
timeoutMs;
|
|
74
|
+
snapshot;
|
|
75
|
+
fetched = false;
|
|
76
|
+
generation = 0;
|
|
77
|
+
inflight = null;
|
|
78
|
+
constructor(
|
|
79
|
+
/** True when the client declared the roots capability at initialize. */
|
|
80
|
+
clientDeclaresRoots, timeoutMs = ROOTS_FETCH_TIMEOUT_MS) {
|
|
81
|
+
this.clientDeclaresRoots = clientDeclaresRoots;
|
|
82
|
+
this.timeoutMs = timeoutMs;
|
|
83
|
+
}
|
|
84
|
+
/** notifications/roots/list_changed: the next get() refetches. */
|
|
85
|
+
invalidate() {
|
|
86
|
+
this.generation++;
|
|
87
|
+
this.fetched = false;
|
|
88
|
+
this.snapshot = undefined;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The session's roots: undefined when the client lacks the roots capability
|
|
92
|
+
* or returned an empty list ("no roots offered"); `fetchError` set when it
|
|
93
|
+
* declared the capability but could not be asked or the fetch failed.
|
|
94
|
+
*/
|
|
95
|
+
async get(sendRequest) {
|
|
96
|
+
if (!this.clientDeclaresRoots())
|
|
97
|
+
return undefined;
|
|
98
|
+
if (this.fetched)
|
|
99
|
+
return this.snapshot;
|
|
100
|
+
if (typeof sendRequest !== 'function')
|
|
101
|
+
return rootsFetchFailed('the call has no way to ask the client');
|
|
102
|
+
if (!this.inflight) {
|
|
103
|
+
const gen = this.generation;
|
|
104
|
+
this.inflight = (async () => {
|
|
105
|
+
let snap;
|
|
106
|
+
try {
|
|
107
|
+
const res = await sendRequest({ method: 'roots/list' }, LenientListRootsResultSchema, { timeout: this.timeoutMs });
|
|
108
|
+
const s = toSessionRoots(res?.roots ?? []);
|
|
109
|
+
snap = s.offered.length > 0 ? s : undefined;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
113
|
+
logLine('session', `roots/list failed, refusing this call: ${message}`);
|
|
114
|
+
return rootsFetchFailed(message);
|
|
115
|
+
}
|
|
116
|
+
if (gen === this.generation) {
|
|
117
|
+
this.snapshot = snap;
|
|
118
|
+
this.fetched = true;
|
|
119
|
+
}
|
|
120
|
+
return snap;
|
|
121
|
+
})().finally(() => { this.inflight = null; });
|
|
122
|
+
}
|
|
123
|
+
return this.inflight;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=session-roots.js.map
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/** True when a process with this pid exists (EPERM = exists, not ours). */
|
|
2
|
+
export declare function isPidAlive(pid: number): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* True when the persisted status for `agentId` is busy but the server process
|
|
5
|
+
* that wrote it is known to be dead -- a busy no live process can ever clear.
|
|
6
|
+
* A busy with no recorded owner (written before owners were tracked) is not
|
|
7
|
+
* judged here; startup reconciliation handles it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isOrphanedBusy(agentId: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Startup reconciliation: a fresh server holds no in-flight work, so any
|
|
12
|
+
* persisted busy whose owner is missing, dead, or this very pid (reuse) was
|
|
13
|
+
* left by a server that died mid-task. Reset those to idle. Busy entries
|
|
14
|
+
* owned by another live server process are kept. Returns the reset ids.
|
|
15
|
+
*/
|
|
16
|
+
export declare function reconcileStaleBusy(): string[];
|
|
1
17
|
/** Return the last-known status for an agent (defaults to 'idle'). */
|
|
2
18
|
export declare function readMemberStatus(agentId: string): string;
|
|
3
19
|
/**
|
|
@@ -5,6 +21,11 @@ export declare function readMemberStatus(agentId: string): string;
|
|
|
5
21
|
* - Overrides are merged into the persisted state (not a full reset).
|
|
6
22
|
* - Agents not in overrides keep their last-known state.
|
|
7
23
|
* - New agents default to 'idle'.
|
|
24
|
+
*
|
|
25
|
+
* Called with NO overrides it only RE-RENDERS (registry changes: names, icons,
|
|
26
|
+
* added/removed members). It never clears a member's busy -- to end a busy
|
|
27
|
+
* period pass an explicit status, or use markBusy() (member-busy.ts), whose
|
|
28
|
+
* release always writes one.
|
|
8
29
|
*/
|
|
9
30
|
export declare function writeStatusline(overrides?: Map<string, string>): void;
|
|
10
31
|
//# sourceMappingURL=statusline.d.ts.map
|
|
@@ -6,6 +6,11 @@ import { DEFAULT_ICON } from './icons.js';
|
|
|
6
6
|
import { groupByCategory } from '../utils/agent-helpers.js';
|
|
7
7
|
const STATUSLINE_PATH = path.join(FLEET_DIR, 'statusline.txt');
|
|
8
8
|
const STATE_PATH = path.join(FLEET_DIR, 'statusline-state.json');
|
|
9
|
+
// Sidecar: agentId -> pid of the server process that last wrote a busy status
|
|
10
|
+
// for it. Lets a reader tell a live busy from one persisted by a server that
|
|
11
|
+
// has since died (crash/restart mid-task). Kept separate so the state file's
|
|
12
|
+
// Record<string, string> shape is unchanged for its readers.
|
|
13
|
+
const OWNERS_PATH = path.join(FLEET_DIR, 'statusline-owners.json');
|
|
9
14
|
// Status display emoji — keyed on base status (without parenthetical suffix)
|
|
10
15
|
const STATUS_EMOJI = {
|
|
11
16
|
busy: '⚡', idle: '💤', offline: '❌', unknown: '❓',
|
|
@@ -31,6 +36,69 @@ function loadState() {
|
|
|
31
36
|
function saveState(state) {
|
|
32
37
|
fs.writeFileSync(STATE_PATH, JSON.stringify(state), { mode: 0o600 });
|
|
33
38
|
}
|
|
39
|
+
function loadOwners() {
|
|
40
|
+
try {
|
|
41
|
+
if (fs.existsSync(OWNERS_PATH)) {
|
|
42
|
+
return JSON.parse(fs.readFileSync(OWNERS_PATH, 'utf-8'));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch { /* corrupted file, start fresh */ }
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
function saveOwners(owners) {
|
|
49
|
+
fs.writeFileSync(OWNERS_PATH, JSON.stringify(owners), { mode: 0o600 });
|
|
50
|
+
}
|
|
51
|
+
function isBusyStatus(status) {
|
|
52
|
+
return status !== undefined && baseStatus(status) === 'busy';
|
|
53
|
+
}
|
|
54
|
+
/** True when a process with this pid exists (EPERM = exists, not ours). */
|
|
55
|
+
export function isPidAlive(pid) {
|
|
56
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
57
|
+
return false;
|
|
58
|
+
try {
|
|
59
|
+
process.kill(pid, 0);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
return err?.code === 'EPERM';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* True when the persisted status for `agentId` is busy but the server process
|
|
68
|
+
* that wrote it is known to be dead -- a busy no live process can ever clear.
|
|
69
|
+
* A busy with no recorded owner (written before owners were tracked) is not
|
|
70
|
+
* judged here; startup reconciliation handles it.
|
|
71
|
+
*/
|
|
72
|
+
export function isOrphanedBusy(agentId) {
|
|
73
|
+
if (!isBusyStatus(loadState()[agentId]))
|
|
74
|
+
return false;
|
|
75
|
+
const owner = loadOwners()[agentId];
|
|
76
|
+
return owner !== undefined && !isPidAlive(owner);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Startup reconciliation: a fresh server holds no in-flight work, so any
|
|
80
|
+
* persisted busy whose owner is missing, dead, or this very pid (reuse) was
|
|
81
|
+
* left by a server that died mid-task. Reset those to idle. Busy entries
|
|
82
|
+
* owned by another live server process are kept. Returns the reset ids.
|
|
83
|
+
*/
|
|
84
|
+
export function reconcileStaleBusy() {
|
|
85
|
+
try {
|
|
86
|
+
const state = loadState();
|
|
87
|
+
const owners = loadOwners();
|
|
88
|
+
const stale = Object.keys(state).filter(id => {
|
|
89
|
+
if (!isBusyStatus(state[id]))
|
|
90
|
+
return false;
|
|
91
|
+
const owner = owners[id];
|
|
92
|
+
return owner === undefined || owner === process.pid || !isPidAlive(owner);
|
|
93
|
+
});
|
|
94
|
+
if (stale.length > 0)
|
|
95
|
+
writeStatusline(new Map(stale.map(id => [id, 'idle'])));
|
|
96
|
+
return stale;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
34
102
|
/** Return the last-known status for an agent (defaults to 'idle'). */
|
|
35
103
|
export function readMemberStatus(agentId) {
|
|
36
104
|
return loadState()[agentId] ?? 'idle';
|
|
@@ -40,6 +108,11 @@ export function readMemberStatus(agentId) {
|
|
|
40
108
|
* - Overrides are merged into the persisted state (not a full reset).
|
|
41
109
|
* - Agents not in overrides keep their last-known state.
|
|
42
110
|
* - New agents default to 'idle'.
|
|
111
|
+
*
|
|
112
|
+
* Called with NO overrides it only RE-RENDERS (registry changes: names, icons,
|
|
113
|
+
* added/removed members). It never clears a member's busy -- to end a busy
|
|
114
|
+
* period pass an explicit status, or use markBusy() (member-busy.ts), whose
|
|
115
|
+
* release always writes one.
|
|
43
116
|
*/
|
|
44
117
|
export function writeStatusline(overrides) {
|
|
45
118
|
try {
|
|
@@ -53,13 +126,28 @@ export function writeStatusline(overrides) {
|
|
|
53
126
|
if (fs.existsSync(STATE_PATH)) {
|
|
54
127
|
fs.writeFileSync(STATE_PATH, '{}', { mode: 0o600 });
|
|
55
128
|
}
|
|
129
|
+
if (fs.existsSync(OWNERS_PATH))
|
|
130
|
+
saveOwners({});
|
|
56
131
|
return;
|
|
57
132
|
}
|
|
58
133
|
const saved = loadState();
|
|
59
|
-
|
|
134
|
+
const owners = loadOwners();
|
|
135
|
+
let ownersChanged = false;
|
|
136
|
+
// Merge overrides into saved state; a busy write records this process as
|
|
137
|
+
// its owner, any other status drops the owner.
|
|
60
138
|
if (overrides) {
|
|
61
139
|
for (const [id, status] of overrides) {
|
|
62
140
|
saved[id] = status;
|
|
141
|
+
if (isBusyStatus(status)) {
|
|
142
|
+
if (owners[id] !== process.pid) {
|
|
143
|
+
owners[id] = process.pid;
|
|
144
|
+
ownersChanged = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (id in owners) {
|
|
148
|
+
delete owners[id];
|
|
149
|
+
ownersChanged = true;
|
|
150
|
+
}
|
|
63
151
|
}
|
|
64
152
|
}
|
|
65
153
|
// Prune agents no longer in registry
|
|
@@ -68,6 +156,12 @@ export function writeStatusline(overrides) {
|
|
|
68
156
|
if (!agentIds.has(id))
|
|
69
157
|
delete saved[id];
|
|
70
158
|
}
|
|
159
|
+
for (const id of Object.keys(owners)) {
|
|
160
|
+
if (!agentIds.has(id)) {
|
|
161
|
+
delete owners[id];
|
|
162
|
+
ownersChanged = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
71
165
|
const states = agents.map(a => ({
|
|
72
166
|
icon: a.icon ?? DEFAULT_ICON,
|
|
73
167
|
name: a.friendlyName,
|
|
@@ -89,6 +183,8 @@ export function writeStatusline(overrides) {
|
|
|
89
183
|
}
|
|
90
184
|
const line = categoryParts.join(' | ');
|
|
91
185
|
saveState(saved);
|
|
186
|
+
if (ownersChanged)
|
|
187
|
+
saveOwners(owners);
|
|
92
188
|
fs.writeFileSync(STATUSLINE_PATH, line + '\n', { mode: 0o600 });
|
|
93
189
|
}
|
|
94
190
|
catch { /* best-effort, never break tool execution */ }
|
|
@@ -34,6 +34,7 @@ import path from 'node:path';
|
|
|
34
34
|
import os from 'node:os';
|
|
35
35
|
import { execFileSync } from 'node:child_process';
|
|
36
36
|
import { BIN_DIR, WORKFLOWS_DIR } from '../cli/config.js';
|
|
37
|
+
import { windowsExecutable } from '../os/windows-executable.js';
|
|
37
38
|
export const SUPERVISOR_LINUX_UNIT_NAMES = ['fleet-supervisor.service', 'apra-fleet-supervisor.service'];
|
|
38
39
|
export const SUPERVISOR_MACOS_LABEL = 'com.apra-fleet.supervisor';
|
|
39
40
|
export const SUPERVISOR_WINDOWS_TASK_NAME = 'ApraFleetSupervisor';
|
|
@@ -241,7 +242,7 @@ function findWindowsSupervisorPids() {
|
|
|
241
242
|
'ForEach-Object { $_.ProcessId }',
|
|
242
243
|
].join(' | ');
|
|
243
244
|
const encoded = Buffer.from(script, 'utf16le').toString('base64');
|
|
244
|
-
const out = execFileSync('powershell', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], {
|
|
245
|
+
const out = execFileSync(windowsExecutable('powershell.exe'), ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], {
|
|
245
246
|
encoding: 'utf8', ...QUIET,
|
|
246
247
|
});
|
|
247
248
|
return String(out ?? '')
|