@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
|
@@ -40,10 +40,33 @@
|
|
|
40
40
|
|
|
41
41
|
import http from 'node:http';
|
|
42
42
|
import { toBeadsSummary } from './beads-identity.mjs';
|
|
43
|
+
import { checkMutatingRequest, checkRequestHost, parseAllowedHosts } from '@apralabs/apra-fleet-workflow/viewer/request-guard';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Environment variable holding the optional supervisor API token. When set
|
|
47
|
+
* (non-empty), a mutating request carrying `Authorization: Bearer <token>` (or
|
|
48
|
+
* `X-Fleet-Token: <token>`) is admitted even from a cross-site Origin. Unset,
|
|
49
|
+
* only same-origin / Origin-less JSON requests reach a mutating route.
|
|
50
|
+
*/
|
|
51
|
+
export const SUPERVISOR_TOKEN_ENV = 'FLEET_SUPERVISOR_TOKEN';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Env var listing extra Host names (comma/space separated) the supervisor
|
|
55
|
+
* answers to, beyond loopback names, IP literals and its --host. Needed only
|
|
56
|
+
* for an off-box bind reached by DNS name (DNS-rebinding defence, see
|
|
57
|
+
* request-guard.mjs checkRequestHost()).
|
|
58
|
+
*/
|
|
59
|
+
export const SUPERVISOR_ALLOWED_HOSTS_ENV = 'FLEET_SUPERVISOR_ALLOWED_HOSTS';
|
|
43
60
|
|
|
44
61
|
/** Default HTTP service port for the always-on supervisor. */
|
|
45
62
|
export const DEFAULT_SERVICE_PORT = 8787;
|
|
46
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Default bind host: loopback only. Off-box exposure is an explicit opt-in via
|
|
66
|
+
* the `host` dep (`fleet-se serve --host <addr>`).
|
|
67
|
+
*/
|
|
68
|
+
export const DEFAULT_SERVICE_HOST = '127.0.0.1';
|
|
69
|
+
|
|
47
70
|
/**
|
|
48
71
|
* An inert seam stub. Later eft tasks pass real implementations; until then the
|
|
49
72
|
* supervisor boots against these no-ops so `fleet-se serve` is independently
|
|
@@ -96,6 +119,47 @@ export function readJsonBody(req, opts = {}) {
|
|
|
96
119
|
});
|
|
97
120
|
}
|
|
98
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Cuts stack-frame lines out of an error message. Linear: one pass over the
|
|
124
|
+
* lines, no regex over the whole string. A frame line is one that starts with
|
|
125
|
+
* "at " and looks like a frame (has "(" or a .js/.mjs/.ts file:line location).
|
|
126
|
+
* Everything from the first frame line onward is dropped.
|
|
127
|
+
* @param {any} v an Error, string or other value
|
|
128
|
+
* @returns {string}
|
|
129
|
+
*/
|
|
130
|
+
export function messageWithoutStack(v) {
|
|
131
|
+
const text = v instanceof Error ? v.message : typeof v === 'string' ? v : String(v);
|
|
132
|
+
let start = 0;
|
|
133
|
+
while (start <= text.length) {
|
|
134
|
+
let end = text.indexOf('\n', start);
|
|
135
|
+
if (end === -1) end = text.length;
|
|
136
|
+
const line = text.slice(start, end).trim();
|
|
137
|
+
if (line.startsWith('at ') && (line.includes('(') || /\.(?:mjs|cjs|js|ts):\d/.test(line))) {
|
|
138
|
+
return text.slice(0, start).trimEnd();
|
|
139
|
+
}
|
|
140
|
+
start = end + 1;
|
|
141
|
+
}
|
|
142
|
+
return text;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Error responses (status >= 400) must carry a message only, never a stack
|
|
147
|
+
* trace: the `error` field is reduced to its message and any `stack` key is
|
|
148
|
+
* dropped. Success payloads are never touched.
|
|
149
|
+
* @param {any} payload
|
|
150
|
+
*/
|
|
151
|
+
function sanitizeErrorPayload(payload) {
|
|
152
|
+
if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return payload;
|
|
153
|
+
const out = { ...payload };
|
|
154
|
+
delete out.stack;
|
|
155
|
+
if ('error' in out && out.error !== undefined && out.error !== null && typeof out.error !== 'object') {
|
|
156
|
+
out.error = messageWithoutStack(out.error);
|
|
157
|
+
} else if (out.error instanceof Error) {
|
|
158
|
+
out.error = messageWithoutStack(out.error);
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
|
|
99
163
|
/**
|
|
100
164
|
* Writes a JSON response. Centralized so every handler (and the error-isolation
|
|
101
165
|
* wrapper) emits a consistent shape.
|
|
@@ -104,7 +168,7 @@ export function readJsonBody(req, opts = {}) {
|
|
|
104
168
|
* @param {any} payload
|
|
105
169
|
*/
|
|
106
170
|
export function sendJson(res, status, payload) {
|
|
107
|
-
const body = JSON.stringify(payload ?? {});
|
|
171
|
+
const body = JSON.stringify((status >= 400 ? sanitizeErrorPayload(payload) : payload) ?? {});
|
|
108
172
|
res.writeHead(status, {
|
|
109
173
|
'content-type': 'application/json; charset=utf-8',
|
|
110
174
|
'content-length': Buffer.byteLength(body),
|
|
@@ -127,7 +191,18 @@ export function sendJson(res, status, payload) {
|
|
|
127
191
|
* backlogMember?: { get: () => { member: object|null, status: string, reason: string|null } },
|
|
128
192
|
* logger?: { log?: Function, error?: Function },
|
|
129
193
|
* createServer?: (handler: (req: any, res: any) => void) => import('http').Server,
|
|
194
|
+
* apiToken?: string|null,
|
|
195
|
+
* host?: string,
|
|
196
|
+
* allowedHosts?: string[]|string|null,
|
|
130
197
|
* }} [deps]
|
|
198
|
+
*
|
|
199
|
+
* `apiToken`: the token that admits a cross-site mutating request (see
|
|
200
|
+
* request-guard.mjs). Defaults to process.env[SUPERVISOR_TOKEN_ENV]; pass null
|
|
201
|
+
* to disable the token mechanism explicitly.
|
|
202
|
+
*
|
|
203
|
+
* `allowedHosts`: extra Host header names admitted besides loopback names, IP
|
|
204
|
+
* literals and `host` itself (DNS-rebinding defence). Defaults to
|
|
205
|
+
* process.env[SUPERVISOR_ALLOWED_HOSTS_ENV].
|
|
131
206
|
* @returns {{
|
|
132
207
|
* route(method: string, path: string, handler: Function): void,
|
|
133
208
|
* start(): Promise<{ port: number }>,
|
|
@@ -140,6 +215,9 @@ export function sendJson(res, status, payload) {
|
|
|
140
215
|
*/
|
|
141
216
|
export function createSupervisor(deps = {}) {
|
|
142
217
|
let port = Number.isInteger(deps.port) ? deps.port : DEFAULT_SERVICE_PORT;
|
|
218
|
+
const apiToken = deps.apiToken !== undefined ? deps.apiToken : (process.env[SUPERVISOR_TOKEN_ENV] || null);
|
|
219
|
+
const host = (typeof deps.host === 'string' && deps.host) ? deps.host : DEFAULT_SERVICE_HOST;
|
|
220
|
+
const allowedHosts = parseAllowedHosts(deps.allowedHosts !== undefined ? deps.allowedHosts : process.env[SUPERVISOR_ALLOWED_HOSTS_ENV]);
|
|
143
221
|
const logger = deps.logger ?? console;
|
|
144
222
|
const log = (...a) => logger.log?.(...a);
|
|
145
223
|
const logError = (...a) => (logger.error ?? logger.log)?.(...a);
|
|
@@ -248,6 +326,23 @@ export function createSupervisor(deps = {}) {
|
|
|
248
326
|
const path = url.pathname;
|
|
249
327
|
|
|
250
328
|
try {
|
|
329
|
+
// Cross-site request forgery guard: every mutating (non-GET/HEAD/
|
|
330
|
+
// OPTIONS) request must be JSON and same-origin (or carry the
|
|
331
|
+
// configured token) BEFORE any route handler runs -- one check here
|
|
332
|
+
// covers every route registered through route(), including those
|
|
333
|
+
// added by api.mjs, reconcile.mjs, proxy.mjs, the dolt mutex and
|
|
334
|
+
// the id allocator.
|
|
335
|
+
//
|
|
336
|
+
// The Host header is checked on EVERY request first (GET too): a
|
|
337
|
+
// DNS-rebound page controls both Origin and Host, so an origin
|
|
338
|
+
// comparison alone admits it, and it could also read GET routes.
|
|
339
|
+
const guardOpts = { token: apiToken, bindHost: host, allowedHosts, allowedHostsHint: `start the supervisor with --allowed-host <name> or set ${SUPERVISOR_ALLOWED_HOSTS_ENV}=<name>` };
|
|
340
|
+
const refused = checkRequestHost(req, guardOpts) || checkMutatingRequest(req, guardOpts);
|
|
341
|
+
if (refused) {
|
|
342
|
+
if (typeof req.resume === 'function') req.resume();
|
|
343
|
+
sendJson(res, refused.status, { error: refused.error });
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
251
346
|
const handler = routes.get(routeKey(method, path));
|
|
252
347
|
if (handler) {
|
|
253
348
|
await handler(req, res, { url, params: {} });
|
|
@@ -317,6 +412,41 @@ export function createSupervisor(deps = {}) {
|
|
|
317
412
|
setImmediate(() => { stop('http:/api/shutdown').catch((e) => logError(e)); });
|
|
318
413
|
});
|
|
319
414
|
|
|
415
|
+
// Shutdown bounds. A seam whose stop() never settles (or an SSE/keep-alive
|
|
416
|
+
// connection that keeps server.close() from completing) must not keep the
|
|
417
|
+
// process alive: each seam gets its own bound, and a forced exit fires a
|
|
418
|
+
// fixed time after shutdown starts (unref'd, so it never itself holds the
|
|
419
|
+
// process open). forcedExitMs 0 disables the forced exit (library/tests).
|
|
420
|
+
const seamStopTimeoutMs = Number.isFinite(deps.seamStopTimeoutMs) && deps.seamStopTimeoutMs > 0 ? deps.seamStopTimeoutMs : 3000;
|
|
421
|
+
const forcedExitMs = Number.isFinite(deps.forcedExitMs) && deps.forcedExitMs > 0 ? deps.forcedExitMs : 0;
|
|
422
|
+
const exitFn = deps.exit ?? ((code) => process.exit(code));
|
|
423
|
+
/** @type {string[]} */
|
|
424
|
+
const hungSeams = [];
|
|
425
|
+
|
|
426
|
+
/** Resolves 'done' | 'timeout' | 'error'; never rejects, never hangs past ms. */
|
|
427
|
+
function boundedStop(name, fn, ms) {
|
|
428
|
+
return new Promise((resolve) => {
|
|
429
|
+
let settled = false;
|
|
430
|
+
const timer = setTimeout(() => {
|
|
431
|
+
if (settled) return;
|
|
432
|
+
settled = true;
|
|
433
|
+
hungSeams.push(name);
|
|
434
|
+
logError(`[supervisor] shutdown: ${name} did not stop within ${ms}ms (hung); continuing without it`);
|
|
435
|
+
resolve('timeout');
|
|
436
|
+
}, ms);
|
|
437
|
+
Promise.resolve().then(fn).then(
|
|
438
|
+
() => { if (!settled) { settled = true; clearTimeout(timer); resolve('done'); } },
|
|
439
|
+
(err) => {
|
|
440
|
+
if (settled) return;
|
|
441
|
+
settled = true;
|
|
442
|
+
clearTimeout(timer);
|
|
443
|
+
logError(`[supervisor] seam ${name} stop failed:`, err);
|
|
444
|
+
resolve('error');
|
|
445
|
+
},
|
|
446
|
+
);
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
|
|
320
450
|
let stopping = null;
|
|
321
451
|
/**
|
|
322
452
|
* Idempotent teardown: close the HTTP server and stop every seam, then
|
|
@@ -327,14 +457,25 @@ export function createSupervisor(deps = {}) {
|
|
|
327
457
|
if (stopping) return stopping;
|
|
328
458
|
stopping = (async () => {
|
|
329
459
|
log(`[supervisor] shutting down (${reason})`);
|
|
330
|
-
|
|
460
|
+
if (forcedExitMs > 0) {
|
|
461
|
+
const forced = setTimeout(() => {
|
|
462
|
+
logError(`[supervisor] shutdown did not complete within ${forcedExitMs}ms; forcing exit. Hung: ${hungSeams.length ? hungSeams.join(', ') : '(none recorded; still stopping a seam or closing the http server)'}`);
|
|
463
|
+
exitFn(0);
|
|
464
|
+
}, forcedExitMs);
|
|
465
|
+
if (typeof forced.unref === 'function') forced.unref();
|
|
466
|
+
}
|
|
467
|
+
await boundedStop('http-server', () => new Promise((resolve) => {
|
|
331
468
|
if (!server || !server.listening) { resolve(); return; }
|
|
332
469
|
server.close(() => resolve());
|
|
333
|
-
|
|
470
|
+
// Long-lived SSE / keep-alive connections would otherwise keep
|
|
471
|
+
// close() from ever completing.
|
|
472
|
+
if (typeof server.closeAllConnections === 'function') server.closeAllConnections();
|
|
473
|
+
}), seamStopTimeoutMs);
|
|
334
474
|
// Stop seams in reverse of a natural start order; isolate each so
|
|
335
|
-
// one failing seam cannot block the others' teardown.
|
|
336
|
-
|
|
337
|
-
|
|
475
|
+
// one failing or hung seam cannot block the others' teardown.
|
|
476
|
+
const ordered = [['doltOrphanSweep', seams.doltOrphanSweep], ['idAllocator', seams.idAllocator], ['doltMutex', seams.doltMutex], ['dashboard', seams.dashboard], ['watchdog', seams.watchdog], ['spawner', seams.spawner], ['ledger', seams.ledger]];
|
|
477
|
+
for (const [key, seam] of ordered) {
|
|
478
|
+
await boundedStop(seam.name ?? key, () => seam.stop?.(), seamStopTimeoutMs);
|
|
338
479
|
}
|
|
339
480
|
shutdownResolve();
|
|
340
481
|
})();
|
|
@@ -366,7 +507,7 @@ export function createSupervisor(deps = {}) {
|
|
|
366
507
|
};
|
|
367
508
|
server.once('error', onError);
|
|
368
509
|
server.once('listening', onListening);
|
|
369
|
-
server.listen(port);
|
|
510
|
+
server.listen(port, host);
|
|
370
511
|
});
|
|
371
512
|
|
|
372
513
|
// port:0 asks the OS to pick a free port; reflect the port it
|
|
@@ -381,7 +522,7 @@ export function createSupervisor(deps = {}) {
|
|
|
381
522
|
// process; log and keep serving.
|
|
382
523
|
server.on('error', (err) => logError('[supervisor] server error:', err));
|
|
383
524
|
|
|
384
|
-
log(`[supervisor] listening on http
|
|
525
|
+
log(`[supervisor] listening on http://${host === '0.0.0.0' || host === '::' ? '127.0.0.1' : host}:${port} (pid ${process.pid})`);
|
|
385
526
|
return { port };
|
|
386
527
|
}
|
|
387
528
|
|
|
@@ -395,5 +536,7 @@ export function createSupervisor(deps = {}) {
|
|
|
395
536
|
get port() { return port; },
|
|
396
537
|
/** Resolves once the supervisor has fully shut down. */
|
|
397
538
|
get shutdownRequested() { return shutdownRequested; },
|
|
539
|
+
/** Names of seams whose stop() exceeded its bound during shutdown. */
|
|
540
|
+
get hungSeams() { return [...hungSeams]; },
|
|
398
541
|
};
|
|
399
542
|
}
|
|
@@ -121,13 +121,12 @@ export function defaultCliPath(deps = {}) {
|
|
|
121
121
|
* real OS-level availability, not just what this supervisor process itself
|
|
122
122
|
* has handed out.
|
|
123
123
|
*
|
|
124
|
-
* The real viewer
|
|
125
|
-
* host
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* process, and inbound connections would silently split between the two.
|
|
124
|
+
* The real viewer and the supervisor both bind loopback (127.0.0.1) by
|
|
125
|
+
* default, so a bind test on the same host reliably conflicts with them. The
|
|
126
|
+
* connect probe remains because it also detects a FOREIGN process that owns
|
|
127
|
+
* the port -- e.g. one bound to the wildcard address, which on Windows can
|
|
128
|
+
* coexist with a loopback-only bind on the same port without either side
|
|
129
|
+
* erroring, splitting inbound connections between the two.
|
|
131
130
|
*
|
|
132
131
|
* This is deliberately NOT fixed by making the probe itself bind the
|
|
133
132
|
* wildcard address: doing so opens this process up to inbound connections
|
|
@@ -208,13 +207,14 @@ export async function allocateFreePort(opts = {}) {
|
|
|
208
207
|
* goal?: string, maxCycles?: number|string, allowMissingMembers?: boolean,
|
|
209
208
|
* requirementsFile?: string, roleMap?: object|string, budget?: number|string,
|
|
210
209
|
* viewerPort: number, serviceUrl?: string, runId?: string, expectBeads?: string,
|
|
211
|
-
* extraArgs?: string[], skipRegression?: boolean,
|
|
210
|
+
* extraArgs?: string[], skipRegression?: boolean, kbDemotionLoop?: 'on'|'off',
|
|
211
|
+
* decisionNotify?: string|object,
|
|
212
212
|
* }} opts
|
|
213
213
|
* @returns {string[]}
|
|
214
214
|
*/
|
|
215
215
|
export function buildSprintArgv(opts = {}) {
|
|
216
216
|
const { issue, members, branch, base, goal, maxCycles, allowMissingMembers,
|
|
217
|
-
requirementsFile, roleMap, budget, viewerPort, serviceUrl, runId, expectBeads, extraArgs, skipRegression } = opts;
|
|
217
|
+
requirementsFile, roleMap, budget, viewerPort, serviceUrl, runId, expectBeads, extraArgs, skipRegression, kbDemotionLoop, decisionNotify } = opts;
|
|
218
218
|
|
|
219
219
|
if (!issue || !members || !branch || !base) {
|
|
220
220
|
throw new Error('buildSprintArgv requires issue, members, branch, and base');
|
|
@@ -239,6 +239,8 @@ export function buildSprintArgv(opts = {}) {
|
|
|
239
239
|
}
|
|
240
240
|
if (budget !== undefined) args.push('--budget', String(budget));
|
|
241
241
|
if (skipRegression === true) args.push('--skip-regression');
|
|
242
|
+
if (kbDemotionLoop !== undefined) args.push('--kb-demotion-loop', kbDemotionLoop);
|
|
243
|
+
if (decisionNotify !== undefined) args.push('--decision-notify', typeof decisionNotify === 'string' ? decisionNotify : JSON.stringify(decisionNotify));
|
|
242
244
|
// apra-fleet-f34.1: when this supervisor instance has a known --service-url
|
|
243
245
|
// (its own HTTP listen address, wired in from createSpawner()'s deps.serviceUrl
|
|
244
246
|
// below), forward it so the spawned cli.mjs child threads it into
|
|
@@ -446,6 +446,9 @@ export function formatFinishedDetail(state) {
|
|
|
446
446
|
const parts = [];
|
|
447
447
|
if (terminalReason) parts.push(`terminalReason=${terminalReason}`);
|
|
448
448
|
if (verdict) parts.push(`verdict=${verdict}`);
|
|
449
|
+
const rs = state.result && typeof state.result === 'object' ? state.result : null;
|
|
450
|
+
if (rs && rs.status === 'success-with-warnings') parts.push('status=success-with-warnings');
|
|
451
|
+
if (rs && Array.isArray(rs.warnings) && rs.warnings.length > 0) parts.push(`warnings=${rs.warnings.join('; ')}`);
|
|
449
452
|
return parts.length > 0 ? parts.join(' ') : 'finished';
|
|
450
453
|
}
|
|
451
454
|
|
|
@@ -469,7 +472,10 @@ export function defaultRecordFinished({ sprintId, state, logger, history }) {
|
|
|
469
472
|
const terminalReason = (state && typeof state === 'object' && state.terminalReason) || null;
|
|
470
473
|
const verdict = (state && typeof state === 'object' && state?.extensions?.terminal?.verdict) || null;
|
|
471
474
|
try {
|
|
472
|
-
const
|
|
475
|
+
const rs = state && typeof state === 'object' && state.result && typeof state.result === 'object' ? state.result : null;
|
|
476
|
+
const resultStatus = rs && typeof rs.status === 'string' ? rs.status : null;
|
|
477
|
+
const warnings = rs && Array.isArray(rs.warnings) ? rs.warnings : [];
|
|
478
|
+
const result = history.record({ sprintId, event: HISTORY_EVENTS.FINISHED, terminalReason, verdict, resultStatus, warnings });
|
|
473
479
|
// history.record() is async; a rejection must never take the
|
|
474
480
|
// classifier down with it (same discipline as recordTerminalError
|
|
475
481
|
// below), so it is observed but not awaited by the caller.
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"./viewer/run-state-paths": "./src/viewer/run-state-paths.mjs",
|
|
16
16
|
"./viewer/sprint-state-paths": "./src/viewer/sprint-state-paths.mjs",
|
|
17
17
|
"./viewer/debounced-writer": "./src/viewer/debounced-writer.mjs",
|
|
18
|
-
"./viewer/lean-state": "./src/viewer/lean-state.mjs"
|
|
18
|
+
"./viewer/lean-state": "./src/viewer/lean-state.mjs",
|
|
19
|
+
"./viewer/request-guard": "./src/viewer/request-guard.mjs"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
22
|
"test": "node ../../scripts/with-test-sandbox.mjs node --test --test-timeout=60000 test/*.test.mjs"
|
|
@@ -10,6 +10,7 @@ import { capCommandActivityMeta, getFullOutput } from './command-output-cap.mjs'
|
|
|
10
10
|
import { buildRunTitle } from './run-title.mjs';
|
|
11
11
|
import { billedTokens } from '../workflow/pricing.mjs';
|
|
12
12
|
import { createRunSummary, refreshSummaryCore, applyExtensionSummary, backfillExtensionSummaries } from './run-summary.mjs';
|
|
13
|
+
import { checkMutatingRequest, checkRequestHost } from './request-guard.mjs';
|
|
13
14
|
|
|
14
15
|
// apra-fleet-eft.6.5: the SAME template serves both the live view and the
|
|
15
16
|
// process-free History view -- `opts.history` (true) feeds a FROZEN state
|
|
@@ -73,6 +74,9 @@ const HTML_TEMPLATE = (dashboardExtensions, opts = {}) => {
|
|
|
73
74
|
/* (apra-fleet-p2to.2.1) 'paused since <ts>' badge + reason card,
|
|
74
75
|
generic to every workflow run -- no per-workflow-type styling. */
|
|
75
76
|
.pause-banner { background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.4); color: var(--warning); }
|
|
77
|
+
/* Header-level extension banner slots (see the markup below the header). */
|
|
78
|
+
.extension-banners { flex-shrink: 0; }
|
|
79
|
+
.extension-banner { max-height: 45vh; overflow-y: auto; }
|
|
76
80
|
|
|
77
81
|
/* min-height: 0 on every rung of the flex chain: a flex item's default
|
|
78
82
|
min-height is content-sized, which lets a tall Activity list push the
|
|
@@ -225,6 +229,13 @@ const HTML_TEMPLATE = (dashboardExtensions, opts = {}) => {
|
|
|
225
229
|
${isHistory ? '' : '<button class="btn btn-stop" onclick="stopWorkflow()">Stop</button>'}
|
|
226
230
|
</div>
|
|
227
231
|
</div>
|
|
232
|
+
<!-- Header-level banner slot per dashboard extension: OUTSIDE every tab
|
|
233
|
+
panel, so whatever an extension renders here stays visible whichever
|
|
234
|
+
tab is active (e.g. a run-wide notice that needs the operator's
|
|
235
|
+
attention). Core never fills or shows these; the extension's own js
|
|
236
|
+
does (document.getElementById('extension-banner-' + id)). Live view
|
|
237
|
+
only, like the pause banner: a finished run has nothing to act on. -->
|
|
238
|
+
${isHistory ? '' : `<div class="extension-banners" id="extension-banners">${dashboardExtensions.map(ext => `<div id="extension-banner-${ext.id}" class="extension-banner" style="display: none;"></div>`).join('')}</div>`}
|
|
228
239
|
${isHistory ? '' : `<div class="modal-overlay" id="stop-modal-overlay">
|
|
229
240
|
<div class="modal-box">
|
|
230
241
|
<p>Are you sure you want to forcibly stop the workflow?</p>
|
|
@@ -362,7 +373,7 @@ const HTML_TEMPLATE = (dashboardExtensions, opts = {}) => {
|
|
|
362
373
|
|
|
363
374
|
async function confirmStopWorkflow() {
|
|
364
375
|
closeStopModal();
|
|
365
|
-
await fetch('/stop', { method: 'POST' });
|
|
376
|
+
await fetch('/stop', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
|
|
366
377
|
showStopToast();
|
|
367
378
|
}
|
|
368
379
|
|
|
@@ -378,10 +389,10 @@ const HTML_TEMPLATE = (dashboardExtensions, opts = {}) => {
|
|
|
378
389
|
// tick, below. That keeps the button truthful about what the engine has
|
|
379
390
|
// ACTUALLY done rather than what the browser merely asked for.
|
|
380
391
|
async function pauseWorkflow() {
|
|
381
|
-
await fetch('/pause', { method: 'POST' });
|
|
392
|
+
await fetch('/pause', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
|
|
382
393
|
}
|
|
383
394
|
async function resumeWorkflow() {
|
|
384
|
-
await fetch('/resume', { method: 'POST' });
|
|
395
|
+
await fetch('/resume', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
|
|
385
396
|
}
|
|
386
397
|
|
|
387
398
|
|
|
@@ -974,6 +985,9 @@ const HTML_TEMPLATE = (dashboardExtensions, opts = {}) => {
|
|
|
974
985
|
// module). Reads from the LIVE, full-fidelity in-memory `state.tree` (never
|
|
975
986
|
// the leaned /state payload), which is where an uncapped activity's complete
|
|
976
987
|
// output/error text still lives.
|
|
988
|
+
// Upper bound on a POST /extensions/:extId/actions/:actionId request body.
|
|
989
|
+
const ACTION_BODY_MAX_BYTES = 64 * 1024;
|
|
990
|
+
|
|
977
991
|
// True for GET /state?summary=1 (any extra query params, e.g. a _t
|
|
978
992
|
// cache-buster, allowed); false for plain /state and /state?_t=....
|
|
979
993
|
function isSummaryRequest(url) {
|
|
@@ -1009,6 +1023,11 @@ export { HTML_TEMPLATE };
|
|
|
1009
1023
|
* @param {import('../workflow/index.mjs').FleetWorkflow} workflow
|
|
1010
1024
|
* @param {Object} opts - Options object
|
|
1011
1025
|
* @param {number} [opts.port=8080] - HTTP server port
|
|
1026
|
+
* @param {string} [opts.host='127.0.0.1'] - Interface to bind. Loopback by default; pass '0.0.0.0' (or a
|
|
1027
|
+
* specific address) to expose the dashboard off-box -- an explicit opt-in.
|
|
1028
|
+
* @param {string[]|string} [opts.allowedHosts] - Extra Host header names this server answers to. Loopback
|
|
1029
|
+
* names, IP literals and `host` are always accepted; any other name is refused on every request
|
|
1030
|
+
* (DNS-rebinding defence, request-guard.mjs checkRequestHost()).
|
|
1012
1031
|
* @param {string} [opts.runId] - Stable per-run identifier (generated if not provided)
|
|
1013
1032
|
* @param {string} [opts.name] - Workflow display name
|
|
1014
1033
|
* @param {string} [opts.debouncedStatePath] - Path to write state JSON (uses default if not provided)
|
|
@@ -1023,6 +1042,7 @@ export { HTML_TEMPLATE };
|
|
|
1023
1042
|
*/
|
|
1024
1043
|
export function createDashboardViewer(workflow, opts = {}) {
|
|
1025
1044
|
const port = (typeof opts.port === 'number') ? opts.port : 8080;
|
|
1045
|
+
const host = (typeof opts.host === 'string' && opts.host) ? opts.host : '127.0.0.1';
|
|
1026
1046
|
const dashboardExtensions = opts.dashboardExtensions || [];
|
|
1027
1047
|
|
|
1028
1048
|
// apra-fleet-eft.2.3 (renamed under eft.37.1): stable per-run id, NOT an
|
|
@@ -1451,6 +1471,21 @@ export function createDashboardViewer(workflow, opts = {}) {
|
|
|
1451
1471
|
});
|
|
1452
1472
|
|
|
1453
1473
|
const server = http.createServer((req, res) => {
|
|
1474
|
+
// Cross-site request forgery guard (request-guard.mjs): this server
|
|
1475
|
+
// listens on a loopback port any visited web page could POST to, and
|
|
1476
|
+
// its POST routes stop/pause the run or record an operator answer. A
|
|
1477
|
+
// mutating request must be JSON and same-origin (no Origin: the
|
|
1478
|
+
// supervisor's proxy and HTTP clients; or this page's own origin).
|
|
1479
|
+
// The Host header is checked on EVERY request (GET /state included):
|
|
1480
|
+
// a DNS-rebound page controls Origin and Host alike.
|
|
1481
|
+
const hostOpts = { bindHost: host, allowedHosts: opts.allowedHosts };
|
|
1482
|
+
const refused = checkRequestHost(req, hostOpts) || checkMutatingRequest(req, hostOpts);
|
|
1483
|
+
if (refused) {
|
|
1484
|
+
if (typeof req.resume === 'function') req.resume();
|
|
1485
|
+
res.writeHead(refused.status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
1486
|
+
res.end(JSON.stringify({ error: refused.error }));
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1454
1489
|
if (req.url === '/') {
|
|
1455
1490
|
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
1456
1491
|
res.end(HTML_TEMPLATE(dashboardExtensions));
|
|
@@ -1512,6 +1547,50 @@ export function createDashboardViewer(workflow, opts = {}) {
|
|
|
1512
1547
|
text: detail.text || '',
|
|
1513
1548
|
updatedAt: detail.updatedAt ?? null
|
|
1514
1549
|
}));
|
|
1550
|
+
} else if (req.method === 'POST' && /^\/extensions\/[^/]+\/actions\/[^/]+$/.test(req.url)) {
|
|
1551
|
+
// GENERIC extension action route (mirrors the detail route above):
|
|
1552
|
+
// an extension may register `actions: { <actionId>(ctx) }`, where
|
|
1553
|
+
// ctx = { body, state } with `body` the parsed JSON request body
|
|
1554
|
+
// (bounded to ACTION_BODY_MAX_BYTES). The action returns
|
|
1555
|
+
// { status?, body? } (sync or async). Core never names a specific
|
|
1556
|
+
// extension or action; an unknown extension/action is a 404, a
|
|
1557
|
+
// malformed or oversized body a 400, a throwing action a 500.
|
|
1558
|
+
const match = req.url.match(/^\/extensions\/([^/]+)\/actions\/([^/]+)$/);
|
|
1559
|
+
const extId = decodeURIComponent(match[1]);
|
|
1560
|
+
const actionId = decodeURIComponent(match[2]);
|
|
1561
|
+
const ext = dashboardExtensions.find((e) => e.id === extId);
|
|
1562
|
+
const action = ext && ext.actions && Object.prototype.hasOwnProperty.call(ext.actions, actionId) ? ext.actions[actionId] : null;
|
|
1563
|
+
const reply = (status, body) => {
|
|
1564
|
+
res.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
1565
|
+
res.end(JSON.stringify(body));
|
|
1566
|
+
};
|
|
1567
|
+
if (typeof action !== 'function') {
|
|
1568
|
+
reply(404, { error: 'action not found', extension: extId, action: actionId });
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
const chunks = [];
|
|
1572
|
+
let size = 0;
|
|
1573
|
+
let tooBig = false;
|
|
1574
|
+
req.on('data', (c) => {
|
|
1575
|
+
size += c.length;
|
|
1576
|
+
if (size > ACTION_BODY_MAX_BYTES) { tooBig = true; return; }
|
|
1577
|
+
chunks.push(c);
|
|
1578
|
+
});
|
|
1579
|
+
req.on('end', async () => {
|
|
1580
|
+
if (tooBig) { reply(400, { error: 'request body too large' }); return; }
|
|
1581
|
+
let body = {};
|
|
1582
|
+
const raw = Buffer.concat(chunks).toString('utf-8');
|
|
1583
|
+
if (raw.trim()) {
|
|
1584
|
+
try { body = JSON.parse(raw); } catch { reply(400, { error: 'request body is not valid JSON' }); return; }
|
|
1585
|
+
}
|
|
1586
|
+
try {
|
|
1587
|
+
const out = (await action({ body, state })) || {};
|
|
1588
|
+
reply(Number.isInteger(out.status) ? out.status : 200, out.body === undefined ? {} : out.body);
|
|
1589
|
+
} catch (err) {
|
|
1590
|
+
console.error('[Viewer] extension action failed:', err && err.message ? err.message : err);
|
|
1591
|
+
reply(500, { error: 'action failed' });
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1515
1594
|
} else if (req.method === 'GET' && /^\/beads\/[^/]+\/description$/.test(req.url)) {
|
|
1516
1595
|
// BOUNDARY-COMPAT (apra-fleet-eft.37.4, one release only, then
|
|
1517
1596
|
// dies per docs/workflow-core-boundary-refactoring.md M3): the
|
|
@@ -1649,8 +1728,10 @@ export function createDashboardViewer(workflow, opts = {}) {
|
|
|
1649
1728
|
}
|
|
1650
1729
|
});
|
|
1651
1730
|
|
|
1652
|
-
server.listen(port, () => {
|
|
1653
|
-
|
|
1731
|
+
server.listen(port, host, () => {
|
|
1732
|
+
const bound = server.address();
|
|
1733
|
+
const shown = (bound.address === '0.0.0.0' || bound.address === '::') ? '127.0.0.1' : bound.address;
|
|
1734
|
+
console.log(`[Viewer] Workflow Dashboard live at http://${shown}:${bound.port}`);
|
|
1654
1735
|
});
|
|
1655
1736
|
|
|
1656
1737
|
workflow.on('end', () => {
|