@cortex-agent/server 2026.9.14 → 2026.9.21
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 +3 -2
- package/defaults/config/hooks/08-agents-md-injector-post-tool.json +10 -0
- package/defaults/config/hooks/{10-cortex-md-injector-session-start.json → 10-agents-md-injector-session-start.json} +3 -3
- package/defaults/config/hooks/{CORTEX.md → AGENTS.md} +2 -2
- package/defaults/hooks/{CORTEX.md → AGENTS.md} +1 -1
- package/defaults/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
- package/defaults/hooks/cortex-hook-api.mjs +2 -2
- package/defaults/hooks/new-session-hook.mjs +2 -2
- package/defaults/hooks/rules-loader.mjs +2 -2
- package/defaults/hooks/status-md-guard.mjs +8 -8
- package/defaults/hooks/task-status-check.mjs +18 -76
- package/defaults/hooks/tasks-yaml-guard.mjs +2 -2
- package/defaults/plugins/cortex-commission/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-commission/plugin.json +2 -2
- package/defaults/plugins/cortex-commission/skills/commission/SKILL.md +3 -3
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +2 -2
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
- package/defaults/plugins/cortex-system/skills/task/SKILL.md +1 -1
- package/defaults/rules/{cortex-md.md → agents-md.md} +4 -4
- package/defaults/rules/decision-records.md +1 -1
- package/defaults/rules/meta-conventions.md +4 -4
- package/defaults/rules/mission-md.md +1 -1
- package/dist/agent-adapter/claude/adapter.d.ts +0 -6
- package/dist/agent-adapter/claude/adapter.js +0 -8
- package/dist/agent-adapter/claude/defaults.d.ts +10 -7
- package/dist/agent-adapter/claude/defaults.js +18 -16
- package/dist/agent-adapter/claude/hooks-builder.js +2 -2
- package/dist/agent-adapter/claude/spawn-args.d.ts +0 -3
- package/dist/agent-adapter/claude/spawn-args.js +20 -16
- package/dist/agent-adapter/claude/turn-machine.d.ts +11 -0
- package/dist/agent-adapter/claude/turn-machine.js +46 -5
- package/dist/agent-adapter/normalize/prompt-builder.d.ts +16 -1
- package/dist/agent-adapter/normalize/prompt-builder.js +24 -6
- package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +11 -2
- package/dist/agent-adapter/pi/mcp-bridge-logic.js +32 -1
- package/dist/agent-adapter/pi/mcp-bridge.js +16 -15
- package/dist/agent-adapter/pi/session-options.d.ts +0 -6
- package/dist/agent-adapter/pi/session-options.js +1 -8
- package/dist/agent-adapter/types.d.ts +1 -1
- package/dist/core/mcp-tool-gate.d.ts +3 -17
- package/dist/core/mcp-tool-gate.js +4 -19
- package/dist/core/media-types.d.ts +10 -0
- package/dist/core/media-types.js +34 -0
- package/dist/core/platform-settings-spec.js +1 -1
- package/dist/core/settings-spec.d.ts +22 -1
- package/dist/core/settings-spec.js +33 -2
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/utils.d.ts +1 -1
- package/dist/core/utils.js +1 -1
- package/dist/domain/agents/config.d.ts +1 -1
- package/dist/domain/agents/config.js +1 -1
- package/dist/domain/agents/profile-switch.d.ts +1 -1
- package/dist/domain/agents/profile-switch.js +3 -5
- package/dist/domain/agents/subagent/runner.js +0 -1
- package/dist/domain/commissions/commission-draft.d.ts +58 -0
- package/dist/domain/commissions/commission-draft.js +87 -4
- package/dist/domain/commissions/commission-finalize.d.ts +8 -3
- package/dist/domain/commissions/commission-finalize.js +14 -0
- package/dist/domain/executions/registry.d.ts +1 -2
- package/dist/domain/executions/registry.js +0 -3
- package/dist/domain/mcp/bundled-server.js +4 -3
- package/dist/domain/mcp/feishu/file.js +37 -18
- package/dist/domain/mcp/feishu/types.d.ts +3 -0
- package/dist/domain/mcp/feishu-server.js +1 -1
- package/dist/domain/mcp/tools/{cortex-md.d.ts → agents-md.d.ts} +6 -6
- package/dist/domain/mcp/tools/{cortex-md.js → agents-md.js} +6 -6
- package/dist/domain/mcp/tools/commission-tools.d.ts +12 -1
- package/dist/domain/mcp/tools/commission-tools.js +68 -14
- package/dist/domain/mcp/tools/remote-file.d.ts +20 -0
- package/dist/domain/mcp/tools/remote-file.js +44 -0
- package/dist/domain/mcp/tools/slack.d.ts +2 -0
- package/dist/domain/mcp/tools/slack.js +22 -7
- package/dist/domain/mcp/tools/task-ops.js +5 -13
- package/dist/domain/mcp/tools/ui-file.js +23 -10
- package/dist/domain/mcp/tools/waitpoint.d.ts +3 -0
- package/dist/domain/mcp/tools/waitpoint.js +122 -0
- package/dist/domain/memory/agents-md-injector.d.ts +24 -0
- package/dist/domain/memory/{cortex-md-injector.js → agents-md-injector.js} +10 -7
- package/dist/domain/projects/project-store.d.ts +1 -1
- package/dist/domain/projects/project-store.js +3 -3
- package/dist/domain/remote/client-hot-reload.js +3 -1
- package/dist/domain/remote/client-manager.js +105 -126
- package/dist/domain/remote/client-ssh-tunnel.d.ts +16 -5
- package/dist/domain/remote/client-ssh-tunnel.js +12 -5
- package/dist/domain/remote/cortex-client-config.d.ts +1 -1
- package/dist/domain/remote/cortex-client-config.js +1 -1
- package/dist/domain/remote/device-file.d.ts +51 -0
- package/dist/domain/remote/device-file.js +193 -0
- package/dist/domain/remote/device-port.js +3 -0
- package/dist/domain/remote/reverse-stream.d.ts +18 -7
- package/dist/domain/remote/reverse-stream.js +19 -6
- package/dist/domain/runs/builders.js +0 -1
- package/dist/domain/runs/compact.js +0 -1
- package/dist/domain/runs/engine-spec.d.ts +11 -4
- package/dist/domain/runs/engine-spec.js +7 -4
- package/dist/domain/runs/prompt.js +16 -10
- package/dist/domain/runs/request.d.ts +0 -1
- package/dist/domain/sessions/session-hooks.d.ts +5 -12
- package/dist/domain/sessions/session-hooks.js +6 -13
- package/dist/domain/sessions/session-lifecycle.d.ts +4 -4
- package/dist/domain/sessions/session-lifecycle.js +5 -6
- package/dist/domain/sessions/session-retention.d.ts +1 -3
- package/dist/domain/sessions/session-retention.js +9 -26
- package/dist/domain/sessions/session-use.d.ts +32 -0
- package/dist/domain/sessions/session-use.js +63 -0
- package/dist/domain/sessions/session.js +6 -5
- package/dist/domain/system/server-update-check.js +29 -1
- package/dist/domain/system/update-ui-state.d.ts +32 -0
- package/dist/domain/system/update-ui-state.js +63 -0
- package/dist/domain/tasks/claim-recovery.js +2 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +10 -1
- package/dist/domain/tasks/dispatch-utils.js +46 -1
- package/dist/domain/tasks/dispatcher.js +4 -5
- package/dist/domain/tasks/mutator.d.ts +2 -2
- package/dist/domain/tasks/mutator.js +2 -2
- package/dist/domain/tasks/system/task-cli.js +2 -2
- package/dist/domain/tasks/system/task-state.js +1 -1
- package/dist/domain/threads/runner.js +3 -2
- package/dist/domain/ui-service/app-router.d.ts +54 -3
- package/dist/domain/ui-service/app-router.js +12 -14
- package/dist/domain/ui-service/input-schemas.d.ts +49 -5
- package/dist/domain/ui-service/input-schemas.js +35 -9
- package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
- package/dist/domain/ui-service/mutate/sessions.d.ts +17 -1
- package/dist/domain/ui-service/mutate/sessions.js +83 -3
- package/dist/domain/ui-service/mutate/system.d.ts +3 -1
- package/dist/domain/ui-service/mutate/system.js +13 -0
- package/dist/domain/ui-service/mutate/waitpoints.d.ts +2 -0
- package/dist/domain/ui-service/mutate/waitpoints.js +20 -0
- package/dist/domain/ui-service/platform-settings.js +1 -1
- package/dist/domain/ui-service/plugins-shared.js +1 -1
- package/dist/domain/ui-service/query/config.js +1 -1
- package/dist/domain/ui-service/query/executions.js +0 -2
- package/dist/domain/ui-service/query/machine-detail.js +3 -8
- package/dist/domain/ui-service/query/memory.js +1 -1
- package/dist/domain/ui-service/query/sessions.js +7 -0
- package/dist/domain/ui-service/query/system.d.ts +2 -1
- package/dist/domain/ui-service/query/system.js +4 -0
- package/dist/domain/ui-service/query/threads.js +1 -54
- package/dist/domain/ui-service/query/waitpoints.d.ts +30 -0
- package/dist/domain/ui-service/query/waitpoints.js +117 -0
- package/dist/domain/ui-service/query-input-schemas.d.ts +3 -0
- package/dist/domain/ui-service/query-input-schemas.js +3 -0
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +175 -50
- package/dist/domain/ui-service/types.js +1 -1
- package/dist/domain/ui-service/ui-service.js +13 -33
- package/dist/domain/waitpoints/notices.d.ts +21 -0
- package/dist/domain/waitpoints/notices.js +115 -0
- package/dist/domain/waitpoints/service.d.ts +91 -0
- package/dist/domain/waitpoints/service.js +243 -0
- package/dist/entry/app.js +39 -29
- package/dist/entry/auth-login-cli.js +1 -1
- package/dist/entry/auth-login-terminal.js +1 -1
- package/dist/entry/init-auth.js +1 -1
- package/dist/entry/init.js +6 -6
- package/dist/entry/signal-cli.d.ts +30 -0
- package/dist/entry/signal-cli.js +207 -0
- package/dist/entry/start-ui-http.d.ts +1 -1
- package/dist/entry/start-ui-http.js +5 -3
- package/dist/events/event-types.d.ts +5 -7
- package/dist/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
- package/dist/hooks/cortex-hook-api.mjs +2 -2
- package/dist/hooks/new-session-hook.mjs +2 -2
- package/dist/hooks/rules-loader.mjs +2 -2
- package/dist/hooks/status-md-guard.mjs +8 -8
- package/dist/hooks/task-status-check.mjs +18 -76
- package/dist/hooks/tasks-yaml-guard.mjs +2 -2
- package/dist/orchestration/agent-file-send.d.ts +9 -0
- package/dist/orchestration/agent-file-send.js +21 -2
- package/dist/orchestration/agent-runner.d.ts +4 -3
- package/dist/orchestration/agent-runner.js +25 -23
- package/dist/orchestration/attachments-store.d.ts +31 -0
- package/dist/orchestration/attachments-store.js +184 -0
- package/dist/orchestration/conversation-request.d.ts +30 -8
- package/dist/orchestration/conversation-request.js +62 -26
- package/dist/orchestration/edit-retry.js +2 -1
- package/dist/orchestration/interactions/ask-user-resume.js +2 -1
- package/dist/orchestration/interactions/plan-approvals.js +1 -1
- package/dist/orchestration/interactions/ui-update-prompt.d.ts +8 -0
- package/dist/orchestration/interactions/ui-update-prompt.js +47 -0
- package/dist/orchestration/outputs-store.d.ts +11 -0
- package/dist/orchestration/outputs-store.js +32 -6
- package/dist/orchestration/resume-dispatcher.js +2 -2
- package/dist/orchestration/routing/file-handler.d.ts +23 -2
- package/dist/orchestration/routing/file-handler.js +22 -5
- package/dist/orchestration/routing/webhook.js +240 -39
- package/dist/orchestration/session-compact.d.ts +3 -0
- package/dist/orchestration/session-compact.js +3 -2
- package/dist/orchestration/session-events.d.ts +6 -0
- package/dist/orchestration/session-events.js +5 -0
- package/dist/orchestration/session-gateway.d.ts +1 -1
- package/dist/orchestration/session-gateway.js +1 -0
- package/dist/orchestration/thread-executor.d.ts +2 -0
- package/dist/orchestration/thread-executor.js +11 -1
- package/dist/orchestration/thread-input.d.ts +3 -2
- package/dist/orchestration/thread-input.js +8 -9
- package/dist/orchestration/turn/turn-prep.d.ts +15 -1
- package/dist/orchestration/turn/turn-prep.js +21 -9
- package/dist/orchestration/waitpoint-ingress.d.ts +41 -0
- package/dist/orchestration/waitpoint-ingress.js +172 -0
- package/dist/orchestration/waitpoint-notifier.d.ts +21 -0
- package/dist/orchestration/waitpoint-notifier.js +119 -0
- package/dist/orchestration/waitpoint-remote-drain.d.ts +20 -0
- package/dist/orchestration/waitpoint-remote-drain.js +147 -0
- package/dist/orchestration/waitpoint-sweep.d.ts +42 -0
- package/dist/orchestration/waitpoint-sweep.js +87 -0
- package/dist/platform/adapters/feishu-image.d.ts +19 -0
- package/dist/platform/adapters/feishu-image.js +71 -0
- package/dist/platform/adapters/feishu.d.ts +2 -0
- package/dist/platform/adapters/feishu.js +26 -16
- package/dist/platform/ui-http/app-update.d.ts +11 -0
- package/dist/platform/ui-http/app-update.js +3 -0
- package/dist/platform/ui-http/listening-ports.d.ts +1 -1
- package/dist/platform/ui-http/listening-ports.js +1 -1
- package/dist/platform/ui-http/ui-session.js +1 -1
- package/dist/store/conversation-ledger-repo.d.ts +10 -19
- package/dist/store/conversation-ledger-repo.js +143 -152
- package/dist/store/execution-repo.d.ts +1 -19
- package/dist/store/execution-repo.js +1 -18
- package/dist/store/project-notes-repo.js +11 -2
- package/dist/store/prompt-migration-replacements.js +1 -1
- package/dist/store/session-registry-import.d.ts +34 -0
- package/dist/store/session-registry-import.js +182 -0
- package/dist/store/session-registry-journal.d.ts +107 -0
- package/dist/store/session-registry-journal.js +308 -19
- package/dist/store/session-registry-repo.d.ts +113 -28
- package/dist/store/session-registry-repo.js +288 -105
- package/dist/store/version-migrations.d.ts +29 -3
- package/dist/store/version-migrations.js +288 -24
- package/dist/store/waitpoint-repo.d.ts +108 -0
- package/dist/store/waitpoint-repo.js +94 -0
- package/package.json +2 -2
- package/web/dist/assets/index-CwwQNMpP.css +1 -0
- package/web/dist/assets/index-DLSfgq3o.js +444 -0
- package/web/dist/assets/{index-aHbOZSP6.js → index-DZTuqUO4.js} +1 -1
- package/web/dist/index.html +2 -2
- package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +0 -10
- package/dist/domain/executions/log-tailer.d.ts +0 -71
- package/dist/domain/executions/log-tailer.js +0 -194
- package/dist/domain/memory/cortex-md-injector.d.ts +0 -24
- package/dist/domain/memory/cortex-md-scanner.d.ts +0 -10
- package/dist/domain/memory/cortex-md-scanner.js +0 -66
- package/dist/domain/remote/cortex-client.d.ts +0 -1
- package/dist/domain/remote/cortex-client.js +0 -662
- package/dist/domain/tasks/system/cortex-run.d.ts +0 -25
- package/dist/domain/tasks/system/cortex-run.js +0 -360
- package/dist/store/session-repo.d.ts +0 -65
- package/dist/store/session-repo.js +0 -184
- package/web/dist/assets/index-BuXbCsuz.js +0 -444
- package/web/dist/assets/index-CCPxQ94C.css +0 -1
- /package/defaults/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/config/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/ideas/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/projects/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/scans/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/user/{CORTEX.md → AGENTS.md} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// input: dotenv files, live environment, atomic mutation and schema
|
|
2
2
|
// output: redacted platform snapshots and serialized credential patches
|
|
3
3
|
// pos: Platform configuration persistence and pending-state reader
|
|
4
|
-
// >>> Once updated, update this header and parent
|
|
4
|
+
// >>> Once updated, update this header and parent AGENTS.md <<<
|
|
5
5
|
import fs from 'node:fs/promises';
|
|
6
6
|
import { parse } from 'dotenv';
|
|
7
7
|
import { mutateFileAtomically } from '../../core/atomic-write.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// input: plugin catalog, settings and plugin directories
|
|
2
2
|
// output: normalized plugin entries and effective scopes
|
|
3
3
|
// pos: Shared plugin helpers for UI service
|
|
4
|
-
// >>> Once updated, update this header and parent
|
|
4
|
+
// >>> Once updated, update this header and parent AGENTS.md <<<
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import { getSettings } from '../../core/settings.js';
|
|
7
7
|
import path from 'node:path';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// input: config root, platform settings, hook registry, live locale and its source
|
|
2
2
|
// output: config snapshot with redacted platform fields and the active UI/server language
|
|
3
3
|
// pos: Config snapshot reader
|
|
4
|
-
// >>> Once updated, update this header and parent
|
|
4
|
+
// >>> Once updated, update this header and parent AGENTS.md <<<
|
|
5
5
|
import fs from 'node:fs/promises';
|
|
6
6
|
import { readPlatformSettings } from '../platform-settings.js';
|
|
7
7
|
import path from 'node:path';
|
|
@@ -61,7 +61,6 @@ export async function handleExecutionsGet(deps, params) {
|
|
|
61
61
|
tmuxName: e.dispatch.tmuxName ?? null,
|
|
62
62
|
sessionName: e.dispatch.sessionName ?? null,
|
|
63
63
|
scheduleTaskId: e.dispatch.scheduleTaskId ?? null,
|
|
64
|
-
runName: e.dispatch.runName ?? null,
|
|
65
64
|
}
|
|
66
65
|
: null,
|
|
67
66
|
metrics: {
|
|
@@ -69,7 +68,6 @@ export async function handleExecutionsGet(deps, params) {
|
|
|
69
68
|
numTurns: e.metrics?.numTurns ?? null,
|
|
70
69
|
durationS: e.metrics?.durationS ?? null,
|
|
71
70
|
},
|
|
72
|
-
gpu: e.gpu ?? null,
|
|
73
71
|
text: {
|
|
74
72
|
label: e.text?.label ?? null,
|
|
75
73
|
finalOutput: e.text?.finalOutput ?? null,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { buildProbeCommand, parseMachineProbe, PROBE_TIMEOUT_MS } from './machine-probe.js';
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* GPU row with its owning run. Process pids are deliberately NOT matched: dispatch.pid is the
|
|
6
|
-
* cortex-run launcher, not the CUDA process, so any such join would be fabricated.
|
|
7
|
-
*/
|
|
2
|
+
/** Running dispatch executions on this machine. Process pids are deliberately NOT matched against
|
|
3
|
+
* the GPU probe: dispatch.pid is the launcher, not the CUDA process, so any such join would be
|
|
4
|
+
* fabricated. */
|
|
8
5
|
function collectLiveRuns(deps, machine) {
|
|
9
6
|
return deps.executionRegistry
|
|
10
7
|
.getAll()
|
|
@@ -12,9 +9,7 @@ function collectLiveRuns(deps, machine) {
|
|
|
12
9
|
.map((exec) => ({
|
|
13
10
|
executionId: String(exec.id),
|
|
14
11
|
taskId: exec.dispatch?.taskId ?? null,
|
|
15
|
-
runName: exec.dispatch?.runName ?? null,
|
|
16
12
|
project: exec.project ?? null,
|
|
17
|
-
gpuIndices: Array.isArray(exec.gpu?.indices) ? exec.gpu.indices : [],
|
|
18
13
|
startedAt: exec.runtime?.startedAt ?? null,
|
|
19
14
|
}));
|
|
20
15
|
}
|
|
@@ -81,7 +81,7 @@ export async function handleMemoryTree(deps, params) {
|
|
|
81
81
|
return [];
|
|
82
82
|
}
|
|
83
83
|
const entries = dirents
|
|
84
|
-
.filter((e) => e.isFile() && e.name.endsWith('.md') && e.name !== 'index.md' && e.name !== '
|
|
84
|
+
.filter((e) => e.isFile() && e.name.endsWith('.md') && e.name !== 'index.md' && e.name !== 'AGENTS.md')
|
|
85
85
|
.map((e) => {
|
|
86
86
|
const st = fs.statSync(path.join(abs, e.name));
|
|
87
87
|
return { name: e.name, sizeBytes: st.size, modifiedAt: st.mtime.toISOString() };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { effectiveBackendSessionId } from '../../../store/session-registry-repo.js';
|
|
2
|
+
import { countWaitingOn } from './waitpoints.js';
|
|
2
3
|
import { sessionTotalsCarry } from '../../../store/session-totals-repo.js';
|
|
3
4
|
import { addTotalsAcc, emptyTotalsAcc, foldExecution, toSessionTotals, } from '../../../store/session-totals.js';
|
|
4
5
|
import { projectCompactHistory, projectSubagentHistory } from '../../../store/conversation-display-projection.js';
|
|
@@ -79,6 +80,11 @@ export async function handleSessionsList(deps, params) {
|
|
|
79
80
|
return null;
|
|
80
81
|
return sessionId ? (lastRunBySession.get(sessionId)?.costUsd ?? null) : null;
|
|
81
82
|
};
|
|
83
|
+
// Armed waitpoints, fetched once for the whole page (the repo read is an in-memory cache hit).
|
|
84
|
+
// Counted per session by the shared ownership rule so `waitingOn` and `waitpoints.list` can never
|
|
85
|
+
// disagree. Absent dep (fixtures / TUI) ⇒ every session reports 0.
|
|
86
|
+
const armedWaitpoints = deps.waitpointRegistry ? await deps.waitpointRegistry.listArmed() : [];
|
|
87
|
+
const waitingOnBySession = countWaitingOn(armedWaitpoints, sessions.map((s) => ({ sessionId: s.sessionId, channel: s.channel ?? null })));
|
|
82
88
|
const infos = sessions.map((s) => {
|
|
83
89
|
// Busy snapshot: the registry's single answer for this session. Snapshot + delta — this field
|
|
84
90
|
// is the queryable snapshot, the `session.status` event stream is the delta.
|
|
@@ -128,6 +134,7 @@ export async function handleSessionsList(deps, params) {
|
|
|
128
134
|
running,
|
|
129
135
|
backgroundRunning: bgHeld,
|
|
130
136
|
awaitingInput,
|
|
137
|
+
waitingOn: waitingOnBySession.get(s.sessionId) ?? 0,
|
|
131
138
|
numTurns: resolveNumTurns(s.sessionId, inTurn, state.numTurns),
|
|
132
139
|
costUsd: resolveCost(s.sessionId, inTurn),
|
|
133
140
|
// Cumulative over every finished run this session has had (plus its Agent-tool children's
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { SystemDaemonStatus, SystemDaemonStatusParams, SystemRateLimitStatus, SystemRateLimitStatusParams, SystemUsageStatus, SystemUsageStatusParams, SystemNotices, SystemNoticesParams } from '../types.js';
|
|
1
|
+
import type { SystemDaemonStatus, SystemDaemonStatusParams, SystemRateLimitStatus, SystemRateLimitStatusParams, SystemUsageStatus, SystemUsageStatusParams, SystemNotices, SystemNoticesParams, SystemUpdateStatus, SystemUpdateStatusParams } from '../types.js';
|
|
2
2
|
export declare function handleSystemDaemonStatus(_params: SystemDaemonStatusParams): Promise<SystemDaemonStatus>;
|
|
3
3
|
export declare function handleSystemRateLimitStatus(_params: SystemRateLimitStatusParams): Promise<SystemRateLimitStatus>;
|
|
4
4
|
export declare function handleSystemUsageStatus(_params: SystemUsageStatusParams): Promise<SystemUsageStatus>;
|
|
5
5
|
export declare function handleSystemNotices(params: SystemNoticesParams): Promise<SystemNotices>;
|
|
6
|
+
export declare function handleSystemUpdateStatus(_params: SystemUpdateStatusParams): Promise<SystemUpdateStatus>;
|
|
@@ -5,6 +5,7 @@ import { getThrottleState } from '../../costs/rate-limit-throttle.js';
|
|
|
5
5
|
import { getResumeCountsByProvider } from '../../costs/resume-registry.js';
|
|
6
6
|
import { usageService } from '../../costs/usage-service.js';
|
|
7
7
|
import { listSystemNotices, NOTICE_HISTORY_CAP } from '../../system/notice-history.js';
|
|
8
|
+
import { getServerUpdateStatus } from '../../system/update-ui-state.js';
|
|
8
9
|
// ── Helpers ───────────────────────────────────────────────────────
|
|
9
10
|
function formatDuration(ms) {
|
|
10
11
|
const seconds = Math.floor(ms / 1000);
|
|
@@ -134,3 +135,6 @@ export async function handleSystemUsageStatus(_params) {
|
|
|
134
135
|
export async function handleSystemNotices(params) {
|
|
135
136
|
return { entries: listSystemNotices(params.limit), cap: NOTICE_HISTORY_CAP };
|
|
136
137
|
}
|
|
138
|
+
export async function handleSystemUpdateStatus(_params) {
|
|
139
|
+
return getServerUpdateStatus();
|
|
140
|
+
}
|
|
@@ -80,7 +80,7 @@ export async function handleThreadsGet(deps, params) {
|
|
|
80
80
|
error: t.error ?? null, abortReason: t.abortReason ?? null,
|
|
81
81
|
activeAgent: t.activeAgent ?? null, activeStage: t.activeStage ?? null,
|
|
82
82
|
totalCostUsd: t.totalCostUsd ?? 0, steps, agentFlow: buildAgentFlow(t),
|
|
83
|
-
|
|
83
|
+
subtasks: buildSubtasks(deps, t),
|
|
84
84
|
children: buildChildTree(deps, t.metadata?.childThreadIds ?? [], 0, new Set([t.id])),
|
|
85
85
|
artifacts: buildArtifactRefs(t, content),
|
|
86
86
|
};
|
|
@@ -140,59 +140,6 @@ function buildAgentFlow(t) {
|
|
|
140
140
|
lastOutput: slot.lastOutput ?? null,
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
function findLaunchStep(steps, thread, startedAt) {
|
|
144
|
-
const launchedAt = Date.parse(startedAt);
|
|
145
|
-
if (!Number.isFinite(launchedAt))
|
|
146
|
-
return null;
|
|
147
|
-
const completed = steps.find((step) => {
|
|
148
|
-
const start = step.startedAt ? Date.parse(step.startedAt) : NaN;
|
|
149
|
-
const end = step.endedAt ? Date.parse(step.endedAt) : NaN;
|
|
150
|
-
return Number.isFinite(start) && Number.isFinite(end) && launchedAt >= start && launchedAt < end;
|
|
151
|
-
});
|
|
152
|
-
if (completed)
|
|
153
|
-
return completed;
|
|
154
|
-
const active = steps.find((step) => step.status === 'running');
|
|
155
|
-
if (!active)
|
|
156
|
-
return null;
|
|
157
|
-
const priorEnd = steps.reduce((latest, step) => {
|
|
158
|
-
const end = step.endedAt ? Date.parse(step.endedAt) : NaN;
|
|
159
|
-
return Number.isFinite(end) ? Math.max(latest, end) : latest;
|
|
160
|
-
}, Date.parse(thread.createdAt));
|
|
161
|
-
return launchedAt >= priorEnd ? active : null;
|
|
162
|
-
}
|
|
163
|
-
function toThreadDispatch(e, step) {
|
|
164
|
-
const startedAt = e.runtime?.startedAt || '';
|
|
165
|
-
const finishedAt = e.runtime?.endedAt || null;
|
|
166
|
-
const endMs = finishedAt ? Date.parse(finishedAt) : null;
|
|
167
|
-
return {
|
|
168
|
-
executionId: e.id,
|
|
169
|
-
status: e.status,
|
|
170
|
-
machine: e.dispatch.machine ?? null,
|
|
171
|
-
type: 'dispatch',
|
|
172
|
-
agentSlotId: step.agentSlotId,
|
|
173
|
-
stepIndex: step.stepIndex,
|
|
174
|
-
taskId: e.dispatch.taskId,
|
|
175
|
-
runName: e.dispatch.runName,
|
|
176
|
-
startedAt,
|
|
177
|
-
finishedAt,
|
|
178
|
-
durationMs: endMs ? endMs - Date.parse(startedAt) : null,
|
|
179
|
-
cost: e.metrics?.costUsd ?? null,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
// Real cortex-runs have a runName and owning task but no caller-thread field. Launch time is the
|
|
183
|
-
// remaining provenance seam: attribute only runs launched inside one of this thread's step windows.
|
|
184
|
-
function buildDispatches(deps, thread, steps) {
|
|
185
|
-
const taskId = thread.metadata?.taskId;
|
|
186
|
-
if (!taskId)
|
|
187
|
-
return [];
|
|
188
|
-
return deps.executionRegistry.getAll()
|
|
189
|
-
.filter((e) => e.dispatch?.taskId === taskId && e.dispatch?.runName)
|
|
190
|
-
.sort((a, b) => (a.runtime?.startedAt || '').localeCompare(b.runtime?.startedAt || ''))
|
|
191
|
-
.flatMap((e) => {
|
|
192
|
-
const step = findLaunchStep(steps, thread, e.runtime?.startedAt || '');
|
|
193
|
-
return step ? [toThreadDispatch(e, step)] : [];
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
143
|
function buildSubtasks(deps, thread) {
|
|
197
144
|
const taskId = thread.metadata?.taskId;
|
|
198
145
|
if (!taskId)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Waitpoint } from '../../../store/waitpoint-repo.js';
|
|
2
|
+
import type { UiServiceDeps, WaitpointInfo, WaitpointsListParams } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Does `wp` belong to the session identified by (`sessionId`, `channel`)?
|
|
5
|
+
*
|
|
6
|
+
* The union of two clauses, each covering the other's blind spot:
|
|
7
|
+
* - `owner.sessionId` — this session's own process armed it. Survives a channel rebind, since
|
|
8
|
+
* `bindChannel` never rewrites the session record's channel.
|
|
9
|
+
* - `owner.channel` — the wake will be DELIVERED here. Survives the session being recreated
|
|
10
|
+
* (`!new`, a scheduled re-run), because delivery is channel-addressed and find-or-creates a
|
|
11
|
+
* session. This clause can surface a waitpoint armed by an earlier session on the same channel;
|
|
12
|
+
* that is honest rather than wrong — its wake really will land on the current one.
|
|
13
|
+
*
|
|
14
|
+
* Kept as one exported function so `SessionInfo.waitingOn` and `waitpoints.list` can never drift.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ownsWaitpoint(wp: Waitpoint, sessionId: string, channel: string | null): boolean;
|
|
17
|
+
/** Count the armed waitpoints each of `sessions` is waiting on. One pass over a handful of records
|
|
18
|
+
* (the repo read is an in-memory cache hit and settled records are purged after 3 days), so the
|
|
19
|
+
* nested loop is cheaper than building and reconciling two indexes. */
|
|
20
|
+
export declare function countWaitingOn(armed: Waitpoint[], sessions: Array<{
|
|
21
|
+
sessionId: string;
|
|
22
|
+
channel: string | null;
|
|
23
|
+
}>): Map<string, number>;
|
|
24
|
+
/**
|
|
25
|
+
* Redacting serialiser. Built field by field, never by spreading the record: `secretHash` must not
|
|
26
|
+
* be able to leak through a field added upstream later. `signals[].data` is dropped on purpose —
|
|
27
|
+
* it is externally written and capped at 16 KB per signal, which would bloat every list response.
|
|
28
|
+
*/
|
|
29
|
+
export declare function toWaitpointInfo(wp: Waitpoint, now: number, wakeLimit: number): WaitpointInfo;
|
|
30
|
+
export declare function handleWaitpointsList(deps: UiServiceDeps, params: WaitpointsListParams): Promise<WaitpointInfo[]>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// input: UiServiceDeps + WaitpointsListParams
|
|
2
|
+
// output: handleWaitpointsList → WaitpointInfo[]; ownsWaitpoint (the ownership rule, shared with
|
|
3
|
+
// query/sessions.ts); toWaitpointInfo (the redacting serialiser)
|
|
4
|
+
// pos: query handler for 'waitpoints.list' — the operator-facing view of the waitpoints a
|
|
5
|
+
// session is still waiting on. Deliberately NOT domain/waitpoints' `publicView`: that one
|
|
6
|
+
// is written for the agent and hides exactly the fields a human needs (delivery state, wake
|
|
7
|
+
// budget, rate-limit latch). Records reach this file only through UiServiceDeps.
|
|
8
|
+
import { getSettings } from '../../../core/settings.js';
|
|
9
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
10
|
+
/**
|
|
11
|
+
* Does `wp` belong to the session identified by (`sessionId`, `channel`)?
|
|
12
|
+
*
|
|
13
|
+
* The union of two clauses, each covering the other's blind spot:
|
|
14
|
+
* - `owner.sessionId` — this session's own process armed it. Survives a channel rebind, since
|
|
15
|
+
* `bindChannel` never rewrites the session record's channel.
|
|
16
|
+
* - `owner.channel` — the wake will be DELIVERED here. Survives the session being recreated
|
|
17
|
+
* (`!new`, a scheduled re-run), because delivery is channel-addressed and find-or-creates a
|
|
18
|
+
* session. This clause can surface a waitpoint armed by an earlier session on the same channel;
|
|
19
|
+
* that is honest rather than wrong — its wake really will land on the current one.
|
|
20
|
+
*
|
|
21
|
+
* Kept as one exported function so `SessionInfo.waitingOn` and `waitpoints.list` can never drift.
|
|
22
|
+
*/
|
|
23
|
+
export function ownsWaitpoint(wp, sessionId, channel) {
|
|
24
|
+
if (sessionId && wp.owner.sessionId === sessionId)
|
|
25
|
+
return true;
|
|
26
|
+
if (channel && wp.owner.channel === channel)
|
|
27
|
+
return true;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
/** Count the armed waitpoints each of `sessions` is waiting on. One pass over a handful of records
|
|
31
|
+
* (the repo read is an in-memory cache hit and settled records are purged after 3 days), so the
|
|
32
|
+
* nested loop is cheaper than building and reconciling two indexes. */
|
|
33
|
+
export function countWaitingOn(armed, sessions) {
|
|
34
|
+
const out = new Map();
|
|
35
|
+
for (const s of sessions) {
|
|
36
|
+
if (armed.length === 0) {
|
|
37
|
+
out.set(s.sessionId, 0);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
let n = 0;
|
|
41
|
+
for (const wp of armed)
|
|
42
|
+
if (ownsWaitpoint(wp, s.sessionId, s.channel))
|
|
43
|
+
n += 1;
|
|
44
|
+
out.set(s.sessionId, n);
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
/** `quorum.need` is collapsed to a number at creation, but the stored type still permits `'all'`
|
|
49
|
+
* (a hand-edited or pre-existing waitpoints.json). Same fallback every other reader uses. */
|
|
50
|
+
function needCount(wp) {
|
|
51
|
+
return typeof wp.quorum.need === 'number' ? wp.quorum.need : wp.quorum.members.length || 1;
|
|
52
|
+
}
|
|
53
|
+
function toSignalInfo(s) {
|
|
54
|
+
return {
|
|
55
|
+
at: s.at,
|
|
56
|
+
status: s.status,
|
|
57
|
+
member: s.member ?? null,
|
|
58
|
+
message: s.message ?? null,
|
|
59
|
+
source: s.source,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Redacting serialiser. Built field by field, never by spreading the record: `secretHash` must not
|
|
64
|
+
* be able to leak through a field added upstream later. `signals[].data` is dropped on purpose —
|
|
65
|
+
* it is externally written and capped at 16 KB per signal, which would bloat every list response.
|
|
66
|
+
*/
|
|
67
|
+
export function toWaitpointInfo(wp, now, wakeLimit) {
|
|
68
|
+
const windowStart = now - HOUR_MS;
|
|
69
|
+
return {
|
|
70
|
+
id: wp.id,
|
|
71
|
+
label: wp.label,
|
|
72
|
+
intent: wp.intent,
|
|
73
|
+
state: wp.state,
|
|
74
|
+
emitFrom: wp.emitFrom.kind === 'device'
|
|
75
|
+
? { kind: 'device', device: wp.emitFrom.device }
|
|
76
|
+
: { kind: 'local' },
|
|
77
|
+
quorum: {
|
|
78
|
+
need: needCount(wp),
|
|
79
|
+
got: wp.quorum.got.length,
|
|
80
|
+
members: [...wp.quorum.members],
|
|
81
|
+
},
|
|
82
|
+
failFast: wp.failFast,
|
|
83
|
+
fires: wp.fires,
|
|
84
|
+
maxSignals: wp.maxSignals,
|
|
85
|
+
createdAt: wp.createdAt,
|
|
86
|
+
expiresAt: wp.expiresAt,
|
|
87
|
+
signals: wp.signals.map(toSignalInfo),
|
|
88
|
+
delivery: {
|
|
89
|
+
pending: wp.delivery.pending,
|
|
90
|
+
attempts: wp.delivery.attempts,
|
|
91
|
+
lastError: wp.delivery.lastError ?? null,
|
|
92
|
+
lastAt: wp.delivery.lastAt ?? null,
|
|
93
|
+
},
|
|
94
|
+
wakesLastHour: wp.wakes.filter((t) => t > windowStart).length,
|
|
95
|
+
wakeLimit,
|
|
96
|
+
rateLimited: wp.rateLimitNotified === true,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export async function handleWaitpointsList(deps, params) {
|
|
100
|
+
if (!deps.waitpointRegistry)
|
|
101
|
+
return [];
|
|
102
|
+
const sessionId = String(params.sessionId || '');
|
|
103
|
+
if (!sessionId)
|
|
104
|
+
return [];
|
|
105
|
+
// The channel half of the ownership rule has to be resolved here: SessionInfo carries no channel,
|
|
106
|
+
// so the client cannot compute this match and must not try to guess it (`web:<id>` only holds for
|
|
107
|
+
// sessions created directly — a Slack, Feishu or scheduled session has a different conduit).
|
|
108
|
+
const record = await deps.sessionStore.getById(sessionId);
|
|
109
|
+
const channel = record?.channel ?? null;
|
|
110
|
+
const armed = await deps.waitpointRegistry.listArmed();
|
|
111
|
+
const mine = armed.filter((wp) => ownsWaitpoint(wp, sessionId, channel));
|
|
112
|
+
const now = Date.now();
|
|
113
|
+
const wakeLimit = getSettings().waitpointMaxWakesPerHour;
|
|
114
|
+
// Soonest to expire first: what is about to time out is what a human needs to see.
|
|
115
|
+
mine.sort((a, b) => a.expiresAt - b.expiresAt);
|
|
116
|
+
return mine.map((wp) => toWaitpointInfo(wp, now, wakeLimit));
|
|
117
|
+
}
|
|
@@ -62,6 +62,9 @@ export declare const commissionsGetInput: z.ZodObject<{
|
|
|
62
62
|
export declare const commissionsDecisionsInput: z.ZodObject<{
|
|
63
63
|
commissionId: z.ZodString;
|
|
64
64
|
}, z.core.$strip>;
|
|
65
|
+
export declare const waitpointsListInput: z.ZodObject<{
|
|
66
|
+
sessionId: z.ZodString;
|
|
67
|
+
}, z.core.$strip>;
|
|
65
68
|
export declare const executionsListInput: z.ZodObject<{
|
|
66
69
|
status: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
67
70
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
@@ -51,6 +51,9 @@ export const commissionsGetInput = z.object({
|
|
|
51
51
|
export const commissionsDecisionsInput = z.object({
|
|
52
52
|
commissionId: z.string(),
|
|
53
53
|
});
|
|
54
|
+
export const waitpointsListInput = z.object({
|
|
55
|
+
sessionId: z.string().min(1),
|
|
56
|
+
});
|
|
54
57
|
export const executionsListInput = z.object({
|
|
55
58
|
status: z.array(z.string()).optional(),
|
|
56
59
|
limit: z.number().optional(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// input: tRPC core and procedure error shapes
|
|
2
2
|
// output: router, publicProcedure and createCallerFactory
|
|
3
3
|
// pos: UI router foundation with credential-error redaction
|
|
4
|
-
// >>> Once updated, update this header and parent
|
|
4
|
+
// >>> Once updated, update this header and parent AGENTS.md <<<
|
|
5
5
|
import { initTRPC } from '@trpc/server';
|
|
6
6
|
/**
|
|
7
7
|
* Keepalive for the SSE subscription that carries the whole UI's live state.
|