@tt-a1i/hive 1.4.3 → 1.5.0
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/CHANGELOG.md +44 -0
- package/README.en.md +5 -4
- package/README.md +9 -1
- package/assets/qq-group.jpg +0 -0
- package/dist/bin/team.cmd +1 -0
- package/dist/src/cli/hive-update.d.ts +57 -0
- package/dist/src/cli/hive-update.js +92 -15
- package/dist/src/cli/hive.d.ts +57 -0
- package/dist/src/cli/hive.js +113 -20
- package/dist/src/cli/team.d.ts +1 -0
- package/dist/src/cli/team.js +215 -7
- package/dist/src/server/agent-command-resolver.d.ts +10 -1
- package/dist/src/server/agent-command-resolver.js +32 -4
- package/dist/src/server/agent-launch-resolver.js +9 -3
- package/dist/src/server/agent-manager-support.d.ts +28 -0
- package/dist/src/server/agent-manager-support.js +138 -10
- package/dist/src/server/agent-run-bootstrap.d.ts +17 -1
- package/dist/src/server/agent-run-bootstrap.js +30 -2
- package/dist/src/server/agent-run-starter.d.ts +7 -1
- package/dist/src/server/agent-run-starter.js +9 -2
- package/dist/src/server/agent-run-store.d.ts +1 -1
- package/dist/src/server/agent-runtime-close.d.ts +1 -0
- package/dist/src/server/agent-runtime-close.js +25 -1
- package/dist/src/server/agent-runtime-contract.d.ts +2 -1
- package/dist/src/server/agent-runtime.d.ts +1 -1
- package/dist/src/server/agent-runtime.js +8 -2
- package/dist/src/server/agent-startup-instructions.d.ts +8 -1
- package/dist/src/server/agent-startup-instructions.js +15 -9
- package/dist/src/server/agent-stdin-dispatcher.d.ts +12 -5
- package/dist/src/server/agent-stdin-dispatcher.js +129 -40
- package/dist/src/server/app.d.ts +1 -0
- package/dist/src/server/app.js +12 -2
- package/dist/src/server/cron-util.d.ts +7 -0
- package/dist/src/server/cron-util.js +19 -0
- package/dist/src/server/dispatch-ledger-store.d.ts +22 -0
- package/dist/src/server/dispatch-ledger-store.js +51 -3
- package/dist/src/server/env-sync-message.js +9 -9
- package/dist/src/server/fs-browse.d.ts +14 -1
- package/dist/src/server/fs-browse.js +48 -5
- package/dist/src/server/fs-pick-folder.js +58 -11
- package/dist/src/server/fs-sandbox.js +36 -7
- package/dist/src/server/hive-team-guidance.d.ts +11 -6
- package/dist/src/server/hive-team-guidance.js +252 -70
- package/dist/src/server/live-run-registry.d.ts +1 -0
- package/dist/src/server/live-run-registry.js +1 -1
- package/dist/src/server/open-target-commands.js +29 -4
- package/dist/src/server/orchestrator-autostart.d.ts +12 -0
- package/dist/src/server/orchestrator-autostart.js +15 -13
- package/dist/src/server/path-canonicalization.d.ts +3 -0
- package/dist/src/server/path-canonicalization.js +29 -0
- package/dist/src/server/platform-path.d.ts +3 -0
- package/dist/src/server/platform-path.js +13 -0
- package/dist/src/server/post-start-input-writer.d.ts +1 -1
- package/dist/src/server/post-start-input-writer.js +116 -16
- package/dist/src/server/preset-launch-support.d.ts +1 -1
- package/dist/src/server/preset-launch-support.js +33 -2
- package/dist/src/server/recovery-summary.d.ts +6 -1
- package/dist/src/server/recovery-summary.js +17 -17
- package/dist/src/server/restart-policy-support.d.ts +6 -1
- package/dist/src/server/restart-policy-support.js +9 -1
- package/dist/src/server/restart-policy.d.ts +2 -2
- package/dist/src/server/restart-policy.js +3 -1
- package/dist/src/server/role-template-store.d.ts +1 -0
- package/dist/src/server/role-template-store.js +11 -1
- package/dist/src/server/route-types.d.ts +43 -0
- package/dist/src/server/routes-runtime.js +2 -1
- package/dist/src/server/routes-settings.js +76 -0
- package/dist/src/server/routes-team.js +221 -2
- package/dist/src/server/routes-workflow-schedules.d.ts +2 -0
- package/dist/src/server/routes-workflow-schedules.js +58 -0
- package/dist/src/server/routes-workflows.d.ts +2 -0
- package/dist/src/server/routes-workflows.js +83 -0
- package/dist/src/server/routes.js +4 -0
- package/dist/src/server/runtime-restart-policy.d.ts +3 -1
- package/dist/src/server/runtime-restart-policy.js +3 -1
- package/dist/src/server/runtime-store-contract.d.ts +122 -0
- package/dist/src/server/runtime-store-contract.js +1 -0
- package/dist/src/server/runtime-store-helpers.d.ts +9 -0
- package/dist/src/server/runtime-store-helpers.js +101 -2
- package/dist/src/server/runtime-store-workflows.d.ts +6 -0
- package/dist/src/server/runtime-store-workflows.js +100 -0
- package/dist/src/server/runtime-store.d.ts +3 -70
- package/dist/src/server/runtime-store.js +70 -4
- package/dist/src/server/session-capture-claude.d.ts +23 -0
- package/dist/src/server/session-capture-claude.js +24 -1
- package/dist/src/server/session-capture-codex.d.ts +3 -3
- package/dist/src/server/session-capture-codex.js +9 -7
- package/dist/src/server/session-capture-gemini.d.ts +1 -1
- package/dist/src/server/session-capture-gemini.js +6 -3
- package/dist/src/server/session-capture-opencode.d.ts +18 -0
- package/dist/src/server/session-capture-opencode.js +27 -2
- package/dist/src/server/settings-store.d.ts +3 -0
- package/dist/src/server/settings-store.js +1 -0
- package/dist/src/server/sqlite-schema-v19.d.ts +2 -0
- package/dist/src/server/sqlite-schema-v19.js +17 -0
- package/dist/src/server/sqlite-schema-v20.d.ts +2 -0
- package/dist/src/server/sqlite-schema-v20.js +20 -0
- package/dist/src/server/sqlite-schema-v21.d.ts +2 -0
- package/dist/src/server/sqlite-schema-v21.js +20 -0
- package/dist/src/server/sqlite-schema.d.ts +1 -1
- package/dist/src/server/sqlite-schema.js +97 -1
- package/dist/src/server/startup-command-parser.d.ts +15 -0
- package/dist/src/server/startup-command-parser.js +33 -2
- package/dist/src/server/system-message.d.ts +7 -0
- package/dist/src/server/system-message.js +8 -1
- package/dist/src/server/tasks-file-watcher.d.ts +39 -1
- package/dist/src/server/tasks-file-watcher.js +155 -25
- package/dist/src/server/tasks-file.d.ts +2 -1
- package/dist/src/server/tasks-file.js +32 -9
- package/dist/src/server/tasks-websocket-server.js +13 -14
- package/dist/src/server/team-authz.d.ts +1 -1
- package/dist/src/server/team-authz.js +9 -1
- package/dist/src/server/team-autostaff.d.ts +16 -0
- package/dist/src/server/team-autostaff.js +16 -0
- package/dist/src/server/team-list-serializer.d.ts +1 -1
- package/dist/src/server/team-list-serializer.js +3 -1
- package/dist/src/server/team-operations.d.ts +20 -2
- package/dist/src/server/team-operations.js +160 -14
- package/dist/src/server/terminal-input-profile.js +2 -8
- package/dist/src/server/terminal-protocol.js +9 -3
- package/dist/src/server/terminal-stream-hub.js +16 -10
- package/dist/src/server/terminal-ws-server.js +36 -16
- package/dist/src/server/websocket-upgrade-safety.d.ts +10 -0
- package/dist/src/server/websocket-upgrade-safety.js +35 -0
- package/dist/src/server/windows-command-line.d.ts +3 -0
- package/dist/src/server/windows-command-line.js +9 -0
- package/dist/src/server/windows-filename.d.ts +2 -0
- package/dist/src/server/windows-filename.js +33 -0
- package/dist/src/server/workflow-cli-policy.d.ts +60 -0
- package/dist/src/server/workflow-cli-policy.js +110 -0
- package/dist/src/server/workflow-dispatch-awaiter.d.ts +12 -0
- package/dist/src/server/workflow-dispatch-awaiter.js +80 -0
- package/dist/src/server/workflow-feature.d.ts +15 -0
- package/dist/src/server/workflow-feature.js +15 -0
- package/dist/src/server/workflow-http-serializers.d.ts +64 -0
- package/dist/src/server/workflow-http-serializers.js +58 -0
- package/dist/src/server/workflow-run-log-store.d.ts +19 -0
- package/dist/src/server/workflow-run-log-store.js +45 -0
- package/dist/src/server/workflow-run-store.d.ts +50 -0
- package/dist/src/server/workflow-run-store.js +103 -0
- package/dist/src/server/workflow-runner.d.ts +147 -0
- package/dist/src/server/workflow-runner.js +401 -0
- package/dist/src/server/workflow-schedule-create.d.ts +14 -0
- package/dist/src/server/workflow-schedule-create.js +41 -0
- package/dist/src/server/workflow-schedule-store.d.ts +43 -0
- package/dist/src/server/workflow-schedule-store.js +112 -0
- package/dist/src/server/workflow-scheduler.d.ts +36 -0
- package/dist/src/server/workflow-scheduler.js +97 -0
- package/dist/src/server/workflow-script-loader.d.ts +34 -0
- package/dist/src/server/workflow-script-loader.js +106 -0
- package/dist/src/server/workspace-path-validation.js +16 -4
- package/dist/src/server/workspace-shell-runtime.d.ts +5 -0
- package/dist/src/server/workspace-shell-runtime.js +24 -2
- package/dist/src/server/workspace-store-contract.d.ts +4 -1
- package/dist/src/server/workspace-store-hydration.js +23 -7
- package/dist/src/server/workspace-store-mutations.js +2 -5
- package/dist/src/server/workspace-store-support.d.ts +4 -0
- package/dist/src/server/workspace-store-support.js +13 -1
- package/dist/src/server/workspace-store.js +38 -4
- package/dist/src/shared/types.d.ts +16 -1
- package/package.json +4 -2
- package/web/dist/assets/{AddWorkerDialog-DmkDOdp6.js → AddWorkerDialog-CcC-7kgG.js} +2 -2
- package/web/dist/assets/AddWorkspaceDialog-BDpOTfmt.js +1 -0
- package/web/dist/assets/{FirstRunWizard-SAd1wsH4.js → FirstRunWizard-BYX_ocQn.js} +1 -1
- package/web/dist/assets/{MarketplaceDrawer-B_8aG2uT.js → MarketplaceDrawer-DUxSk7db.js} +1 -1
- package/web/dist/assets/WhatsNewDialog-B_RlCXcV.js +1 -0
- package/web/dist/assets/WorkerModal-D9-7YfZZ.js +1 -0
- package/web/dist/assets/WorkspaceTaskDrawer-BCKoF7qc.js +1 -0
- package/web/dist/assets/{WorkspaceTerminalPanels-BReWh1YL.js → WorkspaceTerminalPanels-Dq8y91t2.js} +1 -1
- package/web/dist/assets/index-BiOvKIVw.css +1 -0
- package/web/dist/assets/index-DMRUklT3.js +73 -0
- package/web/dist/assets/path-join-7MR1s7b1.js +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/AddWorkspaceDialog-BsVnH3Xe.js +0 -1
- package/web/dist/assets/WorkerModal-CQmjiPme.js +0 -1
- package/web/dist/assets/WorkspaceTaskDrawer-B0DmCWcV.js +0 -1
- package/web/dist/assets/chevron-right-CtLjVEl7.js +0 -1
- package/web/dist/assets/index-BEsTmfrO.css +0 -1
- package/web/dist/assets/index-Cn8X3get.js +0 -76
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createTerminalOutputFlow } from './terminal-flow-control.js';
|
|
2
2
|
import { parseTerminalControlMessage, serializeTerminalError, serializeTerminalExit, serializeTerminalRestore, } from './terminal-protocol.js';
|
|
3
3
|
import { TerminalStateMirror } from './terminal-state-mirror.js';
|
|
4
|
+
import { attachWebSocketErrorHandler, sendWebSocketMessage } from './websocket-upgrade-safety.js';
|
|
4
5
|
const normalizeTerminalInput = (raw, isBinary) => {
|
|
5
6
|
const bytes = Buffer.isBuffer(raw)
|
|
6
7
|
? raw
|
|
@@ -85,8 +86,8 @@ export const createTerminalStreamHub = (store) => {
|
|
|
85
86
|
const payload = serializeTerminalExit(run.exitCode);
|
|
86
87
|
for (const viewer of state.viewers.values()) {
|
|
87
88
|
const controlSocket = viewer.controlSocket;
|
|
88
|
-
if (controlSocket
|
|
89
|
-
controlSocket
|
|
89
|
+
if (controlSocket)
|
|
90
|
+
sendWebSocketMessage(controlSocket, payload, `terminal ${runId} exit`);
|
|
90
91
|
}
|
|
91
92
|
if (state.exitInterval)
|
|
92
93
|
clearInterval(state.exitInterval);
|
|
@@ -103,18 +104,17 @@ export const createTerminalStreamHub = (store) => {
|
|
|
103
104
|
return {
|
|
104
105
|
attachControl(runId, clientId, socket, initialSize) {
|
|
105
106
|
const state = getOrCreateState(runId, initialSize);
|
|
107
|
+
attachWebSocketErrorHandler(socket, `terminal ${runId} control`);
|
|
106
108
|
const viewer = getOrCreateViewer(state, clientId);
|
|
107
109
|
viewer.controlSocket = socket;
|
|
108
110
|
startExitWatcher(runId, state);
|
|
109
111
|
void state.mirror
|
|
110
112
|
.getSnapshot()
|
|
111
113
|
.then((snapshot) => {
|
|
112
|
-
|
|
113
|
-
socket.send(serializeTerminalRestore(snapshot));
|
|
114
|
+
sendWebSocketMessage(socket, serializeTerminalRestore(snapshot), `terminal ${runId} restore`);
|
|
114
115
|
})
|
|
115
116
|
.catch(() => {
|
|
116
|
-
|
|
117
|
-
socket.send(serializeTerminalRestore(''));
|
|
117
|
+
sendWebSocketMessage(socket, serializeTerminalRestore(''), `terminal ${runId} restore`);
|
|
118
118
|
});
|
|
119
119
|
socket.on('message', (raw) => {
|
|
120
120
|
try {
|
|
@@ -131,7 +131,7 @@ export const createTerminalStreamHub = (store) => {
|
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
133
|
catch (error) {
|
|
134
|
-
socket
|
|
134
|
+
sendWebSocketMessage(socket, serializeTerminalError(error instanceof Error ? error.message : 'Invalid control message'), `terminal ${runId} control error`);
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
socket.on('close', () => {
|
|
@@ -142,6 +142,7 @@ export const createTerminalStreamHub = (store) => {
|
|
|
142
142
|
},
|
|
143
143
|
attachIo(runId, clientId, socket, initialSize) {
|
|
144
144
|
const state = getOrCreateState(runId, initialSize);
|
|
145
|
+
attachWebSocketErrorHandler(socket, `terminal ${runId} io`);
|
|
145
146
|
const viewer = getOrCreateViewer(state, clientId);
|
|
146
147
|
viewer.ioSocket = socket;
|
|
147
148
|
viewer.flowState?.close();
|
|
@@ -158,7 +159,12 @@ export const createTerminalStreamHub = (store) => {
|
|
|
158
159
|
},
|
|
159
160
|
});
|
|
160
161
|
socket.on('message', (raw, isBinary) => {
|
|
161
|
-
|
|
162
|
+
try {
|
|
163
|
+
store.writeRunInput(runId, normalizeTerminalInput(raw, isBinary));
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
sendWebSocketMessage(socket, serializeTerminalError(error instanceof Error ? error.message : 'Failed to write terminal input'), `terminal ${runId} input error`);
|
|
167
|
+
}
|
|
162
168
|
});
|
|
163
169
|
socket.on('close', () => {
|
|
164
170
|
if (viewer.ioSocket === socket)
|
|
@@ -176,8 +182,8 @@ export const createTerminalStreamHub = (store) => {
|
|
|
176
182
|
state.mirror.dispose();
|
|
177
183
|
for (const viewer of state.viewers.values()) {
|
|
178
184
|
viewer.flowState?.close();
|
|
179
|
-
viewer.ioSocket?.
|
|
180
|
-
viewer.controlSocket?.
|
|
185
|
+
viewer.ioSocket?.terminate();
|
|
186
|
+
viewer.controlSocket?.terminate();
|
|
181
187
|
}
|
|
182
188
|
runStates.delete(runId);
|
|
183
189
|
}
|
|
@@ -3,6 +3,7 @@ import { getLocalRequestRejection } from './local-request-guard.js';
|
|
|
3
3
|
import { createTasksWebSocketServer } from './tasks-websocket-server.js';
|
|
4
4
|
import { createTerminalStreamHub } from './terminal-stream-hub.js';
|
|
5
5
|
import { readCookie } from './ui-auth-helpers.js';
|
|
6
|
+
import { attachRawSocketErrorHandler, attachWebSocketServerErrorHandler, rejectWebSocketUpgrade, } from './websocket-upgrade-safety.js';
|
|
6
7
|
const matchTerminalPath = (pathname) => {
|
|
7
8
|
const match = /^\/ws\/terminal\/(?<runId>[^/]+)\/(?<channel>io|control)$/.exec(pathname);
|
|
8
9
|
const groups = match?.groups;
|
|
@@ -24,13 +25,11 @@ const getInitialSize = (url) => {
|
|
|
24
25
|
}
|
|
25
26
|
return { cols, rows };
|
|
26
27
|
};
|
|
27
|
-
const rejectUpgrade = (socket, status) => {
|
|
28
|
-
socket.write(`HTTP/1.1 ${status}\r\n\r\n`);
|
|
29
|
-
socket.destroy();
|
|
30
|
-
};
|
|
31
28
|
export const createTerminalWebSocketServer = (server, store, tasksFileService) => {
|
|
32
29
|
const ioWss = new WebSocketServer({ noServer: true });
|
|
33
30
|
const controlWss = new WebSocketServer({ noServer: true });
|
|
31
|
+
attachWebSocketServerErrorHandler(ioWss, 'terminal io');
|
|
32
|
+
attachWebSocketServerErrorHandler(controlWss, 'terminal control');
|
|
34
33
|
const tasksWss = createTasksWebSocketServer(server, store, tasksFileService);
|
|
35
34
|
const hub = createTerminalStreamHub(store);
|
|
36
35
|
const disposeTasksListener = store.registerTasksListener((workspaceId, content) => {
|
|
@@ -43,6 +42,26 @@ export const createTerminalWebSocketServer = (server, store, tasksFileService) =
|
|
|
43
42
|
const token = readCookie(cookieHeader, 'hive_ui_token');
|
|
44
43
|
return store.validateUiToken(token);
|
|
45
44
|
};
|
|
45
|
+
let closed = false;
|
|
46
|
+
const closeAll = () => {
|
|
47
|
+
if (closed)
|
|
48
|
+
return;
|
|
49
|
+
closed = true;
|
|
50
|
+
// Order matters: dispose the publisher first so no new frames are
|
|
51
|
+
// queued onto sockets that are about to be torn down. Then forcibly
|
|
52
|
+
// terminate any open WS clients (terminate() skips the close
|
|
53
|
+
// handshake, which is what we need — a polite ws.close() would wait
|
|
54
|
+
// on the remote side and re-introduce the hang we're fixing).
|
|
55
|
+
disposeTasksListener();
|
|
56
|
+
for (const ws of ioWss.clients)
|
|
57
|
+
ws.terminate();
|
|
58
|
+
for (const ws of controlWss.clients)
|
|
59
|
+
ws.terminate();
|
|
60
|
+
tasksWss.close();
|
|
61
|
+
ioWss.close();
|
|
62
|
+
controlWss.close();
|
|
63
|
+
hub.close();
|
|
64
|
+
};
|
|
46
65
|
server.on('upgrade', (request, socket, head) => {
|
|
47
66
|
const url = new URL(request.url ?? '/', 'http://127.0.0.1');
|
|
48
67
|
const pathname = url.pathname;
|
|
@@ -51,26 +70,29 @@ export const createTerminalWebSocketServer = (server, store, tasksFileService) =
|
|
|
51
70
|
if (/^\/ws\/tasks\/.+/.test(pathname)) {
|
|
52
71
|
return;
|
|
53
72
|
}
|
|
54
|
-
|
|
73
|
+
attachRawSocketErrorHandler(socket, 'terminal upgrade');
|
|
74
|
+
rejectWebSocketUpgrade(socket, '404 Not Found');
|
|
55
75
|
return;
|
|
56
76
|
}
|
|
77
|
+
const detachRawSocketErrorHandler = attachRawSocketErrorHandler(socket, 'terminal upgrade');
|
|
57
78
|
if (getLocalRequestRejection(request)) {
|
|
58
|
-
|
|
79
|
+
rejectWebSocketUpgrade(socket, '403 Forbidden');
|
|
59
80
|
return;
|
|
60
81
|
}
|
|
61
82
|
if (!validateUpgradeSession(request)) {
|
|
62
|
-
|
|
83
|
+
rejectWebSocketUpgrade(socket, '401 Unauthorized');
|
|
63
84
|
return;
|
|
64
85
|
}
|
|
65
86
|
try {
|
|
66
87
|
store.getLiveRun(match.runId);
|
|
67
88
|
}
|
|
68
89
|
catch {
|
|
69
|
-
|
|
90
|
+
rejectWebSocketUpgrade(socket, '404 Not Found');
|
|
70
91
|
return;
|
|
71
92
|
}
|
|
72
93
|
const wss = match.channel === 'io' ? ioWss : controlWss;
|
|
73
94
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
95
|
+
detachRawSocketErrorHandler();
|
|
74
96
|
const clientId = getClientId(url);
|
|
75
97
|
if (match.channel === 'io')
|
|
76
98
|
hub.attachIo(match.runId, clientId, ws, getInitialSize(url));
|
|
@@ -78,12 +100,10 @@ export const createTerminalWebSocketServer = (server, store, tasksFileService) =
|
|
|
78
100
|
hub.attachControl(match.runId, clientId, ws, getInitialSize(url));
|
|
79
101
|
});
|
|
80
102
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
return { close: () => hub.close() };
|
|
103
|
+
// Kept as an idempotent fallback for callers that drive
|
|
104
|
+
// `app.server.close()` directly (e.g. unit tests in tests/server/*)
|
|
105
|
+
// and never see the runHiveCommand close path. closeAll() is guarded
|
|
106
|
+
// by `closed` so calling both is a no-op.
|
|
107
|
+
server.on('close', closeAll);
|
|
108
|
+
return { close: closeAll };
|
|
89
109
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Duplex } from 'node:stream';
|
|
2
|
+
import type WebSocket from 'ws';
|
|
3
|
+
import type { WebSocketServer } from 'ws';
|
|
4
|
+
type UpgradeSocket = Duplex;
|
|
5
|
+
export declare const attachRawSocketErrorHandler: (socket: UpgradeSocket, context: string) => () => Duplex;
|
|
6
|
+
export declare const attachWebSocketServerErrorHandler: (wss: WebSocketServer, context: string) => void;
|
|
7
|
+
export declare const attachWebSocketErrorHandler: (socket: WebSocket, context: string) => void;
|
|
8
|
+
export declare const rejectWebSocketUpgrade: (socket: UpgradeSocket, status: string) => void;
|
|
9
|
+
export declare const sendWebSocketMessage: (socket: WebSocket, payload: string, context: string) => boolean;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const logSocketError = (context, error) => {
|
|
2
|
+
console.error(`[hive] ${context}`, error);
|
|
3
|
+
};
|
|
4
|
+
export const attachRawSocketErrorHandler = (socket, context) => {
|
|
5
|
+
const handler = (error) => logSocketError(`${context} socket error`, error);
|
|
6
|
+
socket.on('error', handler);
|
|
7
|
+
return () => socket.off('error', handler);
|
|
8
|
+
};
|
|
9
|
+
export const attachWebSocketServerErrorHandler = (wss, context) => {
|
|
10
|
+
wss.on('error', (error) => logSocketError(`${context} websocket server error`, error));
|
|
11
|
+
};
|
|
12
|
+
export const attachWebSocketErrorHandler = (socket, context) => {
|
|
13
|
+
socket.on('error', (error) => logSocketError(`${context} websocket error`, error));
|
|
14
|
+
};
|
|
15
|
+
export const rejectWebSocketUpgrade = (socket, status) => {
|
|
16
|
+
try {
|
|
17
|
+
socket.write(`HTTP/1.1 ${status}\r\nConnection: close\r\n\r\n`);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
logSocketError(`failed to reject websocket upgrade with ${status}`, error);
|
|
21
|
+
}
|
|
22
|
+
socket.destroy();
|
|
23
|
+
};
|
|
24
|
+
export const sendWebSocketMessage = (socket, payload, context) => {
|
|
25
|
+
if (socket.readyState !== socket.OPEN)
|
|
26
|
+
return false;
|
|
27
|
+
try {
|
|
28
|
+
socket.send(payload);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
logSocketError(`${context} send failed`, error);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const CMD_META_CHARS = /[\s"&<>|^()%]/u;
|
|
2
|
+
export const escapeCmdToken = (value) => {
|
|
3
|
+
if (value.length === 0)
|
|
4
|
+
return '""';
|
|
5
|
+
const escaped = value.replace(/%/g, '%%').replace(/"/g, '""');
|
|
6
|
+
return CMD_META_CHARS.test(value) ? `"${escaped}"` : escaped;
|
|
7
|
+
};
|
|
8
|
+
export const buildCmdCommand = (command, args = []) => [command, ...args].map(escapeCmdToken).join(' ');
|
|
9
|
+
export const buildCmdCallCommand = (command, args = []) => `call ${buildCmdCommand(command, args)}`;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const WINDOWS_DEVICE_NAMES = /^(con|prn|aux|nul|com[1-9\u00b9\u00b2\u00b3]|lpt[1-9\u00b9\u00b2\u00b3])$/iu;
|
|
2
|
+
const WINDOWS_INVALID_FILENAME_CHARS = new Set(['<', '>', ':', '"', '/', '\\', '|', '?', '*']);
|
|
3
|
+
const hasWindowsInvalidFilenameChar = (filename) => {
|
|
4
|
+
for (const char of filename) {
|
|
5
|
+
if (WINDOWS_INVALID_FILENAME_CHARS.has(char))
|
|
6
|
+
return true;
|
|
7
|
+
const code = char.codePointAt(0) ?? 0;
|
|
8
|
+
if (code >= 0 && code <= 31)
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
13
|
+
export const getWindowsFilenameError = (filename) => {
|
|
14
|
+
if (!filename.trim())
|
|
15
|
+
return 'filename must not be empty';
|
|
16
|
+
if (filename === '.' || filename === '..')
|
|
17
|
+
return 'filename must not be a relative segment';
|
|
18
|
+
if (hasWindowsInvalidFilenameChar(filename)) {
|
|
19
|
+
return 'filename contains characters Windows cannot create';
|
|
20
|
+
}
|
|
21
|
+
if (/[. ]$/u.test(filename))
|
|
22
|
+
return 'filename must not end with a space or period';
|
|
23
|
+
const stem = filename.split('.')[0] ?? filename;
|
|
24
|
+
if (WINDOWS_DEVICE_NAMES.test(stem)) {
|
|
25
|
+
return `filename uses reserved Windows device name: ${stem}`;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
};
|
|
29
|
+
export const assertWindowsSafeFilename = (filename) => {
|
|
30
|
+
const error = getWindowsFilenameError(filename);
|
|
31
|
+
if (error)
|
|
32
|
+
throw new Error(error);
|
|
33
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow CLI policy — controls which CLI a workflow's `agent()` spawns.
|
|
3
|
+
*
|
|
4
|
+
* Before this, the runner hard-coded `opts.cli ?? 'claude'`: a user who only
|
|
5
|
+
* had Codex set up would have every workflow agent that omitted `cli` spawn a
|
|
6
|
+
* `claude` it can't run. The policy makes the default configurable and lets
|
|
7
|
+
* the user constrain which CLIs workflow agents may use.
|
|
8
|
+
*
|
|
9
|
+
* Stored GLOBALLY in `app_state` (CLI availability is a machine-level fact, not
|
|
10
|
+
* per-workspace) under WORKFLOW_CLI_POLICY_KEY as a JSON `{default, allowed}`.
|
|
11
|
+
* An absent/malformed value reads back as DEFAULT_WORKFLOW_CLI_POLICY, which is
|
|
12
|
+
* unrestricted and defaults to `claude` — i.e. exactly the old behavior, so
|
|
13
|
+
* upgrading without configuring anything changes nothing.
|
|
14
|
+
*/
|
|
15
|
+
/** Canonical CLI set — mirrors the built-in command preset ids
|
|
16
|
+
* (see command-preset-defaults.ts). The allowlist is a subset of these. */
|
|
17
|
+
export declare const CANONICAL_WORKFLOW_CLIS: readonly ["claude", "codex", "opencode", "gemini"];
|
|
18
|
+
export type WorkflowCli = (typeof CANONICAL_WORKFLOW_CLIS)[number];
|
|
19
|
+
export declare const WORKFLOW_CLI_POLICY_KEY = "workflow.cli-policy";
|
|
20
|
+
export interface WorkflowCliPolicy {
|
|
21
|
+
/** CLI used when an `agent()` call omits `cli` and isn't a custom template. */
|
|
22
|
+
default: string;
|
|
23
|
+
/** CLIs an explicit `opts.cli` (and the default fallback) may use. */
|
|
24
|
+
allowed: string[];
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_WORKFLOW_CLI_POLICY: WorkflowCliPolicy;
|
|
27
|
+
/**
|
|
28
|
+
* Lenient coercion used by the runtime reader: turn arbitrary stored data into
|
|
29
|
+
* a usable policy, never throwing. Junk in `allowed` is dropped; an empty
|
|
30
|
+
* result falls back to the full canonical default; a `default` outside the
|
|
31
|
+
* sanitized `allowed` is pulled back to the first allowed entry.
|
|
32
|
+
*/
|
|
33
|
+
export declare const normalizeWorkflowCliPolicy: (input: unknown) => WorkflowCliPolicy;
|
|
34
|
+
/** Parse the raw `app_state` string. Absent / malformed → canonical default. */
|
|
35
|
+
export declare const readWorkflowCliPolicy: (raw: string | null | undefined) => WorkflowCliPolicy;
|
|
36
|
+
/**
|
|
37
|
+
* Strict validation for the settings API: reject bad input so a malformed
|
|
38
|
+
* policy can never be persisted (the reader tolerates junk, but we'd rather
|
|
39
|
+
* fail the write than silently store something the user didn't intend).
|
|
40
|
+
*/
|
|
41
|
+
export declare const assertValidWorkflowCliPolicy: (input: unknown) => WorkflowCliPolicy;
|
|
42
|
+
export interface ResolveWorkflowCliInput {
|
|
43
|
+
/** `opts.cli` from the `agent()` call, if any. */
|
|
44
|
+
requestedCli?: string;
|
|
45
|
+
/** True when `agentType` resolved to a workspace custom role template. */
|
|
46
|
+
isCustomTemplate: boolean;
|
|
47
|
+
/** The custom template's `defaultCommand` (only consulted when custom). */
|
|
48
|
+
templateDefaultCommand?: string;
|
|
49
|
+
policy: WorkflowCliPolicy;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the CLI command a workflow agent should launch with.
|
|
53
|
+
*
|
|
54
|
+
* - An explicit `requestedCli` is ALWAYS validated against `allowed` (throws
|
|
55
|
+
* if disallowed, so the orchestrator gets a clear, fixable error).
|
|
56
|
+
* - When omitted: a custom template keeps its own `defaultCommand` (the user
|
|
57
|
+
* curated that role deliberately — exempt from the allowlist); a built-in
|
|
58
|
+
* role falls back to `policy.default`.
|
|
59
|
+
*/
|
|
60
|
+
export declare const resolveWorkflowCli: ({ requestedCli, isCustomTemplate, templateDefaultCommand, policy, }: ResolveWorkflowCliInput) => string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow CLI policy — controls which CLI a workflow's `agent()` spawns.
|
|
3
|
+
*
|
|
4
|
+
* Before this, the runner hard-coded `opts.cli ?? 'claude'`: a user who only
|
|
5
|
+
* had Codex set up would have every workflow agent that omitted `cli` spawn a
|
|
6
|
+
* `claude` it can't run. The policy makes the default configurable and lets
|
|
7
|
+
* the user constrain which CLIs workflow agents may use.
|
|
8
|
+
*
|
|
9
|
+
* Stored GLOBALLY in `app_state` (CLI availability is a machine-level fact, not
|
|
10
|
+
* per-workspace) under WORKFLOW_CLI_POLICY_KEY as a JSON `{default, allowed}`.
|
|
11
|
+
* An absent/malformed value reads back as DEFAULT_WORKFLOW_CLI_POLICY, which is
|
|
12
|
+
* unrestricted and defaults to `claude` — i.e. exactly the old behavior, so
|
|
13
|
+
* upgrading without configuring anything changes nothing.
|
|
14
|
+
*/
|
|
15
|
+
/** Canonical CLI set — mirrors the built-in command preset ids
|
|
16
|
+
* (see command-preset-defaults.ts). The allowlist is a subset of these. */
|
|
17
|
+
export const CANONICAL_WORKFLOW_CLIS = ['claude', 'codex', 'opencode', 'gemini'];
|
|
18
|
+
export const WORKFLOW_CLI_POLICY_KEY = 'workflow.cli-policy';
|
|
19
|
+
export const DEFAULT_WORKFLOW_CLI_POLICY = {
|
|
20
|
+
default: 'claude',
|
|
21
|
+
allowed: [...CANONICAL_WORKFLOW_CLIS],
|
|
22
|
+
};
|
|
23
|
+
const isCanonical = (value) => typeof value === 'string' && CANONICAL_WORKFLOW_CLIS.includes(value);
|
|
24
|
+
/** Canonical entries from `input`, deduped and in canonical order. */
|
|
25
|
+
const sanitizeAllowed = (input) => {
|
|
26
|
+
if (!Array.isArray(input))
|
|
27
|
+
return [];
|
|
28
|
+
const set = new Set(input.filter(isCanonical));
|
|
29
|
+
return CANONICAL_WORKFLOW_CLIS.filter((cli) => set.has(cli));
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Lenient coercion used by the runtime reader: turn arbitrary stored data into
|
|
33
|
+
* a usable policy, never throwing. Junk in `allowed` is dropped; an empty
|
|
34
|
+
* result falls back to the full canonical default; a `default` outside the
|
|
35
|
+
* sanitized `allowed` is pulled back to the first allowed entry.
|
|
36
|
+
*/
|
|
37
|
+
export const normalizeWorkflowCliPolicy = (input) => {
|
|
38
|
+
if (typeof input !== 'object' || input === null)
|
|
39
|
+
return DEFAULT_WORKFLOW_CLI_POLICY;
|
|
40
|
+
const record = input;
|
|
41
|
+
const allowed = sanitizeAllowed(record.allowed);
|
|
42
|
+
if (allowed.length === 0)
|
|
43
|
+
return DEFAULT_WORKFLOW_CLI_POLICY;
|
|
44
|
+
const requestedDefault = record.default;
|
|
45
|
+
const fallback = allowed[0];
|
|
46
|
+
const resolvedDefault = typeof requestedDefault === 'string' && allowed.includes(requestedDefault)
|
|
47
|
+
? requestedDefault
|
|
48
|
+
: fallback;
|
|
49
|
+
return { default: resolvedDefault, allowed };
|
|
50
|
+
};
|
|
51
|
+
/** Parse the raw `app_state` string. Absent / malformed → canonical default. */
|
|
52
|
+
export const readWorkflowCliPolicy = (raw) => {
|
|
53
|
+
if (raw === null || raw === undefined)
|
|
54
|
+
return DEFAULT_WORKFLOW_CLI_POLICY;
|
|
55
|
+
try {
|
|
56
|
+
return normalizeWorkflowCliPolicy(JSON.parse(raw));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return DEFAULT_WORKFLOW_CLI_POLICY;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Strict validation for the settings API: reject bad input so a malformed
|
|
64
|
+
* policy can never be persisted (the reader tolerates junk, but we'd rather
|
|
65
|
+
* fail the write than silently store something the user didn't intend).
|
|
66
|
+
*/
|
|
67
|
+
export const assertValidWorkflowCliPolicy = (input) => {
|
|
68
|
+
if (typeof input !== 'object' || input === null) {
|
|
69
|
+
throw new Error('workflow cli policy must be an object { default, allowed }');
|
|
70
|
+
}
|
|
71
|
+
const record = input;
|
|
72
|
+
if (!Array.isArray(record.allowed)) {
|
|
73
|
+
throw new Error('workflow cli policy `allowed` must be an array');
|
|
74
|
+
}
|
|
75
|
+
if (record.allowed.length === 0) {
|
|
76
|
+
throw new Error('workflow cli policy `allowed` must list at least one CLI');
|
|
77
|
+
}
|
|
78
|
+
const bad = record.allowed.find((entry) => !isCanonical(entry));
|
|
79
|
+
if (bad !== undefined) {
|
|
80
|
+
throw new Error(`workflow cli policy "allowed" has an unsupported CLI: ${JSON.stringify(bad)}. Supported: ${CANONICAL_WORKFLOW_CLIS.join(', ')}`);
|
|
81
|
+
}
|
|
82
|
+
if (typeof record.default !== 'string' || !record.allowed.includes(record.default)) {
|
|
83
|
+
throw new Error(`workflow cli policy "default" (${JSON.stringify(record.default)}) must be one of allowed: ${record.allowed.join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
// Dedupe + canonical order while preserving the (now-validated) selection.
|
|
86
|
+
return { default: record.default, allowed: sanitizeAllowed(record.allowed) };
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Resolve the CLI command a workflow agent should launch with.
|
|
90
|
+
*
|
|
91
|
+
* - An explicit `requestedCli` is ALWAYS validated against `allowed` (throws
|
|
92
|
+
* if disallowed, so the orchestrator gets a clear, fixable error).
|
|
93
|
+
* - When omitted: a custom template keeps its own `defaultCommand` (the user
|
|
94
|
+
* curated that role deliberately — exempt from the allowlist); a built-in
|
|
95
|
+
* role falls back to `policy.default`.
|
|
96
|
+
*/
|
|
97
|
+
export const resolveWorkflowCli = ({ requestedCli, isCustomTemplate, templateDefaultCommand, policy, }) => {
|
|
98
|
+
const explicit = requestedCli?.trim();
|
|
99
|
+
if (explicit) {
|
|
100
|
+
if (!policy.allowed.includes(explicit)) {
|
|
101
|
+
throw new Error(`Workflow agent cli '${explicit}' is not allowed in this workspace. ` +
|
|
102
|
+
`Allowed: ${policy.allowed.join(', ')}. ` +
|
|
103
|
+
`Pick an allowed cli, or change the workflow CLI policy in Settings.`);
|
|
104
|
+
}
|
|
105
|
+
return explicit;
|
|
106
|
+
}
|
|
107
|
+
if (isCustomTemplate && templateDefaultCommand)
|
|
108
|
+
return templateDefaultCommand;
|
|
109
|
+
return policy.default;
|
|
110
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ReportPayload {
|
|
2
|
+
text: string;
|
|
3
|
+
artifacts: string[];
|
|
4
|
+
status?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface WorkflowDispatchAwaiter {
|
|
7
|
+
awaitReport(dispatchId: string, timeoutMs?: number): Promise<ReportPayload>;
|
|
8
|
+
notifyReport(dispatchId: string, payload: ReportPayload): void;
|
|
9
|
+
notifyCancel(dispatchId: string, reason: string): void;
|
|
10
|
+
cancelAll(reason: string): void;
|
|
11
|
+
}
|
|
12
|
+
export declare const createWorkflowDispatchAwaiter: () => WorkflowDispatchAwaiter;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Default 10 minutes — workflows often run long. Callers may shorten via opts.
|
|
2
|
+
const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000;
|
|
3
|
+
export const createWorkflowDispatchAwaiter = () => {
|
|
4
|
+
const pending = new Map();
|
|
5
|
+
// TIER 2 #10 — deferred-cancel state. The runner creates a dispatch
|
|
6
|
+
// and THEN calls awaitReport, with at least one microtask gap between
|
|
7
|
+
// the two. If notifyCancel(id) fires in that gap, it currently hits
|
|
8
|
+
// an empty `pending` map and no-ops; the subsequent awaitReport(id)
|
|
9
|
+
// then waits the full DEFAULT_TIMEOUT_MS (10 min) on a dispatch that
|
|
10
|
+
// is already cancelled. Remembering the cancel intent here lets
|
|
11
|
+
// awaitReport reject synchronously the instant it gets registered.
|
|
12
|
+
// We also remember any pre-arrived report payload for the same
|
|
13
|
+
// reason — defensive against a future ordering change.
|
|
14
|
+
const cancelledIds = new Map();
|
|
15
|
+
const reportedIds = new Map();
|
|
16
|
+
const take = (dispatchId) => {
|
|
17
|
+
const entry = pending.get(dispatchId);
|
|
18
|
+
if (entry) {
|
|
19
|
+
clearTimeout(entry.timer);
|
|
20
|
+
pending.delete(dispatchId);
|
|
21
|
+
}
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
awaitReport(dispatchId, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
// Pre-arrived events: drain immediately, no timer / no entry.
|
|
28
|
+
const earlyReport = reportedIds.get(dispatchId);
|
|
29
|
+
if (earlyReport) {
|
|
30
|
+
reportedIds.delete(dispatchId);
|
|
31
|
+
resolve(earlyReport);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const earlyCancel = cancelledIds.get(dispatchId);
|
|
35
|
+
if (earlyCancel) {
|
|
36
|
+
cancelledIds.delete(dispatchId);
|
|
37
|
+
reject(new Error(`workflow dispatch ${dispatchId} cancelled: ${earlyCancel}`));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const timer = setTimeout(() => {
|
|
41
|
+
pending.delete(dispatchId);
|
|
42
|
+
reject(new Error(`workflow dispatch ${dispatchId} timeout after ${timeoutMs}ms`));
|
|
43
|
+
}, timeoutMs);
|
|
44
|
+
pending.set(dispatchId, { resolve, reject, timer });
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
notifyReport(dispatchId, payload) {
|
|
48
|
+
const entry = take(dispatchId);
|
|
49
|
+
if (entry) {
|
|
50
|
+
entry.resolve(payload);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// Pre-arrival: stash for the eventual awaitReport call. Cap
|
|
54
|
+
// stash size implicitly by overwriting on duplicate id.
|
|
55
|
+
reportedIds.set(dispatchId, payload);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
notifyCancel(dispatchId, reason) {
|
|
59
|
+
const entry = take(dispatchId);
|
|
60
|
+
if (entry) {
|
|
61
|
+
entry.reject(new Error(`workflow dispatch ${dispatchId} cancelled: ${reason}`));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
cancelledIds.set(dispatchId, reason);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
cancelAll(reason) {
|
|
68
|
+
for (const [id, entry] of pending) {
|
|
69
|
+
clearTimeout(entry.timer);
|
|
70
|
+
entry.reject(new Error(`workflow dispatch ${id} cancelled: ${reason}`));
|
|
71
|
+
}
|
|
72
|
+
pending.clear();
|
|
73
|
+
// cancelAll happens at runtime close — anything waiting at that
|
|
74
|
+
// moment should fail loudly, but the deferred state can be
|
|
75
|
+
// safely dropped since no future awaitReport will run.
|
|
76
|
+
cancelledIds.clear();
|
|
77
|
+
reportedIds.clear();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow experimental feature gate.
|
|
3
|
+
*
|
|
4
|
+
* Workflows (`team workflow run`, the scheduler, the UI drawer, and the chunk
|
|
5
|
+
* of orchestrator guidance that teaches them) are a power feature with sharp
|
|
6
|
+
* edges — runaway fan-outs, authoring footguns, no run-resume yet. They ship
|
|
7
|
+
* OFF by default; a user opts in from Settings. While off, the orchestrator is
|
|
8
|
+
* not even taught about workflows, which also keeps its always-on prompt lean.
|
|
9
|
+
*
|
|
10
|
+
* Stored GLOBALLY in `app_state` under WORKFLOW_ENABLED_KEY. Absent / anything
|
|
11
|
+
* other than the exact string "true" reads back as DISABLED.
|
|
12
|
+
*/
|
|
13
|
+
export declare const WORKFLOW_ENABLED_KEY = "workflow.enabled";
|
|
14
|
+
export declare const readWorkflowEnabled: (raw: string | null | undefined) => boolean;
|
|
15
|
+
export declare const serializeWorkflowEnabled: (enabled: boolean) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow experimental feature gate.
|
|
3
|
+
*
|
|
4
|
+
* Workflows (`team workflow run`, the scheduler, the UI drawer, and the chunk
|
|
5
|
+
* of orchestrator guidance that teaches them) are a power feature with sharp
|
|
6
|
+
* edges — runaway fan-outs, authoring footguns, no run-resume yet. They ship
|
|
7
|
+
* OFF by default; a user opts in from Settings. While off, the orchestrator is
|
|
8
|
+
* not even taught about workflows, which also keeps its always-on prompt lean.
|
|
9
|
+
*
|
|
10
|
+
* Stored GLOBALLY in `app_state` under WORKFLOW_ENABLED_KEY. Absent / anything
|
|
11
|
+
* other than the exact string "true" reads back as DISABLED.
|
|
12
|
+
*/
|
|
13
|
+
export const WORKFLOW_ENABLED_KEY = 'workflow.enabled';
|
|
14
|
+
export const readWorkflowEnabled = (raw) => raw === 'true';
|
|
15
|
+
export const serializeWorkflowEnabled = (enabled) => (enabled ? 'true' : 'false');
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { LiveAgentRun } from './agent-runtime-types.js';
|
|
2
|
+
import type { DispatchRecord } from './dispatch-ledger-store.js';
|
|
3
|
+
import type { WorkflowRunRecord } from './workflow-run-store.js';
|
|
4
|
+
import type { WorkflowScheduleRecord } from './workflow-schedule-store.js';
|
|
5
|
+
export declare const serializeLiveAgentRun: (run: LiveAgentRun) => {
|
|
6
|
+
agent_id: string;
|
|
7
|
+
exit_code: number | null;
|
|
8
|
+
output: string;
|
|
9
|
+
pid: number | null;
|
|
10
|
+
run_id: string;
|
|
11
|
+
started_at: number;
|
|
12
|
+
status: import("./agent-manager.js").RunStatus;
|
|
13
|
+
};
|
|
14
|
+
export declare const serializeWorkflowRun: (run: WorkflowRunRecord) => {
|
|
15
|
+
agent_count: number;
|
|
16
|
+
args: unknown;
|
|
17
|
+
created_at: number;
|
|
18
|
+
error: string | null;
|
|
19
|
+
finished_at: number | null;
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
parent_run_id: string | null;
|
|
23
|
+
phase: string | null;
|
|
24
|
+
result: unknown;
|
|
25
|
+
script_hash: string | null;
|
|
26
|
+
script_path: string;
|
|
27
|
+
started_at: number;
|
|
28
|
+
status: import("./workflow-run-store.js").WorkflowRunStatus;
|
|
29
|
+
workspace_id: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const serializeWorkflowDispatch: (dispatch: DispatchRecord & {
|
|
32
|
+
lastPtyLine?: string;
|
|
33
|
+
}) => {
|
|
34
|
+
artifacts: string[];
|
|
35
|
+
created_at: number;
|
|
36
|
+
delivered_at: number | null;
|
|
37
|
+
from_agent_id: string | null;
|
|
38
|
+
id: string;
|
|
39
|
+
label: string | null;
|
|
40
|
+
last_pty_line: string | null;
|
|
41
|
+
phase: string | null;
|
|
42
|
+
reported_at: number | null;
|
|
43
|
+
report_text: string | null;
|
|
44
|
+
sequence: number | null;
|
|
45
|
+
status: import("./dispatch-ledger-store.js").DispatchStatus;
|
|
46
|
+
step_index: number | null;
|
|
47
|
+
submitted_at: number | null;
|
|
48
|
+
text: string;
|
|
49
|
+
to_agent_id: string;
|
|
50
|
+
workflow_run_id: string | null;
|
|
51
|
+
workspace_id: string;
|
|
52
|
+
};
|
|
53
|
+
export declare const serializeWorkflowSchedule: (schedule: WorkflowScheduleRecord) => {
|
|
54
|
+
args: unknown;
|
|
55
|
+
created_at: number;
|
|
56
|
+
cron: string;
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
id: string;
|
|
59
|
+
last_run_at: number | null;
|
|
60
|
+
next_run_at: number;
|
|
61
|
+
script_path: string;
|
|
62
|
+
updated_at: number;
|
|
63
|
+
workspace_id: string;
|
|
64
|
+
};
|