@cortex-agent/server 2026.9.15 → 2026.9.25
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/config/thread-templates/agents/creative.json +17 -0
- 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-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/prompts/systemPrompts/creative.md +13 -0
- package/defaults/prompts/systemPrompts/direct.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 +12 -0
- package/dist/agent-adapter/claude/adapter.js +19 -1
- package/dist/agent-adapter/claude/hooks-builder.js +2 -2
- package/dist/agent-adapter/claude/spawn-args.d.ts +7 -0
- package/dist/agent-adapter/claude/spawn-args.js +14 -0
- 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/child-runner.d.ts +4 -2
- package/dist/agent-adapter/pi/child-runner.js +5 -1
- package/dist/agent-adapter/pi/event-parser.d.ts +3 -2
- package/dist/agent-adapter/pi/event-parser.js +46 -2
- package/dist/agent-adapter/pi/extensions.d.ts +7 -1
- package/dist/agent-adapter/pi/extensions.js +10 -3
- package/dist/agent-adapter/pi/mcp-bridge.js +8 -8
- package/dist/agent-adapter/pi/pi-session.js +5 -0
- package/dist/agent-adapter/pi/runtime.js +3 -0
- package/dist/agent-adapter/pi/session-options.js +5 -1
- package/dist/agent-adapter/pi/subagent.d.ts +15 -3
- package/dist/agent-adapter/pi/subagent.js +18 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +6 -1
- package/dist/agent-adapter/pi/tool-shims.js +34 -1
- package/dist/agent-adapter/types.d.ts +6 -0
- package/dist/core/agents/subagent/types.d.ts +3 -0
- package/dist/core/config-generator.js +17 -2
- package/dist/core/debug-mode.d.ts +11 -10
- package/dist/core/debug-mode.js +12 -18
- package/dist/core/exec-async.d.ts +26 -0
- package/dist/core/exec-async.js +47 -0
- package/dist/core/locales/en.d.ts +14 -1
- package/dist/core/locales/slices/commands.d.ts +12 -1
- package/dist/core/locales/slices/commands.js +24 -2
- package/dist/core/locales/slices/startup.d.ts +2 -0
- package/dist/core/locales/slices/startup.js +4 -0
- package/dist/core/mcp-tool-gate.js +1 -0
- 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/rebuild-progress.d.ts +58 -0
- package/dist/core/rebuild-progress.js +103 -0
- package/dist/core/resilient-watch.js +5 -3
- package/dist/core/run-registry.d.ts +7 -0
- package/dist/core/run-registry.js +6 -0
- package/dist/core/settings-spec.d.ts +21 -0
- package/dist/core/settings-spec.js +28 -1
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/types/thread-types.d.ts +23 -4
- package/dist/core/utils.d.ts +1 -1
- package/dist/core/utils.js +1 -1
- package/dist/domain/agents/agent-state.d.ts +7 -0
- package/dist/domain/agents/agent-state.js +9 -1
- package/dist/domain/agents/agent-switch.d.ts +38 -0
- package/dist/domain/agents/agent-switch.js +106 -0
- package/dist/domain/agents/config.d.ts +20 -2
- package/dist/domain/agents/config.js +58 -4
- package/dist/domain/agents/index.d.ts +1 -0
- package/dist/domain/agents/index.js +1 -0
- package/dist/domain/agents/profile-manager.d.ts +6 -0
- package/dist/domain/agents/profile-manager.js +14 -1
- package/dist/domain/executions/registry.d.ts +3 -2
- package/dist/domain/executions/registry.js +84 -10
- 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/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/plugins/runtime.js +1 -1
- package/dist/domain/plugins/skill-projection.d.ts +8 -2
- package/dist/domain/plugins/skill-projection.js +76 -19
- package/dist/domain/projects/project-store.d.ts +1 -1
- package/dist/domain/projects/project-store.js +3 -3
- package/dist/domain/remote/client-bootstrap.js +1 -1
- package/dist/domain/remote/client-hot-reload.d.ts +1 -1
- package/dist/domain/remote/client-hot-reload.js +30 -24
- package/dist/domain/remote/client-manager.js +39 -119
- 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/engine-spec.js +4 -0
- package/dist/domain/runs/request.d.ts +6 -0
- package/dist/domain/runs/run.js +1 -0
- package/dist/domain/runs/spec-loader.d.ts +4 -3
- package/dist/domain/runs/spec-loader.js +4 -3
- package/dist/domain/scheduling/jobs/sync-public.js +6 -6
- package/dist/domain/scheduling/scheduler.js +14 -12
- package/dist/domain/sessions/session-lifecycle.d.ts +5 -0
- package/dist/domain/sessions/session-lifecycle.js +13 -1
- package/dist/domain/system/rebuild-hold.d.ts +44 -0
- package/dist/domain/system/rebuild-hold.js +91 -0
- package/dist/domain/system/server-update-check.d.ts +2 -1
- package/dist/domain/system/server-update-check.js +15 -13
- package/dist/domain/tasks/archiver.js +21 -13
- 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 +62 -61
- package/dist/domain/tasks/system/task-cli.js +2 -2
- package/dist/domain/tasks/system/task-completion.d.ts +7 -2
- package/dist/domain/tasks/system/task-completion.js +69 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -1
- package/dist/domain/tasks/system/task-lifecycle-edit.js +21 -2
- package/dist/domain/tasks/system/task-lock.d.ts +23 -0
- package/dist/domain/tasks/system/task-lock.js +29 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +14 -1
- package/dist/domain/tasks/system/task-mutations.js +25 -2
- package/dist/domain/tasks/system/task-state.d.ts +12 -1
- package/dist/domain/tasks/system/task-state.js +20 -3
- package/dist/domain/threads/prompt-builder.d.ts +9 -6
- package/dist/domain/threads/prompt-builder.js +28 -10
- package/dist/domain/threads/runner.js +10 -4
- package/dist/domain/threads/state-machine.js +15 -11
- package/dist/domain/threads/template-loader.js +6 -4
- package/dist/domain/threads/template-validate.d.ts +43 -6
- package/dist/domain/threads/template-validate.js +12 -0
- package/dist/domain/ui-service/app-router.d.ts +34 -3
- package/dist/domain/ui-service/app-router.js +9 -14
- package/dist/domain/ui-service/input-schemas.d.ts +28 -5
- package/dist/domain/ui-service/input-schemas.js +24 -9
- package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
- package/dist/domain/ui-service/mutate/sessions.d.ts +6 -1
- package/dist/domain/ui-service/mutate/sessions.js +54 -0
- package/dist/domain/ui-service/mutate/tasks.js +4 -3
- 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 +20 -2
- 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 +29 -35
- package/dist/domain/ui-service/query/sessions.js +96 -12
- package/dist/domain/ui-service/query/system.js +19 -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 +4 -0
- package/dist/domain/ui-service/query-input-schemas.js +5 -0
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +229 -51
- package/dist/domain/ui-service/types.js +1 -1
- package/dist/domain/ui-service/ui-service.js +8 -31
- 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 +52 -11
- package/dist/entry/auth-login-cli.js +1 -1
- package/dist/entry/auth-login-terminal.js +1 -1
- package/dist/entry/daemon-notice.d.ts +10 -1
- package/dist/entry/daemon-notice.js +16 -1
- package/dist/entry/daemon.d.ts +43 -2
- package/dist/entry/daemon.js +163 -9
- 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 +2 -2
- package/dist/events/event-types.d.ts +0 -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 +3 -2
- package/dist/orchestration/agent-runner.js +33 -12
- package/dist/orchestration/attachments-store.d.ts +31 -0
- package/dist/orchestration/attachments-store.js +184 -0
- package/dist/orchestration/conversation-request.d.ts +37 -0
- package/dist/orchestration/conversation-request.js +91 -22
- package/dist/orchestration/interactions/plan-approvals.js +1 -1
- package/dist/orchestration/mid-turn-inject.d.ts +3 -0
- package/dist/orchestration/mid-turn-inject.js +9 -4
- package/dist/orchestration/outputs-store.d.ts +11 -0
- package/dist/orchestration/outputs-store.js +32 -6
- package/dist/orchestration/resume-dispatcher.js +4 -2
- package/dist/orchestration/routing/commands/mode.js +114 -63
- 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 +193 -39
- 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 +24 -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 +19 -8
- package/dist/orchestration/turn/turn.js +1 -0
- 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/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-display-projection.d.ts +9 -1
- package/dist/store/conversation-display-projection.js +13 -6
- package/dist/store/conversation-history-reader.d.ts +19 -0
- package/dist/store/conversation-history-reader.js +163 -44
- package/dist/store/conversation-history-repo.d.ts +37 -10
- package/dist/store/conversation-history-repo.js +161 -139
- package/dist/store/conversation-ledger-repo.js +1 -1
- 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.js +1 -1
- package/dist/store/session-registry-journal.d.ts +4 -0
- package/dist/store/session-registry-journal.js +5 -1
- package/dist/store/session-registry-repo.d.ts +2 -1
- package/dist/store/session-registry-repo.js +3 -1
- package/dist/store/task-repo.d.ts +6 -3
- package/dist/store/task-repo.js +26 -10
- package/dist/store/version-migrations.d.ts +13 -3
- package/dist/store/version-migrations.js +254 -24
- package/dist/store/waitpoint-repo.d.ts +108 -0
- package/dist/store/waitpoint-repo.js +94 -0
- package/package.json +3 -2
- package/web/dist/AGENTS.md +10 -0
- package/web/dist/assets/index-B1dBi8Za.css +1 -0
- package/web/dist/assets/{index-CEZ0DSei.js → index-BAeLybF0.js} +1 -1
- package/web/dist/assets/index-BcQI8Fh5.js +445 -0
- package/web/dist/index.html +12 -4
- package/web/dist/theme.css +211 -40
- 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/web/dist/assets/index-CRDJo39X.css +0 -1
- package/web/dist/assets/index-DjuPJVZE.js +0 -444
- /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,194 +0,0 @@
|
|
|
1
|
-
// input: a resolved LogLocation (local fs path or remote device+path) per running executionId
|
|
2
|
-
// output: { ExecutionLogTailer, executionLogTailer, resolveExecutionLogLocation, LogLocation, LogReader }
|
|
3
|
-
// — ref-counted live tail of a running cortex-run/dispatch output.log, publishing bounded
|
|
4
|
-
// `execution.log` EventBus events { executionId, seq, lines, dropped? }.
|
|
5
|
-
// pos: domain/executions layer (L3). The genuinely-new engine for B2 live log streaming.
|
|
6
|
-
// RED LINE: uses only the existing single-shot client actions (fs locally, `bash` remotely) —
|
|
7
|
-
// no client WS protocol change, no client redeploy.
|
|
8
|
-
import * as fs from 'node:fs';
|
|
9
|
-
import * as path from 'node:path';
|
|
10
|
-
import { createLogger } from '../../core/log.js';
|
|
11
|
-
import { DATA_DIR } from '../../core/paths.js';
|
|
12
|
-
import { getExecution as registryGetExecution } from '../executions/registry.js';
|
|
13
|
-
import { getLocalMachine } from '../tasks/dispatch-utils.js';
|
|
14
|
-
import { sendCommand } from '../remote/client-manager.js';
|
|
15
|
-
const log = createLogger('execution-log-tailer');
|
|
16
|
-
const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
17
|
-
const DEFAULT_MAX_BUFFER_LINES = 1000;
|
|
18
|
-
const DEFAULT_MAX_BUFFER_BYTES = 256 * 1024;
|
|
19
|
-
const DEFAULT_MAX_READ_BYTES = 64 * 1024;
|
|
20
|
-
// --- Default readers (single-shot client actions only) ---
|
|
21
|
-
function defaultLocalRead(p, offset, maxReadBytes) {
|
|
22
|
-
let size;
|
|
23
|
-
try {
|
|
24
|
-
size = fs.statSync(p).size;
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return { chunk: '', nextOffset: offset };
|
|
28
|
-
}
|
|
29
|
-
const start = size < offset ? 0 : offset; // shrink ⇒ rotated/truncated, restart from head
|
|
30
|
-
if (size <= start)
|
|
31
|
-
return { chunk: '', nextOffset: size };
|
|
32
|
-
const len = Math.min(size - start, maxReadBytes);
|
|
33
|
-
const fd = fs.openSync(p, 'r');
|
|
34
|
-
try {
|
|
35
|
-
const buf = Buffer.allocUnsafe(len);
|
|
36
|
-
const bytesRead = fs.readSync(fd, buf, 0, len, start);
|
|
37
|
-
return { chunk: buf.subarray(0, bytesRead).toString('utf8'), nextOffset: start + bytesRead };
|
|
38
|
-
}
|
|
39
|
-
finally {
|
|
40
|
-
fs.closeSync(fd);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async function defaultRemoteRead(device, p, offset, maxReadBytes) {
|
|
44
|
-
const quoted = `'${p.replace(/'/g, `'\\''`)}'`;
|
|
45
|
-
const cmd = `tail -c +${offset + 1} -- ${quoted} 2>/dev/null | head -c ${maxReadBytes}`;
|
|
46
|
-
const res = await sendCommand(device, { action: 'bash', params: { command: cmd }, timeout: 30_000 });
|
|
47
|
-
const chunk = res && typeof res.stdout === 'string' ? res.stdout : '';
|
|
48
|
-
return { chunk, nextOffset: offset + Buffer.byteLength(chunk, 'utf8') };
|
|
49
|
-
}
|
|
50
|
-
function makeDefaultReader(maxReadBytes) {
|
|
51
|
-
return (loc, offset) => loc.kind === 'local'
|
|
52
|
-
? Promise.resolve(defaultLocalRead(loc.path, offset, maxReadBytes))
|
|
53
|
-
: defaultRemoteRead(loc.device, loc.path, offset, maxReadBytes);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Registry-only resolution of a running execution's log location (B2-C). The cortex-run run name
|
|
57
|
-
* is persisted on `dispatch.runName` at launch, so the executionId alone is sufficient: the run's
|
|
58
|
-
* output.log is `<tmpBaseDir>/<runName>/output.log`, and local-vs-remote is decided by
|
|
59
|
-
* `dispatch.machine`. Returns null for an unknown id or one with no runName (nothing to tail).
|
|
60
|
-
*/
|
|
61
|
-
export function resolveExecutionLogLocation(executionId, opts = {}) {
|
|
62
|
-
const get = opts.getExecution ?? registryGetExecution;
|
|
63
|
-
const rec = get(executionId);
|
|
64
|
-
const runName = rec?.dispatch?.runName ?? null;
|
|
65
|
-
if (!runName)
|
|
66
|
-
return null;
|
|
67
|
-
const base = opts.tmpBaseDir ?? path.join(DATA_DIR, 'tmp', 'cortex-run');
|
|
68
|
-
const logPath = path.join(base, runName, 'output.log');
|
|
69
|
-
const machine = rec.dispatch?.machine ?? null;
|
|
70
|
-
const local = opts.localMachine ?? getLocalMachine();
|
|
71
|
-
if (!machine || machine === 'local' || machine === local) {
|
|
72
|
-
return { kind: 'local', path: logPath };
|
|
73
|
-
}
|
|
74
|
-
return { kind: 'remote', device: machine, path: logPath };
|
|
75
|
-
}
|
|
76
|
-
export class ExecutionLogTailer {
|
|
77
|
-
states = new Map();
|
|
78
|
-
bus = null;
|
|
79
|
-
read;
|
|
80
|
-
pollIntervalMs;
|
|
81
|
-
maxBufferLines;
|
|
82
|
-
maxBufferBytes;
|
|
83
|
-
constructor(opts = {}) {
|
|
84
|
-
this.read = opts.read ?? makeDefaultReader(opts.maxReadBytes ?? DEFAULT_MAX_READ_BYTES);
|
|
85
|
-
this.pollIntervalMs = opts.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
86
|
-
this.maxBufferLines = opts.maxBufferLines ?? DEFAULT_MAX_BUFFER_LINES;
|
|
87
|
-
this.maxBufferBytes = opts.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;
|
|
88
|
-
}
|
|
89
|
-
setBus(bus) {
|
|
90
|
-
this.bus = bus;
|
|
91
|
-
}
|
|
92
|
-
/** Current subscriber ref-count for an execution (0 if not tailing). */
|
|
93
|
-
refCount(executionId) {
|
|
94
|
-
return this.states.get(executionId)?.refCount ?? 0;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Register interest in an execution's live log. Ref-counted: the first call opens the tail
|
|
98
|
-
* (and starts the poll timer); subsequent calls only bump the count. `location` is supplied by
|
|
99
|
-
* the caller (resolveExecutionLogLocation is the registry-backed helper).
|
|
100
|
-
*/
|
|
101
|
-
startTail(executionId, location) {
|
|
102
|
-
const existing = this.states.get(executionId);
|
|
103
|
-
if (existing) {
|
|
104
|
-
existing.refCount++;
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const state = {
|
|
108
|
-
location, refCount: 1, offset: 0, carry: '', buffer: [], dropped: 0, seq: 0, timer: null, reading: false,
|
|
109
|
-
};
|
|
110
|
-
this.states.set(executionId, state);
|
|
111
|
-
if (this.pollIntervalMs > 0) {
|
|
112
|
-
state.timer = setInterval(() => { void this.pollOnce(executionId); }, this.pollIntervalMs);
|
|
113
|
-
state.timer.unref?.();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/** Release interest. The last release tears down the underlying tail (timer + offset state). */
|
|
117
|
-
stopTail(executionId) {
|
|
118
|
-
const state = this.states.get(executionId);
|
|
119
|
-
if (!state)
|
|
120
|
-
return;
|
|
121
|
-
state.refCount--;
|
|
122
|
-
if (state.refCount > 0)
|
|
123
|
-
return;
|
|
124
|
-
if (state.timer)
|
|
125
|
-
clearInterval(state.timer);
|
|
126
|
-
this.states.delete(executionId);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Read and publish one increment. Public so the poll timer and tests share one path.
|
|
130
|
-
* No-op when the execution is not tailing, no bus is wired, or a read is already in flight.
|
|
131
|
-
*/
|
|
132
|
-
async pollOnce(executionId) {
|
|
133
|
-
const state = this.states.get(executionId);
|
|
134
|
-
if (!state || !this.bus || state.reading)
|
|
135
|
-
return;
|
|
136
|
-
state.reading = true;
|
|
137
|
-
try {
|
|
138
|
-
const { chunk, nextOffset } = await this.read(state.location, state.offset);
|
|
139
|
-
if (!this.states.has(executionId))
|
|
140
|
-
return; // torn down while awaiting
|
|
141
|
-
state.offset = nextOffset;
|
|
142
|
-
if (!chunk)
|
|
143
|
-
return;
|
|
144
|
-
this.ingest(state, chunk);
|
|
145
|
-
this.flush(executionId, state);
|
|
146
|
-
}
|
|
147
|
-
catch (err) {
|
|
148
|
-
log.warn(`tail read failed for ${executionId}: ${err.message}`);
|
|
149
|
-
}
|
|
150
|
-
finally {
|
|
151
|
-
state.reading = false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
/** Split a chunk into complete lines, holding a trailing partial line for the next read. */
|
|
155
|
-
ingest(state, chunk) {
|
|
156
|
-
const parts = (state.carry + chunk).split('\n');
|
|
157
|
-
state.carry = parts.pop() ?? '';
|
|
158
|
-
for (const line of parts)
|
|
159
|
-
state.buffer.push(line);
|
|
160
|
-
this.enforceBound(state);
|
|
161
|
-
}
|
|
162
|
-
/** Drop-oldest until within the line AND byte caps, accumulating the drop count. */
|
|
163
|
-
enforceBound(state) {
|
|
164
|
-
if (state.buffer.length > this.maxBufferLines) {
|
|
165
|
-
const drop = state.buffer.length - this.maxBufferLines;
|
|
166
|
-
state.buffer.splice(0, drop);
|
|
167
|
-
state.dropped += drop;
|
|
168
|
-
}
|
|
169
|
-
let bytes = 0;
|
|
170
|
-
for (const l of state.buffer)
|
|
171
|
-
bytes += Buffer.byteLength(l, 'utf8');
|
|
172
|
-
while (state.buffer.length > 0 && bytes > this.maxBufferBytes) {
|
|
173
|
-
bytes -= Buffer.byteLength(state.buffer.shift(), 'utf8');
|
|
174
|
-
state.dropped += 1;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
flush(executionId, state) {
|
|
178
|
-
if (state.buffer.length === 0)
|
|
179
|
-
return;
|
|
180
|
-
const lines = state.buffer;
|
|
181
|
-
const dropped = state.dropped;
|
|
182
|
-
state.buffer = [];
|
|
183
|
-
state.dropped = 0;
|
|
184
|
-
this.bus.publish({
|
|
185
|
-
type: 'execution.log',
|
|
186
|
-
executionId,
|
|
187
|
-
seq: state.seq++,
|
|
188
|
-
lines,
|
|
189
|
-
...(dropped > 0 ? { dropped } : {}),
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/** Process-wide singleton, wired to the EventBus in entry/app.ts. */
|
|
194
|
-
export const executionLogTailer = new ExecutionLogTailer();
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface CortexMDEntry {
|
|
2
|
-
path: string;
|
|
3
|
-
content: string;
|
|
4
|
-
mtimeMs: number;
|
|
5
|
-
deviceId?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface CortexMDBlock {
|
|
8
|
-
type: 'text';
|
|
9
|
-
text: string;
|
|
10
|
-
}
|
|
11
|
-
export interface CortexMDInjectorOptions {
|
|
12
|
-
sessionId?: string;
|
|
13
|
-
cacheDir?: string;
|
|
14
|
-
cacheFile?: string | null;
|
|
15
|
-
}
|
|
16
|
-
export declare class CortexMDInjector {
|
|
17
|
-
private readonly memoryCache;
|
|
18
|
-
private readonly cacheFile;
|
|
19
|
-
constructor(options?: CortexMDInjectorOptions);
|
|
20
|
-
private transact;
|
|
21
|
-
buildBlocks(device: string, entries: CortexMDEntry[], markOnlyPaths?: Set<string>): CortexMDBlock[];
|
|
22
|
-
private formatBlock;
|
|
23
|
-
}
|
|
24
|
-
export declare function getDefaultCortexInjector(): CortexMDInjector;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface CortexMDEntry {
|
|
2
|
-
path: string;
|
|
3
|
-
content: string;
|
|
4
|
-
mtimeMs: number;
|
|
5
|
-
deviceId?: string;
|
|
6
|
-
}
|
|
7
|
-
/** Walk from the directory containing `targetFilePath` up to the filesystem root,
|
|
8
|
-
* collecting CORTEX.md and CORTEX.local.md at each level. Also appends the
|
|
9
|
-
* remote user's ~/.cortex/CORTEX.md if present. Returns leaf→root order. */
|
|
10
|
-
export declare function scanCortexMDChain(targetFilePath: string): CortexMDEntry[];
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import * as os from 'os';
|
|
4
|
-
const CORTEX_MD_NAMES = ['CORTEX.md', 'CORTEX.local.md'];
|
|
5
|
-
const DEVICE_ID = os.hostname();
|
|
6
|
-
const MAX_FILE_SIZE = 200 * 1024;
|
|
7
|
-
const MAX_DEPTH = 20;
|
|
8
|
-
function tryReadEntry(filePath) {
|
|
9
|
-
try {
|
|
10
|
-
const stat = fs.statSync(filePath, { throwIfNoEntry: false });
|
|
11
|
-
if (!stat || !stat.isFile())
|
|
12
|
-
return null;
|
|
13
|
-
if (stat.size > MAX_FILE_SIZE)
|
|
14
|
-
return null;
|
|
15
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
16
|
-
return { path: filePath, content, mtimeMs: stat.mtimeMs, deviceId: DEVICE_ID };
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** Walk from the directory containing `targetFilePath` up to the filesystem root,
|
|
23
|
-
* collecting CORTEX.md and CORTEX.local.md at each level. Also appends the
|
|
24
|
-
* remote user's ~/.cortex/CORTEX.md if present. Returns leaf→root order. */
|
|
25
|
-
export function scanCortexMDChain(targetFilePath) {
|
|
26
|
-
const entries = [];
|
|
27
|
-
const seen = new Set();
|
|
28
|
-
let dir;
|
|
29
|
-
try {
|
|
30
|
-
dir = path.dirname(path.resolve(targetFilePath));
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return entries;
|
|
34
|
-
}
|
|
35
|
-
for (let depth = 0; depth < MAX_DEPTH; depth++) {
|
|
36
|
-
for (const name of CORTEX_MD_NAMES) {
|
|
37
|
-
const p = path.join(dir, name);
|
|
38
|
-
if (seen.has(p))
|
|
39
|
-
continue;
|
|
40
|
-
seen.add(p);
|
|
41
|
-
const entry = tryReadEntry(p);
|
|
42
|
-
if (entry)
|
|
43
|
-
entries.push(entry);
|
|
44
|
-
}
|
|
45
|
-
const parent = path.dirname(dir);
|
|
46
|
-
if (parent === dir)
|
|
47
|
-
break;
|
|
48
|
-
dir = parent;
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
const cortexHome = process.env.CORTEX_HOME
|
|
52
|
-
? path.resolve(process.env.CORTEX_HOME)
|
|
53
|
-
: path.join(os.homedir(), '.cortex');
|
|
54
|
-
const homeCortex = path.join(cortexHome, 'CORTEX.md');
|
|
55
|
-
if (!seen.has(homeCortex)) {
|
|
56
|
-
seen.add(homeCortex);
|
|
57
|
-
const entry = tryReadEntry(homeCortex);
|
|
58
|
-
if (entry)
|
|
59
|
-
entries.push(entry);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
// homedir unavailable — skip
|
|
64
|
-
}
|
|
65
|
-
return entries;
|
|
66
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|