claude-flow 3.57.2 → 3.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.claude/proven-config.json +1 -1
  2. package/.claude-plugin/marketplace.json +11 -0
  3. package/README.md +1 -0
  4. package/node_modules/@claude-flow/codex/README.md +78 -0
  5. package/node_modules/@claude-flow/codex/dist/activity/cli.d.ts +3 -0
  6. package/node_modules/@claude-flow/codex/dist/activity/cli.d.ts.map +1 -0
  7. package/node_modules/@claude-flow/codex/dist/activity/cli.js +115 -0
  8. package/node_modules/@claude-flow/codex/dist/activity/cli.js.map +1 -0
  9. package/node_modules/@claude-flow/codex/dist/activity/files.d.ts +14 -0
  10. package/node_modules/@claude-flow/codex/dist/activity/files.d.ts.map +1 -0
  11. package/node_modules/@claude-flow/codex/dist/activity/files.js +142 -0
  12. package/node_modules/@claude-flow/codex/dist/activity/files.js.map +1 -0
  13. package/node_modules/@claude-flow/codex/dist/activity/parser.d.ts +21 -0
  14. package/node_modules/@claude-flow/codex/dist/activity/parser.d.ts.map +1 -0
  15. package/node_modules/@claude-flow/codex/dist/activity/parser.js +179 -0
  16. package/node_modules/@claude-flow/codex/dist/activity/parser.js.map +1 -0
  17. package/node_modules/@claude-flow/codex/dist/activity/reader.d.ts +20 -0
  18. package/node_modules/@claude-flow/codex/dist/activity/reader.d.ts.map +1 -0
  19. package/node_modules/@claude-flow/codex/dist/activity/reader.js +106 -0
  20. package/node_modules/@claude-flow/codex/dist/activity/reader.js.map +1 -0
  21. package/node_modules/@claude-flow/codex/dist/activity/sanitize.d.ts +4 -0
  22. package/node_modules/@claude-flow/codex/dist/activity/sanitize.d.ts.map +1 -0
  23. package/node_modules/@claude-flow/codex/dist/activity/sanitize.js +27 -0
  24. package/node_modules/@claude-flow/codex/dist/activity/sanitize.js.map +1 -0
  25. package/node_modules/@claude-flow/codex/dist/activity/types.d.ts +31 -0
  26. package/node_modules/@claude-flow/codex/dist/activity/types.d.ts.map +1 -0
  27. package/node_modules/@claude-flow/codex/dist/activity/types.js +5 -0
  28. package/node_modules/@claude-flow/codex/dist/activity/types.js.map +1 -0
  29. package/node_modules/@claude-flow/codex/dist/activity/viewer.d.ts +21 -0
  30. package/node_modules/@claude-flow/codex/dist/activity/viewer.d.ts.map +1 -0
  31. package/node_modules/@claude-flow/codex/dist/activity/viewer.js +168 -0
  32. package/node_modules/@claude-flow/codex/dist/activity/viewer.js.map +1 -0
  33. package/node_modules/@claude-flow/codex/dist/cli.js +3 -0
  34. package/node_modules/@claude-flow/codex/dist/cli.js.map +1 -1
  35. package/node_modules/@claude-flow/mcp/dist/server.d.ts.map +1 -1
  36. package/node_modules/@claude-flow/mcp/dist/server.js +5 -3
  37. package/node_modules/@claude-flow/mcp/dist/server.js.map +1 -1
  38. package/node_modules/@claude-flow/mcp/dist/types.d.ts +11 -0
  39. package/node_modules/@claude-flow/mcp/dist/types.d.ts.map +1 -1
  40. package/node_modules/@claude-flow/mcp/dist/types.js.map +1 -1
  41. package/package.json +1 -1
  42. package/v3/@claude-flow/cli/README.md +1 -0
  43. package/v3/@claude-flow/cli/catalog-manifest.json +2 -2
  44. package/v3/@claude-flow/cli/dist/src/commands/agent.js +4 -1
  45. package/v3/@claude-flow/cli/dist/src/commands/mcp.js +66 -6
  46. package/v3/@claude-flow/cli/dist/src/commands/memory.js +53 -2
  47. package/v3/@claude-flow/cli/dist/src/mcp-server.d.ts +5 -0
  48. package/v3/@claude-flow/cli/dist/src/mcp-server.js +39 -0
  49. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +28 -0
  50. package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +25 -15
  51. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +43 -4
  52. package/v3/@claude-flow/cli/dist/src/memory/memory-peek.d.ts +28 -0
  53. package/v3/@claude-flow/cli/dist/src/memory/memory-peek.js +222 -0
  54. package/v3/@claude-flow/cli/dist/src/memory/model-cache-dir.d.ts +11 -0
  55. package/v3/@claude-flow/cli/dist/src/memory/model-cache-dir.js +17 -0
  56. package/v3/@claude-flow/cli/dist/src/ruvector/task-embedder.js +38 -4
  57. package/v3/@claude-flow/cli/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  {
2
- "adoptedAt": 1792452783501,
2
+ "adoptedAt": 1792476754804,
3
3
  "championId": "sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319",
4
4
  "manifest": {
5
5
  "schema": "ruflo.proven-config/v1",
@@ -51,6 +51,17 @@
51
51
  "source": "./plugins/ruflo-testgen",
52
52
  "description": "Test gap detection, coverage analysis, and automated test generation"
53
53
  },
54
+ {
55
+ "name": "agentic-qe-fleet",
56
+ "source": {
57
+ "source": "git-subdir",
58
+ "url": "https://github.com/proffesor-for-testing/agentic-qe.git",
59
+ "path": "plugins/agentic-qe-fleet",
60
+ "ref": "v3.15.10",
61
+ "sha": "e5814a2f4f3d7995b87ebda9ad30e8a3d92cd555"
62
+ },
63
+ "description": "Agentic QE (external: maintained in proffesor-for-testing/agentic-qe, pinned to v3.15.10): a quality-engineering fleet with 11 QE agents, 9 skills, 9 commands, the agentic-qe MCP server pinned to the plugin version, and the aqe-mod guard that refuses destructive operations on AQE learning data"
64
+ },
54
65
  {
55
66
  "name": "ruflo-docs",
56
67
  "source": "./plugins/ruflo-docs",
package/README.md CHANGED
@@ -240,6 +240,7 @@ This adds slash commands and agent definitions. `ruflo-core` (installed above) d
240
240
  | [**ruflo-browser**](plugins/ruflo-browser/README.md) | Automate browser testing with Playwright |
241
241
  | [**ruflo-jujutsu**](plugins/ruflo-jujutsu/README.md) | Analyze git diffs, score risk, suggest reviewers |
242
242
  | [**ruflo-docs**](plugins/ruflo-docs/README.md) | Generate and maintain documentation automatically |
243
+ | [**agentic-qe-fleet**](https://github.com/proffesor-for-testing/agentic-qe/tree/v3.15.10/plugins/agentic-qe-fleet) | External, maintained by [Agentic QE](https://github.com/proffesor-for-testing/agentic-qe): 11 QE agents, test generation, coverage, chaos and TDD skills, the `agentic-qe` MCP server, and a guard for AQE learning data (`/plugin install agentic-qe-fleet@ruflo`). Install it from one marketplace only, `agentic-qe` or `ruflo`: enabled from both, its mod and commands load twice |
243
244
 
244
245
  #### Security & Compliance
245
246
 
@@ -1042,6 +1042,84 @@ npx claude-flow memory optimize --rebuild-index
1042
1042
 
1043
1043
  ---
1044
1044
 
1045
+ ## Inspect an existing Codex session
1046
+
1047
+ The `activity` command lets you pick a helper and read its assignment, recorded
1048
+ state, public progress messages, and tool calls/results. It reads local rollout
1049
+ files without starting model sessions or sending commands to agents.
1050
+
1051
+ From a checkout containing this change:
1052
+
1053
+ ```bash
1054
+ npm install --prefix v3/@claude-flow/codex --workspaces=false --ignore-scripts --legacy-peer-deps --package-lock=false
1055
+ npm run build --prefix v3/@claude-flow/codex
1056
+ node v3/@claude-flow/codex/dist/cli.js activity \
1057
+ --session-file /path/to/sessions/parent-rollout.jsonl \
1058
+ --sessions-dir /path/to/sessions
1059
+ ```
1060
+
1061
+ Choose the parent rollout explicitly. Only helpers whose recorded parent chain
1062
+ leads back to that session appear. The selected directory must contain both the
1063
+ parent and helper files; use the smallest directory that contains them all.
1064
+
1065
+ Use **j/k** or the arrow keys to select a helper, then **Enter** to open it.
1066
+ In the detail view, **j/k** scroll, **Space** moves down a page, **g** goes to the
1067
+ top, **G** follows the latest activity, and **b** or **Escape** returns to the list.
1068
+ Press **q** to quit; the Codex session keeps running.
1069
+
1070
+ Use `--agent <thread-id>` to open a specific helper, `--once` to print a snapshot
1071
+ without an interactive terminal, or `--interval <seconds>` to change the refresh
1072
+ interval (default: 2 seconds; range: 0.2–60).
1073
+
1074
+ These screenshots use made-up session records:
1075
+
1076
+ ![Agent picker with a parser-review helper](docs/images/activity-picker.png)
1077
+
1078
+ ![Helper assignment, public progress, command and result](docs/images/activity-detail.png)
1079
+
1080
+ ### What the viewer can read
1081
+
1082
+ The parser supports CLI rollout files with a `session_meta` header, helper ancestry
1083
+ in `source.subagent.thread_spawn.parent_thread_id`, and an own-thread marker
1084
+ (`payload.thread_id`) before helper activity. Public message, function/custom tool
1085
+ call and result records, and supported task/item events are shown. Formats without
1086
+ these attribution fields may produce an empty list or unavailable activity.
1087
+
1088
+ Copied parent history, reasoning, and system/developer messages are excluded.
1089
+ Ambiguous identities and paths through symlinks are rejected. The viewer strips
1090
+ terminal controls and masks common credential patterns before shortening previews.
1091
+ Masking cannot catch every secret in arbitrary command output: check the visible
1092
+ content before sharing a screenshot.
1093
+
1094
+ State is the last **recorded** state, not a heartbeat. Discovery stops after 4,000
1095
+ entries or eight directory levels; ancestry is limited to 64 links. Each detail
1096
+ refresh reads at most 1 MiB, lines are limited to 64 KiB, previews to 2,400 characters,
1097
+ and history to 80 events. The metadata header must include its terminating newline
1098
+ within the first 64 KiB; an oversized or incomplete header excludes that file.
1099
+ The screen labels incomplete scans, omitted records and logs that are still being
1100
+ read. Missing data stays unavailable.
1101
+
1102
+ ### Check the viewer locally
1103
+
1104
+ ```bash
1105
+ cd v3/@claude-flow/codex
1106
+ npm test -- --run tests/activity-files.test.ts tests/activity-parser.test.ts tests/activity-viewer.test.ts
1107
+ cd ../../..
1108
+ node scripts/smoke-codex-activity.mjs
1109
+ ```
1110
+
1111
+ The Node smoke check runs the built CLI against synthetic files and checks the
1112
+ picker, detail output, history isolation, invalid input and read-only access.
1113
+ The screenshots above were captured from the interactive viewer using synthetic
1114
+ records; screenshot generation is not part of CI.
1115
+
1116
+ ### Release integration
1117
+
1118
+ Ship the viewer in `@claude-flow/codex` with the next coordinated Ruflo release.
1119
+ At release, bump the package version and exported `VERSION` together, update the
1120
+ bundled dependency pins and lockfile, and include the built package in the release
1121
+ train.
1122
+
1045
1123
  ## Related Packages
1046
1124
 
1047
1125
  | Package | Description |
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function createActivityCommand(): Command;
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/activity/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAwB,MAAM,WAAW,CAAC;AAO1D,wBAAgB,qBAAqB,IAAI,OAAO,CA6B/C"}
@@ -0,0 +1,115 @@
1
+ import { Command, InvalidArgumentError } from 'commander';
2
+ import { realpath } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { emitKeypressEvents } from 'node:readline';
5
+ import { ActivityViewer } from './viewer.js';
6
+ import { sanitize } from './sanitize.js';
7
+ export function createActivityCommand() {
8
+ return new Command('activity')
9
+ .description('Inspect helpers from an existing Codex session (read-only)')
10
+ .requiredOption('--session-file <file>', 'Parent CLI rollout JSONL file')
11
+ .requiredOption('--sessions-dir <directory>', 'Directory containing parent and helper rollouts')
12
+ .option('--agent <id>', 'Open a particular helper thread ID')
13
+ .option('--once', 'Print one bounded snapshot and exit (no interactive terminal needed)')
14
+ .option('--interval <seconds>', 'Refresh interval, 0.2 to 60 seconds', interval, 2)
15
+ .action(async (options) => {
16
+ try {
17
+ const root = await realpath(path.resolve(options.sessionsDir));
18
+ // Canonicalize the directory only. A selected file through a symlink is rejected.
19
+ const file = path.resolve(root, path.relative(path.resolve(options.sessionsDir), path.resolve(options.sessionFile)));
20
+ const viewer = new ActivityViewer(root, file);
21
+ await viewer.refresh();
22
+ if (viewer.list.error)
23
+ throw new Error(viewer.list.error);
24
+ if (options.agent) {
25
+ if (!viewer.list.helpers.some(item => item.id === options.agent))
26
+ throw new Error('Agent is not an attributable helper of this session.');
27
+ viewer.selected = options.agent;
28
+ viewer.detail = true;
29
+ await viewer.refresh();
30
+ }
31
+ if (options.once)
32
+ console.log(viewer.render(100, 200));
33
+ else
34
+ await runTerminal(viewer, options.interval * 1000);
35
+ }
36
+ catch (error) {
37
+ console.error(`Activity viewer: ${sanitize(error instanceof Error ? error.message : 'Unable to read session.', 300)}`);
38
+ process.exitCode = 1;
39
+ }
40
+ });
41
+ }
42
+ function interval(value) {
43
+ const parsed = Number(value);
44
+ if (!Number.isFinite(parsed) || parsed < 0.2 || parsed > 60)
45
+ throw new InvalidArgumentError('Choose 0.2 to 60 seconds.');
46
+ return parsed;
47
+ }
48
+ async function runTerminal(viewer, intervalMs) {
49
+ const input = process.stdin;
50
+ const output = process.stdout;
51
+ if (!input.isTTY || !output.isTTY)
52
+ throw new Error('Use --once when input or output is not a terminal.');
53
+ const wasRaw = input.isRaw;
54
+ let stopped = false;
55
+ let busy = false;
56
+ let finish = () => { };
57
+ const done = new Promise(resolve => { finish = resolve; });
58
+ const draw = () => {
59
+ if (!stopped)
60
+ output.write(`\x1b[H\x1b[2J${viewer.render(output.columns || 80, output.rows || 24)}`);
61
+ };
62
+ const close = () => { stopped = true; finish(); };
63
+ const update = async () => {
64
+ if (busy || stopped)
65
+ return;
66
+ busy = true;
67
+ try {
68
+ await viewer.refresh();
69
+ draw();
70
+ }
71
+ catch {
72
+ close();
73
+ process.exitCode = 1;
74
+ }
75
+ finally {
76
+ busy = false;
77
+ }
78
+ };
79
+ const keypress = (text, key) => {
80
+ if (key?.name === 'q' || key?.ctrl && key.name === 'c') {
81
+ close();
82
+ return;
83
+ }
84
+ viewer.key(text === 'G' ? 'G' : key?.name ?? text);
85
+ draw();
86
+ if (key?.name === 'return')
87
+ void update();
88
+ };
89
+ emitKeypressEvents(input);
90
+ const timer = setInterval(() => { void update(); }, intervalMs);
91
+ try {
92
+ input.setRawMode(true);
93
+ input.resume();
94
+ input.on('keypress', keypress);
95
+ output.on('resize', draw);
96
+ process.on('SIGINT', close);
97
+ process.on('SIGTERM', close);
98
+ output.write('\x1b[?1049h\x1b[?25l');
99
+ draw();
100
+ await done;
101
+ }
102
+ finally {
103
+ stopped = true;
104
+ clearInterval(timer);
105
+ input.off('keypress', keypress);
106
+ output.off('resize', draw);
107
+ process.off('SIGINT', close);
108
+ process.off('SIGTERM', close);
109
+ input.setRawMode(wasRaw);
110
+ // This command owns stdin. A resumed stream would keep Node alive after q.
111
+ input.pause();
112
+ output.write('\x1b[?25h\x1b[?1049l');
113
+ }
114
+ }
115
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/activity/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAY,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;SAC3B,WAAW,CAAC,4DAA4D,CAAC;SACzE,cAAc,CAAC,uBAAuB,EAAE,+BAA+B,CAAC;SACxE,cAAc,CAAC,4BAA4B,EAAE,iDAAiD,CAAC;SAC/F,MAAM,CAAC,cAAc,EAAE,oCAAoC,CAAC;SAC5D,MAAM,CAAC,QAAQ,EAAE,sEAAsE,CAAC;SACxF,MAAM,CAAC,sBAAsB,EAAE,qCAAqC,EAAE,QAAQ,EAAE,CAAC,CAAC;SAClF,MAAM,CAAC,KAAK,EAAE,OAAuG,EAAE,EAAE;QACxH,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;YAC/D,kFAAkF;YAClF,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAC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C,CAAC;QACrC,IAAI,EAAE,CAAC;QACP,MAAM,IAAI,CAAC;IACb,CAAC;YAAS,CAAC;QACT,OAAO,GAAG,IAAI,CAAC;QACf,aAAa,CAAC,KAAK,CAAC,CAAC;QACrB,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC9B,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACzB,2EAA2E;QAC3E,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { FileHandle } from 'node:fs/promises';
2
+ import { type SessionIdentity } from './types.js';
3
+ export declare const MAX_LINE: number;
4
+ /** Only regular files whose resolved path stays inside the selected directory. */
5
+ export declare function openSession(root: string, file: string): Promise<FileHandle>;
6
+ export declare function readIdentity(root: string, file: string): Promise<SessionIdentity | null>;
7
+ export interface SessionList {
8
+ root: SessionIdentity | null;
9
+ helpers: SessionIdentity[];
10
+ partial: boolean;
11
+ error: string;
12
+ }
13
+ export declare function listSessions(root: string, rootFile: string, expectedId?: string): Promise<SessionList>;
14
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/activity/files.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAU,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAG1D,eAAO,MAAM,QAAQ,QAAY,CAAC;AAGlC,kFAAkF;AAClF,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAmBjF;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAyB9F;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAsD5G"}
@@ -0,0 +1,142 @@
1
+ import { constants } from 'node:fs';
2
+ import { lstat, open, opendir, realpath } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { object } from './types.js';
5
+ import { sanitize } from './sanitize.js';
6
+ export const MAX_LINE = 64 * 1024;
7
+ const MAX_ENTRIES = 4000;
8
+ /** Only regular files whose resolved path stays inside the selected directory. */
9
+ export async function openSession(root, file) {
10
+ const absolute = path.resolve(file);
11
+ const relative = path.relative(root, absolute);
12
+ if (!relative || relative === '..' || relative.startsWith(`..${path.sep}`)
13
+ || path.isAbsolute(relative) || await realpath(absolute) !== absolute) {
14
+ throw new Error('Session file is outside the selected directory or uses a symlink.');
15
+ }
16
+ const before = await lstat(absolute);
17
+ if (!before.isFile())
18
+ throw new Error('Session is not a regular file.');
19
+ const handle = await open(absolute, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
20
+ try {
21
+ const after = await handle.stat();
22
+ if (!after.isFile() || after.ino !== before.ino || after.dev !== before.dev
23
+ || await realpath(absolute) !== absolute)
24
+ throw new Error('Session changed while opening.');
25
+ return handle;
26
+ }
27
+ catch (error) {
28
+ await handle.close();
29
+ throw error;
30
+ }
31
+ }
32
+ export async function readIdentity(root, file) {
33
+ const handle = await openSession(root, file);
34
+ try {
35
+ const buffer = Buffer.alloc(MAX_LINE);
36
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
37
+ const newline = buffer.subarray(0, bytesRead).indexOf(10);
38
+ // A valid JSON prefix is not enough: require the complete metadata line.
39
+ if (newline < 0)
40
+ return null;
41
+ const record = object(JSON.parse(buffer.subarray(0, newline).toString('utf8')));
42
+ const meta = object(record.payload);
43
+ if (record.type !== 'session_meta' || typeof meta.id !== 'string' || !meta.id
44
+ || meta.id.length > 300)
45
+ return null;
46
+ const spawn = object(object(object(meta.source).subagent).thread_spawn);
47
+ const parent = typeof spawn.parent_thread_id === 'string' ? spawn.parent_thread_id : null;
48
+ const rootSession = meta.source === 'cli' && !meta.forked_from_id
49
+ && !meta.parent_thread_id && (!meta.thread_source || meta.thread_source === 'user');
50
+ if (!parent && !rootSession)
51
+ return null; // Excludes guardians and unknown sources.
52
+ return {
53
+ id: meta.id, parent, file,
54
+ name: sanitize(meta.agent_nickname ?? spawn.agent_nickname ?? '', 120),
55
+ path: sanitize(meta.agent_path ?? spawn.agent_path ?? meta.id, 200),
56
+ };
57
+ }
58
+ finally {
59
+ await handle.close();
60
+ }
61
+ }
62
+ export async function listSessions(root, rootFile, expectedId) {
63
+ const empty = { root: null, helpers: [], partial: false, error: '' };
64
+ let selected;
65
+ try {
66
+ selected = await readIdentity(root, rootFile);
67
+ }
68
+ catch {
69
+ return { ...empty, error: 'The selected session file is unavailable.' };
70
+ }
71
+ if (!selected || selected.parent || (expectedId && selected.id !== expectedId)) {
72
+ return { ...empty, error: 'Select a root CLI session with an unchanged identity.' };
73
+ }
74
+ const sessions = new Map([[selected.id, selected]]);
75
+ const duplicates = new Set();
76
+ const queue = [{ directory: root, depth: 0 }];
77
+ let entries = 0;
78
+ let partial = false;
79
+ while (queue.length && entries < MAX_ENTRIES) {
80
+ const current = queue.shift();
81
+ try {
82
+ // Revalidate directories too; never recurse through a symlink.
83
+ if (await realpath(current.directory) !== current.directory) {
84
+ partial = true;
85
+ continue;
86
+ }
87
+ const directory = await opendir(current.directory);
88
+ for await (const entry of directory) {
89
+ if (++entries > MAX_ENTRIES) {
90
+ partial = true;
91
+ break;
92
+ }
93
+ const file = path.join(current.directory, entry.name);
94
+ if (entry.isDirectory()) {
95
+ if (current.depth < 8)
96
+ queue.push({ directory: file, depth: current.depth + 1 });
97
+ else
98
+ partial = true;
99
+ }
100
+ else if (entry.isFile() && entry.name.endsWith('.jsonl') && file !== rootFile) {
101
+ try {
102
+ const identity = await readIdentity(root, file);
103
+ if (!identity)
104
+ continue;
105
+ if (sessions.has(identity.id))
106
+ duplicates.add(identity.id);
107
+ else
108
+ sessions.set(identity.id, identity);
109
+ }
110
+ catch {
111
+ partial = true;
112
+ }
113
+ }
114
+ }
115
+ }
116
+ catch {
117
+ partial = true;
118
+ }
119
+ }
120
+ partial ||= queue.length > 0;
121
+ if (duplicates.has(selected.id))
122
+ return { ...empty, partial: true, error: 'Root session identity is ambiguous.' };
123
+ const belongs = (identity) => {
124
+ const seen = new Set();
125
+ let node = identity;
126
+ while (node?.parent && seen.size < 64) {
127
+ if (seen.has(node.id) || duplicates.has(node.id))
128
+ return false;
129
+ seen.add(node.id);
130
+ if (node.parent === selected.id)
131
+ return true;
132
+ node = sessions.get(node.parent);
133
+ }
134
+ return false;
135
+ };
136
+ return {
137
+ root: selected,
138
+ helpers: [...sessions.values()].filter(belongs).sort((a, b) => a.path.localeCompare(b.path)),
139
+ partial: partial || duplicates.size > 0, error: '',
140
+ };
141
+ }
142
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/activity/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAElE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AW,EAAE;QACrD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,IAAI,IAAI,GAAgC,QAAQ,CAAC;QACjD,OAAO,IAAI,EAAE,MAAM,IAAI,IAAI,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC/D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClB,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,EAAE;gBAAE,OAAO,IAAI,CAAC;YAC7C,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC5F,OAAO,EAAE,OAAO,IAAI,UAAU,CAAC,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE;KACnD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type ActivitySnapshot } from './types.js';
2
+ /** An allowlist parser. Helper logs may begin with a complete copy of parent history. */
3
+ export declare class ActivityParser {
4
+ private readonly identity;
5
+ private readonly agentPath;
6
+ readonly snapshot: ActivitySnapshot;
7
+ private first;
8
+ private verified;
9
+ private own;
10
+ private calls;
11
+ constructor(identity: string, agentPath: string);
12
+ invalidate(): void;
13
+ consume(value: unknown): void;
14
+ private append;
15
+ private message;
16
+ private tool;
17
+ private result;
18
+ private event;
19
+ private response;
20
+ }
21
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/activity/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,gBAAgB,EAAqB,MAAM,YAAY,CAAC;AAMlG,yFAAyF;AACzF,qBAAa,cAAc;IAUb,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAAU,OAAO,CAAC,QAAQ,CAAC,SAAS;IATzE,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAGjC;IACF,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,KAAK,CAAoC;gBAEpB,QAAQ,EAAE,MAAM,EAAmB,SAAS,EAAE,MAAM;IAEjF,UAAU,IAAI,IAAI;IAOlB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IA2B7B,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,IAAI;IAUZ,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,KAAK;IA0Bb,OAAO,CAAC,QAAQ;CAiBjB"}
@@ -0,0 +1,179 @@
1
+ import { object } from './types.js';
2
+ import { publicText, sanitize } from './sanitize.js';
3
+ const MAX_EVENTS = 80;
4
+ const CALL_ID = /^[\w.:/-]{1,300}$/;
5
+ /** An allowlist parser. Helper logs may begin with a complete copy of parent history. */
6
+ export class ActivityParser {
7
+ identity;
8
+ agentPath;
9
+ snapshot = {
10
+ available: false, status: 'unknown', assignment: '', events: [], updatedAt: '',
11
+ bytesRead: 0, fileSize: 0, partial: false, limited: false, attributed: false, error: '',
12
+ };
13
+ first = true;
14
+ verified = false;
15
+ own = false;
16
+ calls = new Map();
17
+ constructor(identity, agentPath) {
18
+ this.identity = identity;
19
+ this.agentPath = agentPath;
20
+ }
21
+ invalidate() {
22
+ this.own = false;
23
+ this.calls.clear();
24
+ this.snapshot.limited = true;
25
+ if (this.first) {
26
+ this.first = false;
27
+ this.snapshot.error = 'Invalid first session record.';
28
+ }
29
+ }
30
+ consume(value) {
31
+ const record = object(value);
32
+ if (!Object.keys(object(record.payload)).length) {
33
+ this.invalidate();
34
+ return;
35
+ }
36
+ const payload = object(record.payload);
37
+ if (this.first) {
38
+ this.first = false;
39
+ if (record.type !== 'session_meta' || payload.id !== this.identity) {
40
+ this.snapshot.error = 'Session identity does not match the selected agent.';
41
+ return;
42
+ }
43
+ this.verified = true;
44
+ this.snapshot.available = true;
45
+ return; // A helper's first header never opens the attribution boundary.
46
+ }
47
+ if (!this.verified)
48
+ return;
49
+ if (record.type === 'session_meta') {
50
+ this.own = false;
51
+ this.calls.clear();
52
+ return;
53
+ }
54
+ if (payload.thread_id !== undefined) {
55
+ this.own = payload.thread_id === this.identity;
56
+ if (!this.own)
57
+ this.calls.clear();
58
+ }
59
+ if (!this.own)
60
+ return;
61
+ this.snapshot.attributed = true;
62
+ const time = sanitize(record.timestamp ?? '', 80);
63
+ if (record.type === 'event_msg')
64
+ this.event(payload, time);
65
+ if (record.type === 'response_item')
66
+ this.response(payload, time);
67
+ }
68
+ append(event) {
69
+ this.snapshot.events.push(event);
70
+ if (this.snapshot.events.length > MAX_EVENTS) {
71
+ const removed = this.snapshot.events.shift();
72
+ for (const [id, item] of this.calls)
73
+ if (item === removed)
74
+ this.calls.delete(id);
75
+ this.snapshot.limited = true;
76
+ }
77
+ this.snapshot.updatedAt = event.time;
78
+ }
79
+ message(text, label, time) {
80
+ if (!text)
81
+ return;
82
+ const preview = sanitize(text);
83
+ if (label === 'Assignment')
84
+ this.snapshot.assignment = preview;
85
+ if (this.snapshot.events.at(-1)?.text === preview)
86
+ return;
87
+ this.append({ kind: 'message', time, label, text: preview, output: '', status: '' });
88
+ }
89
+ tool(id, name, input, time) {
90
+ if (typeof id !== 'string' || !CALL_ID.test(id) || this.calls.has(id))
91
+ return;
92
+ const event = {
93
+ kind: 'tool', time, label: sanitize(name ?? 'tool', 200), text: sanitize(input), output: '', status: 'running',
94
+ };
95
+ this.append(event);
96
+ this.calls.set(id, event);
97
+ this.snapshot.status = 'running';
98
+ }
99
+ result(id, output, time, status) {
100
+ const call = typeof id === 'string' ? this.calls.get(id) : undefined;
101
+ if (!call)
102
+ return;
103
+ call.output = sanitize(output);
104
+ call.status = status ?? resultStatus(output);
105
+ this.snapshot.updatedAt = time;
106
+ }
107
+ event(payload, time) {
108
+ const states = {
109
+ task_started: 'running', task_complete: 'completed', task_failed: 'failed',
110
+ turn_failed: 'failed', turn_aborted: 'interrupted', task_aborted: 'interrupted',
111
+ };
112
+ const state = typeof payload.type === 'string' ? states[payload.type] : undefined;
113
+ if (state) {
114
+ this.snapshot.status = state;
115
+ this.snapshot.updatedAt = time;
116
+ }
117
+ if (payload.type === 'user_message')
118
+ this.message(publicText(payload.message), 'Assignment', time);
119
+ if (payload.type === 'agent_message')
120
+ this.message(publicText(payload.message), 'Assistant', time);
121
+ if (payload.type !== 'item_started' && payload.type !== 'item_completed')
122
+ return;
123
+ const item = object(payload.item);
124
+ if (item.type === 'AgentMessage' && ['commentary', 'final', 'final_answer'].includes(String(item.phase))) {
125
+ this.message(publicText(item.content), 'Assistant', time);
126
+ this.snapshot.status = item.phase === 'commentary' ? 'running' : 'completed';
127
+ return;
128
+ }
129
+ if (item.type !== 'CommandExecution' && item.type !== 'McpToolCall')
130
+ return;
131
+ this.tool(item.id, item.type === 'CommandExecution' ? 'command' : `${String(item.server)}.${String(item.tool)}`, item.command ?? item.arguments ?? '', time);
132
+ if (payload.type === 'item_completed') {
133
+ const status = ['failed', 'error', 'declined'].includes(String(item.status))
134
+ || (item.exit_code !== undefined && item.exit_code !== null && item.exit_code !== 0) ? 'failed' : 'completed';
135
+ this.result(item.id, item.aggregated_output ?? item.result ?? '', time, status);
136
+ }
137
+ }
138
+ response(payload, time) {
139
+ if (payload.type === 'message') {
140
+ const phase = payload.channel ?? payload.phase;
141
+ if (payload.role === 'user')
142
+ this.message(publicText(payload.content), 'Assignment', time);
143
+ else if (payload.role === 'assistant' && ['commentary', 'final', 'final_answer'].includes(String(phase))) {
144
+ this.message(publicText(payload.content), 'Assistant', time);
145
+ this.snapshot.status = phase === 'commentary' ? 'running' : 'completed';
146
+ }
147
+ }
148
+ else if (payload.type === 'agent_message') {
149
+ const incoming = !payload.recipient || payload.recipient === this.agentPath || payload.recipient === this.identity;
150
+ this.message(publicText(payload.content), incoming ? 'Assignment' : 'Assistant', time);
151
+ }
152
+ else if (payload.type === 'function_call' || payload.type === 'custom_tool_call') {
153
+ this.tool(payload.call_id, payload.name, payload.arguments ?? payload.input ?? '', time);
154
+ }
155
+ else if (payload.type === 'function_call_output' || payload.type === 'custom_tool_call_output') {
156
+ this.result(payload.call_id, payload.output ?? '', time);
157
+ }
158
+ }
159
+ }
160
+ function resultStatus(output) {
161
+ if (typeof output === 'string') {
162
+ try {
163
+ return resultStatus(JSON.parse(output));
164
+ }
165
+ catch {
166
+ if (/(?:Script running with cell ID|Process running with session ID)/.test(output))
167
+ return 'running';
168
+ const code = /(?:Process exited with code|exit_code["']?\s*:)\s*(-?\d+)/.exec(output);
169
+ return code && Number(code[1]) !== 0 ? 'failed' : 'returned';
170
+ }
171
+ }
172
+ const value = object(output);
173
+ if (value.isError === true || (value.exit_code != null && value.exit_code !== 0))
174
+ return 'failed';
175
+ if (value.session_id != null && value.exit_code == null)
176
+ return 'running';
177
+ return value.exit_code === 0 ? 'completed' : 'returned';
178
+ }
179
+ //# sourceMappingURL=parser.js.map