@cortex-agent/server 2026.9.15 → 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-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/hooks-builder.js +2 -2
- package/dist/agent-adapter/claude/spawn-args.js +4 -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/types.d.ts +1 -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/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/utils.d.ts +1 -1
- package/dist/core/utils.js +1 -1
- 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/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 +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/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 -1
- package/dist/domain/ui-service/app-router.d.ts +24 -3
- package/dist/domain/ui-service/app-router.js +8 -14
- package/dist/domain/ui-service/input-schemas.d.ts +17 -5
- package/dist/domain/ui-service/input-schemas.js +13 -9
- package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
- package/dist/domain/ui-service/mutate/sessions.d.ts +5 -1
- package/dist/domain/ui-service/mutate/sessions.js +14 -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/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 +133 -49
- package/dist/domain/ui-service/types.js +1 -1
- package/dist/domain/ui-service/ui-service.js +7 -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 +29 -7
- 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 +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 +17 -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 +4 -0
- package/dist/orchestration/conversation-request.js +13 -6
- package/dist/orchestration/interactions/plan-approvals.js +1 -1
- package/dist/orchestration/outputs-store.d.ts +11 -0
- package/dist/orchestration/outputs-store.js +32 -6
- 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 +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 +19 -8
- 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-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.js +1 -1
- package/dist/store/session-registry-repo.js +1 -1
- 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 +2 -2
- package/web/dist/assets/{index-CRDJo39X.css → index-CwwQNMpP.css} +1 -1
- package/web/dist/assets/index-DLSfgq3o.js +444 -0
- package/web/dist/assets/{index-CEZ0DSei.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/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
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// input: a local file a Feishu send is about to carry
|
|
2
|
+
// output: an image_key when Feishu can show it inline in the chat, null when it has to go as a file
|
|
3
|
+
// pos: platform/adapters — shared by the Feishu adapter's `uploadFile` and the `feishu_send_file`
|
|
4
|
+
// MCP tool, the two independent implementations of "send this file to Feishu". Both used to
|
|
5
|
+
// call `im/v1/files` unconditionally, so a screenshot the agent produced arrived as a
|
|
6
|
+
// download card: the user had to tap it to see their own picture, and it never previewed in
|
|
7
|
+
// a notification or on mobile. `im/v1/images` was never called at all.
|
|
8
|
+
import { createReadStream, promises as fs } from 'fs';
|
|
9
|
+
import { sniffImageMime } from '../../core/media-types.js';
|
|
10
|
+
import { createLogger } from '../../core/log.js';
|
|
11
|
+
const log = createLogger('feishu-image');
|
|
12
|
+
/** Feishu rejects an image upload above 10 MB (im/v1/images). Anything larger goes as a file. */
|
|
13
|
+
export const FEISHU_IMAGE_MAX_BYTES = 10 * 1024 * 1024;
|
|
14
|
+
/** Bytes read to identify the file's real type. */
|
|
15
|
+
const SNIFF_BYTES = 16;
|
|
16
|
+
/** The formats Feishu renders inline in a chat. Deliberately a subset of what it accepts: a format
|
|
17
|
+
* we cannot identify from its first bytes is safer as a file than as a rejected upload. */
|
|
18
|
+
const INLINE_IMAGE_MIMES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp']);
|
|
19
|
+
/**
|
|
20
|
+
* The mime Feishu would show inline for this file, or null when it must be sent as a file.
|
|
21
|
+
*
|
|
22
|
+
* Decided from the bytes, not the extension: the agent writes `chart.png` with whatever its plotting
|
|
23
|
+
* library produced, and a mislabelled file that is uploaded as an image is rejected by the API.
|
|
24
|
+
*/
|
|
25
|
+
export async function inlineImageMime(filePath, size) {
|
|
26
|
+
if (!(size > 0) || size > FEISHU_IMAGE_MAX_BYTES)
|
|
27
|
+
return null;
|
|
28
|
+
let handle;
|
|
29
|
+
try {
|
|
30
|
+
handle = await fs.open(filePath, 'r');
|
|
31
|
+
const buf = Buffer.alloc(SNIFF_BYTES);
|
|
32
|
+
const { bytesRead } = await handle.read(buf, 0, SNIFF_BYTES, 0);
|
|
33
|
+
const mime = sniffImageMime(buf.subarray(0, bytesRead));
|
|
34
|
+
return mime && INLINE_IMAGE_MIMES.has(mime) ? mime : null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
await handle?.close().catch(() => undefined);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Upload `filePath` as a chat image and return its `image_key`, or null when the caller should send
|
|
45
|
+
* it as a file instead.
|
|
46
|
+
*
|
|
47
|
+
* Null is the ordinary outcome for a non-image, an oversized image — and for an upload the app is
|
|
48
|
+
* not allowed to make: `im/v1/images` needs the `im:resource` scope, which an app registered before
|
|
49
|
+
* Cortex ever sent an image will not have. A missing scope must degrade to the previous behaviour,
|
|
50
|
+
* never lose the send.
|
|
51
|
+
*/
|
|
52
|
+
export async function uploadFeishuImage(client, filePath, size) {
|
|
53
|
+
if (!(await inlineImageMime(filePath, size)))
|
|
54
|
+
return null;
|
|
55
|
+
try {
|
|
56
|
+
const res = await client.im.v1.image.create({
|
|
57
|
+
data: { image_type: 'message', image: createReadStream(filePath) },
|
|
58
|
+
});
|
|
59
|
+
if (res && typeof res.code === 'number' && res.code !== 0) {
|
|
60
|
+
throw new Error(`Feishu API error ${res.code}: ${res.msg ?? 'unknown'}`);
|
|
61
|
+
}
|
|
62
|
+
const key = res?.data?.image_key ?? res?.image_key;
|
|
63
|
+
if (key)
|
|
64
|
+
return key;
|
|
65
|
+
log.warn(`image upload returned no image_key for ${filePath}; sending it as a file`);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
log.warn(`image upload failed for ${filePath} (${e.message}); sending it as a file`);
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
@@ -50,6 +50,8 @@ export declare class FeishuAdapter implements PlatformAdapter {
|
|
|
50
50
|
markQueued(ref: MessageRef): Promise<void>;
|
|
51
51
|
unmarkQueued(ref: MessageRef): Promise<void>;
|
|
52
52
|
uploadFile(destination: Destination, filePath: string, opts?: FileUploadOpts): Promise<void>;
|
|
53
|
+
/** Upload as a chat file and return its file_key. */
|
|
54
|
+
private uploadFeishuFile;
|
|
53
55
|
downloadFile(fileRef: PlatformFileRef, destDir: string): Promise<DownloadedFile>;
|
|
54
56
|
getPermalink(_ref: MessageRef): Promise<string | null>;
|
|
55
57
|
openOutputStream(destination: Destination, opts?: OpenOutputStreamOpts): OutputStream;
|
|
@@ -7,6 +7,7 @@ import { updateSettings } from '../../core/settings.js';
|
|
|
7
7
|
import { FeishuOutputStream } from './feishu-output-stream.js';
|
|
8
8
|
import { configureFeishuHttp } from './feishu-http.js';
|
|
9
9
|
import { ProjectConduitsStore } from './project-conduits.js';
|
|
10
|
+
import { uploadFeishuImage } from './feishu-image.js';
|
|
10
11
|
import { reactionFailureReason, shouldWarnReactionFailure } from '../utils/reaction-diagnostics.js';
|
|
11
12
|
const log = createLogger('feishu');
|
|
12
13
|
/**
|
|
@@ -316,26 +317,21 @@ export class FeishuAdapter {
|
|
|
316
317
|
if (!destResolved.channel) {
|
|
317
318
|
return;
|
|
318
319
|
}
|
|
319
|
-
const { resolved: fileResolved } = this.resolveFilePath(filePath);
|
|
320
|
+
const { resolved: fileResolved, size } = this.resolveFilePath(filePath);
|
|
320
321
|
const fileName = opts?.filename || path.basename(fileResolved);
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const fileKey = uploadRes?.data?.file_key;
|
|
330
|
-
if (!fileKey)
|
|
331
|
-
throw new Error('Feishu file upload failed: no file_key returned');
|
|
332
|
-
// Send file message
|
|
333
|
-
const msgContent = JSON.stringify({ file_key: fileKey });
|
|
322
|
+
// A picture the user can see beats a download card. Feishu shows an `image` message inline (and
|
|
323
|
+
// in the notification preview); anything it cannot — a non-image, an image over 10 MB, an app
|
|
324
|
+
// without the `im:resource` scope — falls back to the file card this always used to send.
|
|
325
|
+
const imageKey = await uploadFeishuImage(this.client, fileResolved, size);
|
|
326
|
+
const msgType = imageKey ? 'image' : 'file';
|
|
327
|
+
const msgContent = imageKey
|
|
328
|
+
? JSON.stringify({ image_key: imageKey })
|
|
329
|
+
: JSON.stringify({ file_key: await this.uploadFeishuFile(fileResolved, fileName) });
|
|
334
330
|
const threadId = opts?.threadId;
|
|
335
331
|
if (threadId) {
|
|
336
332
|
await this.client.im.v1.message.reply({
|
|
337
333
|
path: { message_id: threadId },
|
|
338
|
-
data: { msg_type:
|
|
334
|
+
data: { msg_type: msgType, content: msgContent },
|
|
339
335
|
});
|
|
340
336
|
}
|
|
341
337
|
else {
|
|
@@ -343,12 +339,26 @@ export class FeishuAdapter {
|
|
|
343
339
|
params: { receive_id_type: 'chat_id' },
|
|
344
340
|
data: {
|
|
345
341
|
receive_id: destResolved.channel,
|
|
346
|
-
msg_type:
|
|
342
|
+
msg_type: msgType,
|
|
347
343
|
content: msgContent,
|
|
348
344
|
},
|
|
349
345
|
});
|
|
350
346
|
}
|
|
351
347
|
}
|
|
348
|
+
/** Upload as a chat file and return its file_key. */
|
|
349
|
+
async uploadFeishuFile(fileResolved, fileName) {
|
|
350
|
+
const uploadRes = await this.client.im.v1.file.create({
|
|
351
|
+
data: {
|
|
352
|
+
file_type: this.inferFeishuFileType(fileName),
|
|
353
|
+
file_name: fileName,
|
|
354
|
+
file: fs.readFileSync(fileResolved),
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
const fileKey = uploadRes?.data?.file_key;
|
|
358
|
+
if (!fileKey)
|
|
359
|
+
throw new Error('Feishu file upload failed: no file_key returned');
|
|
360
|
+
return fileKey;
|
|
361
|
+
}
|
|
352
362
|
async downloadFile(fileRef, destDir) {
|
|
353
363
|
const raw = fileRef.raw || {};
|
|
354
364
|
const messageId = raw.message_id;
|
|
@@ -24,7 +24,7 @@ export declare const MIN_FORWARDABLE_PORT = 1024;
|
|
|
24
24
|
*
|
|
25
25
|
* `MSYS_NO_PATHCONV=1` is required because commands reach a Windows device through git-bash, which
|
|
26
26
|
* rewrites the `/FO` switch into a filesystem path (`C:/Program Files/Git/FO`) and makes tasklist
|
|
27
|
-
* fail. Verified on
|
|
27
|
+
* fail. Verified on a Windows device.
|
|
28
28
|
*/
|
|
29
29
|
export declare const WINDOWS_LISTENER_COMMAND = "netstat -ano; echo '#--tasklist--#'; MSYS_NO_PATHCONV=1 tasklist /FO CSV /NH";
|
|
30
30
|
/**
|
|
@@ -27,7 +27,7 @@ const TASKLIST_MARKER = '#--tasklist--#';
|
|
|
27
27
|
*
|
|
28
28
|
* `MSYS_NO_PATHCONV=1` is required because commands reach a Windows device through git-bash, which
|
|
29
29
|
* rewrites the `/FO` switch into a filesystem path (`C:/Program Files/Git/FO`) and makes tasklist
|
|
30
|
-
* fail. Verified on
|
|
30
|
+
* fail. Verified on a Windows device.
|
|
31
31
|
*/
|
|
32
32
|
export const WINDOWS_LISTENER_COMMAND = `netstat -ano; echo '${TASKLIST_MARKER}'; MSYS_NO_PATHCONV=1 tasklist /FO CSV /NH`;
|
|
33
33
|
/** Foreign address of a listening socket, in both families. Locale-independent — unlike the state
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// HttpOnly cookie; every later request is admitted by that id instead of the token, so the
|
|
6
6
|
// secret itself never enters the page's JavaScript. Ids are 32 random bytes with an
|
|
7
7
|
// ABSOLUTE expiry (verify never renews — that keeps verify write-free), persisted to
|
|
8
|
-
//
|
|
8
|
+
// STORE_DIR/ui-sessions.json at 0600 so a daemon restart does not log every browser out.
|
|
9
9
|
// A session id is bearer-equivalent but strictly weaker than the token: the auth gate never
|
|
10
10
|
// accepts it on the /forward WebSocket upgrade (see ui-http-server.ts).
|
|
11
11
|
import * as crypto from 'crypto';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// ledger API (getConversation / beginTurn / rollbackTo / …) while the registry owns the data.
|
|
4
4
|
// pos: Compatibility surface for turn-history callers; NO storage of its own (no JSON file — the
|
|
5
5
|
// registry journal is the only store)
|
|
6
|
-
// >>> Once I am updated, be sure to update my header comment and the parent folder
|
|
6
|
+
// >>> Once I am updated, be sure to update my header comment and the parent folder AGENTS.md <<<
|
|
7
7
|
//
|
|
8
8
|
// The ledger no longer has a JSON file. Every method maps onto the registry's channel-keyed
|
|
9
9
|
// conversation header + turn history, most under a single `registry.batch(...)` critical section so a
|
|
@@ -7,16 +7,6 @@ export interface DispatchInfo {
|
|
|
7
7
|
sessionName: string | null;
|
|
8
8
|
tmuxName: string | null;
|
|
9
9
|
pid: string | null;
|
|
10
|
-
/** cortex-run `--name` (log-ref): resolves the run's output.log for the live log tailer (B2-C). */
|
|
11
|
-
runName: string | null;
|
|
12
|
-
}
|
|
13
|
-
/** The GPU actually selected for a cortex-run/dispatch execution (DR-0018 §6.3 B2-followup).
|
|
14
|
-
* Captured by the client watcher (`resolveGpuSelection`, incl. `--gpu auto`) and delivered via
|
|
15
|
-
* task-callback. `indices` = CUDA device ordinals; `memoryMb` = the selected GPU's total memory
|
|
16
|
-
* (auto-pick only — null for an explicit `--gpu N`). Null on the record ⇒ unknown / not captured. */
|
|
17
|
-
export interface ExecutionGpuInfo {
|
|
18
|
-
indices: number[];
|
|
19
|
-
memoryMb: number | null;
|
|
20
10
|
}
|
|
21
11
|
export interface ExecutionRecord {
|
|
22
12
|
id: string;
|
|
@@ -56,7 +46,6 @@ export interface ExecutionRecord {
|
|
|
56
46
|
numTurns: number | null;
|
|
57
47
|
durationS: number | null;
|
|
58
48
|
};
|
|
59
|
-
gpu: ExecutionGpuInfo | null;
|
|
60
49
|
text: {
|
|
61
50
|
label: string | null;
|
|
62
51
|
finalOutput: string | null;
|
|
@@ -113,7 +102,7 @@ declare class ExecutionRepo {
|
|
|
113
102
|
threadId?: string | null;
|
|
114
103
|
agentSlotId?: string | null;
|
|
115
104
|
}): ExecutionRecord;
|
|
116
|
-
registerDispatchExecution({ taskId, machine, channel, project, scheduleTaskId, taskText, taskHash, sessionName, tmuxName, pid,
|
|
105
|
+
registerDispatchExecution({ taskId, machine, channel, project, scheduleTaskId, taskText, taskHash, sessionName, tmuxName, pid, backend, billingMode }: {
|
|
117
106
|
taskId: string;
|
|
118
107
|
machine?: string | null;
|
|
119
108
|
channel?: string | null;
|
|
@@ -124,7 +113,6 @@ declare class ExecutionRepo {
|
|
|
124
113
|
sessionName?: string | null;
|
|
125
114
|
tmuxName?: string | null;
|
|
126
115
|
pid?: string | null;
|
|
127
|
-
runName?: string | null;
|
|
128
116
|
backend?: string;
|
|
129
117
|
billingMode?: string;
|
|
130
118
|
}): ExecutionRecord | null;
|
|
@@ -135,12 +123,6 @@ declare class ExecutionRepo {
|
|
|
135
123
|
session?: Partial<ExecutionRecord['session']>;
|
|
136
124
|
[key: string]: unknown;
|
|
137
125
|
}): ExecutionRecord | null;
|
|
138
|
-
/** Record the per-execution GPU onto the dispatch record keyed by taskId (DR-0018 §6.3
|
|
139
|
-
* B2-followup). GPU is write-once metadata delivered by the terminal task-callback, so —
|
|
140
|
-
* unlike touchExecution — this bypasses the terminal-status guard (the dispatch record is
|
|
141
|
-
* usually still 'running' at callback time, but a re-dispatched/terminal one must still learn
|
|
142
|
-
* its GPU). Returns null when no execution is registered for the task. */
|
|
143
|
-
setExecutionGpuByTaskId(taskId: string, gpu: ExecutionGpuInfo | null): ExecutionRecord | null;
|
|
144
126
|
completeExecution(id: string, metrics?: {
|
|
145
127
|
costUsd?: number | null;
|
|
146
128
|
numTurns?: number | null;
|
|
@@ -48,7 +48,6 @@ function createBaseRecord({ kind, channel, project, trigger, backend, billingMod
|
|
|
48
48
|
numTurns: null,
|
|
49
49
|
durationS: null,
|
|
50
50
|
},
|
|
51
|
-
gpu: null,
|
|
52
51
|
text: {
|
|
53
52
|
label: label || null,
|
|
54
53
|
finalOutput: null,
|
|
@@ -180,7 +179,7 @@ class ExecutionRepo {
|
|
|
180
179
|
this.queuePersist();
|
|
181
180
|
return record;
|
|
182
181
|
}
|
|
183
|
-
registerDispatchExecution({ taskId, machine, channel, project, scheduleTaskId, taskText, taskHash, sessionName, tmuxName, pid,
|
|
182
|
+
registerDispatchExecution({ taskId, machine, channel, project, scheduleTaskId, taskText, taskHash, sessionName, tmuxName, pid, backend, billingMode }) {
|
|
184
183
|
const existing = this.getExecutionByTaskId(taskId);
|
|
185
184
|
if (existing && !TERMINAL_STATUSES.has(existing.status)) {
|
|
186
185
|
return this.updateRecordInternal(existing.id, (record) => ({
|
|
@@ -200,7 +199,6 @@ class ExecutionRepo {
|
|
|
200
199
|
sessionName: sessionName || record.dispatch?.sessionName || null,
|
|
201
200
|
tmuxName: tmuxName || record.dispatch?.tmuxName || null,
|
|
202
201
|
pid: pid || record.dispatch?.pid || null,
|
|
203
|
-
runName: runName || record.dispatch?.runName || null,
|
|
204
202
|
},
|
|
205
203
|
}));
|
|
206
204
|
}
|
|
@@ -222,7 +220,6 @@ class ExecutionRepo {
|
|
|
222
220
|
sessionName: sessionName || null,
|
|
223
221
|
tmuxName: tmuxName || null,
|
|
224
222
|
pid: pid || null,
|
|
225
|
-
runName: runName || null,
|
|
226
223
|
};
|
|
227
224
|
this.map.set(record.id, record);
|
|
228
225
|
this.queuePersist();
|
|
@@ -238,20 +235,6 @@ class ExecutionRepo {
|
|
|
238
235
|
session: patch.session ? { ...record.session, ...patch.session } : record.session,
|
|
239
236
|
}));
|
|
240
237
|
}
|
|
241
|
-
/** Record the per-execution GPU onto the dispatch record keyed by taskId (DR-0018 §6.3
|
|
242
|
-
* B2-followup). GPU is write-once metadata delivered by the terminal task-callback, so —
|
|
243
|
-
* unlike touchExecution — this bypasses the terminal-status guard (the dispatch record is
|
|
244
|
-
* usually still 'running' at callback time, but a re-dispatched/terminal one must still learn
|
|
245
|
-
* its GPU). Returns null when no execution is registered for the task. */
|
|
246
|
-
setExecutionGpuByTaskId(taskId, gpu) {
|
|
247
|
-
const record = this.getExecutionByTaskId(taskId);
|
|
248
|
-
if (!record)
|
|
249
|
-
return null;
|
|
250
|
-
const next = { ...record, gpu };
|
|
251
|
-
this.map.set(record.id, next);
|
|
252
|
-
this.queuePersist();
|
|
253
|
-
return next;
|
|
254
|
-
}
|
|
255
238
|
completeExecution(id, metrics = {}) {
|
|
256
239
|
return this.updateRecordInternal(id, (record) => finalizeExecution(record, 'completed', metrics));
|
|
257
240
|
}
|
|
@@ -62,6 +62,10 @@ function isChromeLine(line) {
|
|
|
62
62
|
return line === '' || line === '# Notes' || line === FORMAT_MARKER || line === PRIVACY_MARKER
|
|
63
63
|
|| line === '## Active' || line === '## Completed';
|
|
64
64
|
}
|
|
65
|
+
function excerpt(line) {
|
|
66
|
+
const text = line.trim();
|
|
67
|
+
return text.length > 60 ? `${text.slice(0, 60)}...` : text;
|
|
68
|
+
}
|
|
65
69
|
export function parseNotesMarkdown(md) {
|
|
66
70
|
if (!md.includes(FORMAT_MARKER))
|
|
67
71
|
throw invalidFile('Unsupported NOTES.md format');
|
|
@@ -71,8 +75,13 @@ export function parseNotesMarkdown(md) {
|
|
|
71
75
|
const line = lines[index];
|
|
72
76
|
if (isChromeLine(line))
|
|
73
77
|
continue;
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
// Strict on purpose: this file is machine-owned, and quietly skipping a line we do not
|
|
79
|
+
// understand would silently delete it on the next write. The excerpt is what makes the refusal
|
|
80
|
+
// actionable — hand-written prose appended below the notes is the one way this ever happens.
|
|
81
|
+
if (!line.startsWith(META_PREFIX)) {
|
|
82
|
+
throw invalidFile(`Unexpected NOTES.md content at line ${index + 1}: ${JSON.stringify(excerpt(line))}. `
|
|
83
|
+
+ 'NOTES.md is written by the notes UI only — move hand-written text to another file.');
|
|
84
|
+
}
|
|
76
85
|
notes.push(parseEntry(lines, index));
|
|
77
86
|
index += 1;
|
|
78
87
|
}
|
|
@@ -77,7 +77,7 @@ export const MANAGER_TASK_FILE_REPLACEMENTS = [
|
|
|
77
77
|
export const STATUS_REGISTER_REPLACEMENTS = [
|
|
78
78
|
[
|
|
79
79
|
"Record findings, decisions, and artifacts in files as you go — not in a final summary. Update STATUS.md, the directory's CORTEX.md index, and the role's designated output artifact(s) before exiting.",
|
|
80
|
-
"Record findings, decisions, and artifacts in files as you go — not in a final summary. Update the role's designated output artifact(s) and the directory's
|
|
80
|
+
"Record findings, decisions, and artifacts in files as you go — not in a final summary. Update the role's designated output artifact(s) and the directory's AGENTS.md index before exiting. Update STATUS.md only if your work changed the project's situation (unblocked something, introduced a blocker, changed the next step) — STATUS is a state register, not a changelog; one line + pointer per change (see rules/status-md.md).",
|
|
81
81
|
],
|
|
82
82
|
[
|
|
83
83
|
"Prefer editing the existing project artifacts (STATUS.md, knowledge entries, the role's artifact file) over creating parallel new files.",
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// whitelist/replay contract stays the single source of truth for what a field means.
|
|
7
7
|
// pos: Migration helper invoked as a step migration from store/version-migrations.ts (B.T4).
|
|
8
8
|
// Idempotent via the rename: a second run finds no sources and is a no-op.
|
|
9
|
-
// >>> Once I am updated, be sure to update my header comment and the parent folder
|
|
9
|
+
// >>> Once I am updated, be sure to update my header comment and the parent folder AGENTS.md <<<
|
|
10
10
|
import * as fs from 'node:fs/promises';
|
|
11
11
|
import * as path from 'node:path';
|
|
12
12
|
import { createLogger } from '../core/log.js';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// (records + channel bindings + per-CHANNEL conversation header & turn history;
|
|
4
4
|
// events: put/patch/delete-*/bind/unbind/turn/conversation)
|
|
5
5
|
// pos: Low-level journal I/O for session registry state — the single owner of session identity
|
|
6
|
-
// >>> Once I am updated, be sure to update my header comment and the parent folder
|
|
6
|
+
// >>> Once I am updated, be sure to update my header comment and the parent folder AGENTS.md <<<
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import fsp from 'node:fs/promises';
|
|
9
9
|
import path from 'node:path';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// output: SessionRegistryRepo JSONL-backed registry and admission APIs
|
|
3
3
|
// (patch-delta updates, channel bindings + conduit resolvers, turn history, batch())
|
|
4
4
|
// pos: Stable session identity store with delete-intent guards
|
|
5
|
-
// >>> Once I am updated, be sure to update my header comment and the parent folder
|
|
5
|
+
// >>> Once I am updated, be sure to update my header comment and the parent folder AGENTS.md <<<
|
|
6
6
|
import * as crypto from 'node:crypto';
|
|
7
7
|
import * as path from 'node:path';
|
|
8
8
|
import { isDeepStrictEqual } from 'node:util';
|
|
@@ -42,6 +42,11 @@ export declare function upsertMarkerBlock(content: string, block: string): strin
|
|
|
42
42
|
* customized away from the shipped wording simply won't match and is left untouched,
|
|
43
43
|
* preserving their edits. */
|
|
44
44
|
export declare function applyReplacements(content: string, pairs: ReadonlyArray<readonly [string, string]>): string;
|
|
45
|
+
export declare function renameMemoryFilesToAgentsMd(dataDir: string): Promise<number>;
|
|
46
|
+
/** Rename `rules/cortex-md.md` → `rules/agents-md.md` and repair references to it across `rules/`.
|
|
47
|
+
* Returns the number of rule files whose content changed. Never clobbers an existing
|
|
48
|
+
* `agents-md.md`; a no-op on a fresh install, where `init` seeded the new name already. */
|
|
49
|
+
export declare function renameIndexRuleFile(dataDir: string): Promise<number>;
|
|
45
50
|
/** Exported for plugin-retirement.ts, which guards its own one-shot rewrite with a sentinel key
|
|
46
51
|
* in the same versions.json. Keeping one reader means one definition of "corrupt → reset". */
|
|
47
52
|
export declare function loadVersionsFrom(filePath: string): Promise<Record<string, string>>;
|
|
@@ -72,12 +77,17 @@ export declare function migrateAistatusConfigLocation(dataDir: string, dstPath?:
|
|
|
72
77
|
/**
|
|
73
78
|
* Delete hooks Cortex no longer ships from an existing install.
|
|
74
79
|
*
|
|
75
|
-
*
|
|
80
|
+
* The first three members were unreachable by construction rather than merely unused. The
|
|
76
81
|
* AskUserQuestion / ExitPlanMode bridge hooks matched native tools that headless `-p` strips from
|
|
77
82
|
* the session whatever `--tools` lists (plan approval and questions now run through the
|
|
78
83
|
* interaction-bridge MCP tools against the same webhook endpoints), and the PermissionRequest
|
|
79
84
|
* auto-allow matched an event Claude never emits under the `bypassPermissions` mode every Cortex
|
|
80
|
-
* spawn runs in.
|
|
81
|
-
*
|
|
85
|
+
* spawn runs in. The last two are a rename: the CORTEX.md injector became the AGENTS.md injector
|
|
86
|
+
* under new filenames, and leaving the old pair deployed would double every injection.
|
|
87
|
+
* `syncManagedHooks` only adds and upgrades files, so without this the dead entries would linger
|
|
88
|
+
* in every upgraded registry. Idempotent, and a no-op once the files are gone.
|
|
89
|
+
*
|
|
90
|
+
* Entries go first and scripts second: two entries can share one script, so a script is only
|
|
91
|
+
* orphaned once every entry that ran it is gone.
|
|
82
92
|
*/
|
|
83
93
|
export declare function removeRetiredDefaultHooks(dataDir: string): Promise<void>;
|