@zergai/ztc 0.23.1-dev.202611152321 → 0.24.0-beta.1
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 +299 -13
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/agent/agent.js +57 -14
- package/dist/agent/backends/http_error.d.ts +2 -0
- package/dist/agent/backends/http_error.js +2 -0
- package/dist/agent/backends/router_gate.d.ts +3 -2
- package/dist/agent/backends/router_gate.js +5 -4
- package/dist/agent/backends/router_keys.d.ts +14 -0
- package/dist/agent/backends/router_keys.js +19 -0
- package/dist/agent/backends/router_refusal.d.ts +5 -3
- package/dist/agent/backends/router_refusal.js +28 -6
- package/dist/agent/backends/types.d.ts +1 -1
- package/dist/agent/backends/zrouter_stream.js +10 -6
- package/dist/agent/commands/agent_cli.d.ts +11 -1
- package/dist/agent/commands/agent_cli.js +295 -38
- package/dist/agent/commands/diff.js +4 -1
- package/dist/agent/commands/help.js +4 -1
- package/dist/agent/commands/plan.js +3 -1
- package/dist/agent/commands/session_redaction.d.ts +16 -0
- package/dist/agent/commands/session_redaction.js +77 -0
- package/dist/agent/commands/settings.js +144 -0
- package/dist/agent/commands/types.d.ts +5 -0
- package/dist/agent/commands/usage_spec.d.ts +4 -0
- package/dist/agent/commands/usage_spec.js +10 -4
- package/dist/agent/runtime/policy.d.ts +25 -0
- package/dist/agent/runtime/policy.js +154 -26
- package/dist/agent/runtime/source_verification.js +6 -2
- package/dist/agent/runtime/tool_runtime.js +81 -3
- package/dist/agent/tools/apply_patch.js +678 -131
- package/dist/agent/tools/bus_message.d.ts +26 -1
- package/dist/agent/tools/bus_message.js +126 -10
- package/dist/agent/tools/file.d.ts +16 -1
- package/dist/agent/tools/file.js +43 -5
- package/dist/agent/tools/index.d.ts +1 -1
- package/dist/agent/tools/index.js +1 -1
- package/dist/agent/tools/pane.js +5 -0
- package/dist/agent/tools/search.js +5 -1
- package/dist/agent/tools/supervision.js +16 -2
- package/dist/agent/tools/types.d.ts +22 -0
- package/dist/app/mirror_startup.d.ts +7 -5
- package/dist/app/mirror_startup.js +7 -5
- package/dist/app/navigator_mirrors.d.ts +20 -0
- package/dist/app/navigator_mirrors.js +36 -0
- package/dist/app/workspace_layout_controller.d.ts +11 -2
- package/dist/app/workspace_layout_controller.js +13 -2
- package/dist/batch/worktree.js +9 -1
- package/dist/cli_ratatui.d.ts +264 -12
- package/dist/cli_ratatui.js +1198 -103
- package/dist/config/types.d.ts +29 -0
- package/dist/desktop/daily/source_baseline.js +3 -1
- package/dist/diagnostics/session_export.d.ts +1 -0
- package/dist/diagnostics/session_export.js +229 -26
- package/dist/emulation/tool_adapters.js +42 -5
- package/dist/headless.js +24 -5
- package/dist/instance_registry.d.ts +7 -0
- package/dist/mcp/workspace_server.d.ts +12 -1
- package/dist/mcp/workspace_server.js +75 -8
- package/dist/panes/agent_cli.d.ts +60 -3
- package/dist/panes/agent_cli.js +169 -16
- package/dist/panes/agent_pane_sessions.d.ts +22 -0
- package/dist/panes/agent_pane_sessions.js +111 -0
- package/dist/panes/agent_panes.d.ts +77 -3
- package/dist/panes/agent_panes.js +199 -10
- package/dist/panes/agent_profiles.d.ts +5 -0
- package/dist/panes/agent_profiles.js +7 -0
- package/dist/panes/agent_resume.d.ts +134 -0
- package/dist/panes/agent_resume.js +155 -0
- package/dist/panes/agent_sessions/claude_head.d.ts +32 -0
- package/dist/panes/agent_sessions/claude_head.js +122 -0
- package/dist/panes/agent_sessions/claude_store.d.ts +59 -0
- package/dist/panes/agent_sessions/claude_store.js +223 -0
- package/dist/panes/agent_sessions/codex_head.d.ts +55 -0
- package/dist/panes/agent_sessions/codex_head.js +161 -0
- package/dist/panes/agent_sessions/codex_store.d.ts +43 -0
- package/dist/panes/agent_sessions/codex_store.js +187 -0
- package/dist/panes/agent_sessions/controller.d.ts +74 -0
- package/dist/panes/agent_sessions/controller.js +110 -0
- package/dist/panes/agent_sessions/cut_json.d.ts +14 -0
- package/dist/panes/agent_sessions/cut_json.js +109 -0
- package/dist/panes/agent_sessions/limits.d.ts +48 -0
- package/dist/panes/agent_sessions/limits.js +48 -0
- package/dist/panes/agent_sessions/scan.d.ts +49 -0
- package/dist/panes/agent_sessions/scan.js +86 -0
- package/dist/panes/agent_sessions/store_fs.d.ts +51 -0
- package/dist/panes/agent_sessions/store_fs.js +128 -0
- package/dist/panes/agent_sessions/stores.d.ts +36 -0
- package/dist/panes/agent_sessions/stores.js +89 -0
- package/dist/panes/agent_sessions/title.d.ts +9 -0
- package/dist/panes/agent_sessions/title.js +51 -0
- package/dist/panes/agent_sessions/types.d.ts +48 -0
- package/dist/panes/agent_sessions/types.js +2 -0
- package/dist/panes/reply_arbitrator.d.ts +39 -0
- package/dist/panes/reply_arbitrator.js +185 -0
- package/dist/panes/reply_modes.d.ts +291 -0
- package/dist/panes/reply_modes.js +598 -0
- package/dist/runtime_info.js +11 -2
- package/dist/session.js +4 -2
- package/dist/simulation/living/context.d.ts +8 -8
- package/dist/simulation/living/types.d.ts +5 -5
- package/dist/simulation/toolkit/dynamic_state.d.ts +1 -1
- package/dist/ui/ratatui/ipc_path.d.ts +5 -0
- package/dist/ui/ratatui/ipc_path.js +23 -3
- package/dist/ui/ratatui/pane_credential_broker.d.ts +23 -8
- package/dist/ui/ratatui/pane_credential_broker.js +49 -14
- package/dist/ui/ratatui/pane_relay.d.ts +5 -2
- package/dist/ui/ratatui/pane_relay.js +86 -19
- package/dist/ui/ratatui/process.js +3 -0
- package/dist/ui/ratatui/protocol.d.ts +50 -1
- package/dist/ui/ratatui/protocol.js +56 -0
- package/dist/ui/ratatui/relay_policy.d.ts +39 -0
- package/dist/ui/ratatui/relay_policy.js +94 -0
- package/dist/ui/ratatui/screen_privacy.d.ts +15 -0
- package/dist/ui/ratatui/screen_privacy.js +24 -0
- package/dist/ui/scrollback.js +8 -0
- package/dist/ui/widgets/agent_sessions_panel.d.ts +139 -0
- package/dist/ui/widgets/agent_sessions_panel.js +542 -0
- package/dist/ui/widgets/log_view.d.ts +5 -1
- package/dist/ui/widgets/log_view.js +40 -4
- package/dist/utils/atomic_write.js +9 -11
- package/dist/utils/canonical_path.d.ts +19 -0
- package/dist/utils/canonical_path.js +44 -0
- package/dist/utils/compaction.d.ts +2 -1
- package/dist/utils/compaction.js +3 -1
- package/dist/utils/git_directory_names.d.ts +51 -0
- package/dist/utils/git_directory_names.js +429 -0
- package/dist/utils/temporary_write_root.d.ts +6 -1
- package/dist/utils/temporary_write_root.js +32 -2
- package/dist/utils/tool_result_message.d.ts +4 -1
- package/dist/utils/tool_result_message.js +6 -2
- package/dist/web/bus_hold.d.ts +70 -0
- package/dist/web/bus_hold.js +118 -0
- package/dist/web/mirror_client.d.ts +7 -3
- package/dist/web/mirror_client.js +61 -23
- package/dist/web/mirror_route_gate.d.ts +40 -0
- package/dist/web/mirror_route_gate.js +71 -0
- package/dist/web/mirror_stream.d.ts +147 -22
- package/dist/web/mirror_stream.js +350 -83
- package/dist/web/pane_credentials.d.ts +32 -1
- package/dist/web/pane_credentials.js +62 -2
- package/dist/workspace_collision.js +11 -2
- package/dist/zlm-embed.mjs +940 -273
- package/package.json +39 -7
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A JSON line that a session head ends inside, read as far as it is whole: a Claude Code session whose first prompt is
|
|
3
|
+
* a pasted screenshot or a long paste has that prompt's line cut by the 64 KiB head, and Claude Code writes the line's
|
|
4
|
+
* folder, entrypoint and sidechain flag ahead of its message.
|
|
5
|
+
*
|
|
6
|
+
* One pass over the text finds the last place it can be closed (after a whole value, or just inside a bracket), and
|
|
7
|
+
* the text up to there, closed, is parsed: `{"a":1,"b":{"c":"x` reads as {"a":1,"b":{}}. With `partialStrings`, a
|
|
8
|
+
* string value the cut falls inside is kept as far as the cut (an escape it cuts is dropped), so a long prompt's start
|
|
9
|
+
* can still be its title. A key the cut falls inside never is: its value is unknown. Nothing here throws.
|
|
10
|
+
*/
|
|
11
|
+
const WHITESPACE = new Set([' ', '\t', '\n', '\r']);
|
|
12
|
+
/** The values of a JSON object or array cut short that are whole before the cut, closed; undefined when there are none. */
|
|
13
|
+
export function closeCutJson(text, options = {}) {
|
|
14
|
+
// What closes each open container, innermost last. Nothing opens or closes after the last place to close, so this
|
|
15
|
+
// stack, at the end, is what closes the text there too.
|
|
16
|
+
const closers = [];
|
|
17
|
+
let closeAt = -1;
|
|
18
|
+
let inString = false;
|
|
19
|
+
let stringIsKey = false;
|
|
20
|
+
let escapeAt = -1;
|
|
21
|
+
let unicodeLeft = 0;
|
|
22
|
+
let scalar = false;
|
|
23
|
+
// The last character that matters outside a string: '{', '[', ',', ':', or 'k'/'v' after a key or a value.
|
|
24
|
+
let last = '';
|
|
25
|
+
for (let at = 0; at < text.length; at++) {
|
|
26
|
+
const char = text[at];
|
|
27
|
+
if (inString) {
|
|
28
|
+
if (unicodeLeft > 0) {
|
|
29
|
+
unicodeLeft -= 1;
|
|
30
|
+
if (unicodeLeft === 0)
|
|
31
|
+
escapeAt = -1;
|
|
32
|
+
}
|
|
33
|
+
else if (escapeAt !== -1) {
|
|
34
|
+
if (char === 'u')
|
|
35
|
+
unicodeLeft = 4;
|
|
36
|
+
else
|
|
37
|
+
escapeAt = -1;
|
|
38
|
+
}
|
|
39
|
+
else if (char === '\\') {
|
|
40
|
+
escapeAt = at;
|
|
41
|
+
}
|
|
42
|
+
else if (char === '"') {
|
|
43
|
+
inString = false;
|
|
44
|
+
if (stringIsKey) {
|
|
45
|
+
last = 'k';
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
last = 'v';
|
|
49
|
+
closeAt = at + 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (scalar) {
|
|
55
|
+
if (char !== ',' && char !== '}' && char !== ']' && !WHITESPACE.has(char))
|
|
56
|
+
continue;
|
|
57
|
+
// A number, true, false or null is whole once what follows it is read.
|
|
58
|
+
scalar = false;
|
|
59
|
+
last = 'v';
|
|
60
|
+
closeAt = at;
|
|
61
|
+
}
|
|
62
|
+
if (WHITESPACE.has(char))
|
|
63
|
+
continue;
|
|
64
|
+
if (closers.length === 0 && closeAt === -1 && char !== '{' && char !== '[')
|
|
65
|
+
return undefined;
|
|
66
|
+
if (char === '{' || char === '[') {
|
|
67
|
+
closers.push(char === '{' ? '}' : ']');
|
|
68
|
+
last = char;
|
|
69
|
+
closeAt = at + 1;
|
|
70
|
+
}
|
|
71
|
+
else if (char === '}' || char === ']') {
|
|
72
|
+
if (closers.pop() !== char)
|
|
73
|
+
return undefined;
|
|
74
|
+
last = 'v';
|
|
75
|
+
closeAt = at + 1;
|
|
76
|
+
if (closers.length === 0)
|
|
77
|
+
return parse(text.slice(0, closeAt));
|
|
78
|
+
}
|
|
79
|
+
else if (char === '"') {
|
|
80
|
+
inString = true;
|
|
81
|
+
// In an object, a string after its opening brace or a comma is a key.
|
|
82
|
+
stringIsKey = closers.at(-1) === '}' && (last === '{' || last === ',');
|
|
83
|
+
}
|
|
84
|
+
else if (char === ',' || char === ':') {
|
|
85
|
+
last = char;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
scalar = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (closers.length === 0)
|
|
92
|
+
return undefined;
|
|
93
|
+
const close = [...closers].reverse().join('');
|
|
94
|
+
if (inString && !stringIsKey && options.partialStrings) {
|
|
95
|
+
const end = escapeAt === -1 ? text.length : escapeAt;
|
|
96
|
+
const kept = parse(`${text.slice(0, end)}"${close}`);
|
|
97
|
+
if (kept !== undefined)
|
|
98
|
+
return kept;
|
|
99
|
+
}
|
|
100
|
+
return closeAt === -1 ? undefined : parse(`${text.slice(0, closeAt)}${close}`);
|
|
101
|
+
}
|
|
102
|
+
function parse(text) {
|
|
103
|
+
try {
|
|
104
|
+
return JSON.parse(text);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much of a Claude Code or Codex session ZTC reads to list it, and how many it reads, so the picker reads the
|
|
3
|
+
* fewest bytes it needs: the head of a file, never a whole transcript (workspace spec §14's exception).
|
|
4
|
+
*/
|
|
5
|
+
/** Claude Code: the first 64 KiB of a session file hold its folder, its entrypoint and its opening prompt. */
|
|
6
|
+
export declare const CLAUDE_HEAD_BYTES: number;
|
|
7
|
+
/**
|
|
8
|
+
* Codex: the first megabyte of a rollout. Its session_meta line alone is some 23 KB, and the first request can follow
|
|
9
|
+
* several hundred kilobytes of instructions and world state.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CODEX_HEAD_BYTES: number;
|
|
12
|
+
/** A Codex line longer than this is skipped unread: it is never the session's folder or title. */
|
|
13
|
+
export declare const CODEX_LINE_BYTES: number;
|
|
14
|
+
/** Codex's session_index.jsonl, which names sessions, is read from its end, this far back only. */
|
|
15
|
+
export declare const CODEX_INDEX_TAIL_BYTES: number;
|
|
16
|
+
/**
|
|
17
|
+
* Claude Code's command tags (<command-name>, <command-args>) are looked for only in a prompt's first 8 KiB: a slash
|
|
18
|
+
* command's name and arguments are short, and a pattern never meets an unbounded run of someone else's text.
|
|
19
|
+
*/
|
|
20
|
+
export declare const COMMAND_TAG_CHARS: number;
|
|
21
|
+
/** A title is at most this many code points, then "…". */
|
|
22
|
+
export declare const TITLE_CODE_POINTS = 200;
|
|
23
|
+
/** Rows each view of the picker shows at most. */
|
|
24
|
+
export declare const ROWS_PER_VIEW = 100;
|
|
25
|
+
/** Session files whose heads one opening of the picker reads at most, newest first. */
|
|
26
|
+
export declare const HEAD_READS_PER_OPEN = 300;
|
|
27
|
+
/** After this long the picker shows the rows it has, saying the list is partial. */
|
|
28
|
+
export declare const SCAN_DEADLINE_MS = 5000;
|
|
29
|
+
/** Session files open at once while the picker fills. */
|
|
30
|
+
export declare const READS_AT_ONCE = 4;
|
|
31
|
+
/** A session's folder that doesn't say whether it is there within this long (a sleeping NAS, a dead mount) counts as gone. */
|
|
32
|
+
export declare const FOLDER_CHECK_MS = 1000;
|
|
33
|
+
/**
|
|
34
|
+
* Folder checks waiting on the filesystem at once. A check of a dead mount can hold one of Node's four filesystem
|
|
35
|
+
* threads until the mount gives up, so no more than this many are ever held; a check still queued at its deadline is
|
|
36
|
+
* never started.
|
|
37
|
+
*/
|
|
38
|
+
export declare const FOLDER_CHECKS_AT_ONCE = 2;
|
|
39
|
+
/**
|
|
40
|
+
* Heads read at most for continue, newest first, to find this folder's latest session: Claude Code's from this
|
|
41
|
+
* folder's project folder alone, Codex's among the newest HEAD_READS_PER_OPEN rollouts, each to its first line.
|
|
42
|
+
*/
|
|
43
|
+
export declare const CONTINUE_READS = 20;
|
|
44
|
+
/**
|
|
45
|
+
* A session whose file was written this recently may still be open where ZTC can't tell: a Codex pane, one started
|
|
46
|
+
* with --continue or --last, another terminal. The picker asks for a second ↵ before resuming it.
|
|
47
|
+
*/
|
|
48
|
+
export declare const RECENT_ACTIVITY_MS: number;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much of a Claude Code or Codex session ZTC reads to list it, and how many it reads, so the picker reads the
|
|
3
|
+
* fewest bytes it needs: the head of a file, never a whole transcript (workspace spec §14's exception).
|
|
4
|
+
*/
|
|
5
|
+
/** Claude Code: the first 64 KiB of a session file hold its folder, its entrypoint and its opening prompt. */
|
|
6
|
+
export const CLAUDE_HEAD_BYTES = 64 * 1024;
|
|
7
|
+
/**
|
|
8
|
+
* Codex: the first megabyte of a rollout. Its session_meta line alone is some 23 KB, and the first request can follow
|
|
9
|
+
* several hundred kilobytes of instructions and world state.
|
|
10
|
+
*/
|
|
11
|
+
export const CODEX_HEAD_BYTES = 1024 * 1024;
|
|
12
|
+
/** A Codex line longer than this is skipped unread: it is never the session's folder or title. */
|
|
13
|
+
export const CODEX_LINE_BYTES = 256 * 1024;
|
|
14
|
+
/** Codex's session_index.jsonl, which names sessions, is read from its end, this far back only. */
|
|
15
|
+
export const CODEX_INDEX_TAIL_BYTES = 256 * 1024;
|
|
16
|
+
/**
|
|
17
|
+
* Claude Code's command tags (<command-name>, <command-args>) are looked for only in a prompt's first 8 KiB: a slash
|
|
18
|
+
* command's name and arguments are short, and a pattern never meets an unbounded run of someone else's text.
|
|
19
|
+
*/
|
|
20
|
+
export const COMMAND_TAG_CHARS = 8 * 1024;
|
|
21
|
+
/** A title is at most this many code points, then "…". */
|
|
22
|
+
export const TITLE_CODE_POINTS = 200;
|
|
23
|
+
/** Rows each view of the picker shows at most. */
|
|
24
|
+
export const ROWS_PER_VIEW = 100;
|
|
25
|
+
/** Session files whose heads one opening of the picker reads at most, newest first. */
|
|
26
|
+
export const HEAD_READS_PER_OPEN = 300;
|
|
27
|
+
/** After this long the picker shows the rows it has, saying the list is partial. */
|
|
28
|
+
export const SCAN_DEADLINE_MS = 5000;
|
|
29
|
+
/** Session files open at once while the picker fills. */
|
|
30
|
+
export const READS_AT_ONCE = 4;
|
|
31
|
+
/** A session's folder that doesn't say whether it is there within this long (a sleeping NAS, a dead mount) counts as gone. */
|
|
32
|
+
export const FOLDER_CHECK_MS = 1000;
|
|
33
|
+
/**
|
|
34
|
+
* Folder checks waiting on the filesystem at once. A check of a dead mount can hold one of Node's four filesystem
|
|
35
|
+
* threads until the mount gives up, so no more than this many are ever held; a check still queued at its deadline is
|
|
36
|
+
* never started.
|
|
37
|
+
*/
|
|
38
|
+
export const FOLDER_CHECKS_AT_ONCE = 2;
|
|
39
|
+
/**
|
|
40
|
+
* Heads read at most for continue, newest first, to find this folder's latest session: Claude Code's from this
|
|
41
|
+
* folder's project folder alone, Codex's among the newest HEAD_READS_PER_OPEN rollouts, each to its first line.
|
|
42
|
+
*/
|
|
43
|
+
export const CONTINUE_READS = 20;
|
|
44
|
+
/**
|
|
45
|
+
* A session whose file was written this recently may still be open where ZTC can't tell: a Codex pane, one started
|
|
46
|
+
* with --continue or --last, another terminal. The picker asks for a second ↵ before resuming it.
|
|
47
|
+
*/
|
|
48
|
+
export const RECENT_ACTIVITY_MS = 2 * 60_000;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading session heads for the picker: which files to read, in what order, how many at once and until when, and how
|
|
3
|
+
* the rows they give are ordered. Shared by the Claude Code and Codex readers.
|
|
4
|
+
*/
|
|
5
|
+
import type { AgentSessionRow, SessionCandidate, SessionListing } from './types.js';
|
|
6
|
+
/** What reading one candidate gave: a row to list, a row the picker leaves out, or nothing readable. */
|
|
7
|
+
export type CandidateRead = {
|
|
8
|
+
row: AgentSessionRow;
|
|
9
|
+
listed: boolean;
|
|
10
|
+
} | null;
|
|
11
|
+
export interface ScanOptions {
|
|
12
|
+
/** Files read at once (default READS_AT_ONCE). */
|
|
13
|
+
atOnce?: number;
|
|
14
|
+
/** No file is started after this long (default SCAN_DEADLINE_MS). */
|
|
15
|
+
deadlineMs?: number;
|
|
16
|
+
/** Clock for the deadline (default: Date.now). */
|
|
17
|
+
now?: () => number;
|
|
18
|
+
/** Each listed row as its file is read. */
|
|
19
|
+
onRow?: (row: AgentSessionRow) => void;
|
|
20
|
+
}
|
|
21
|
+
/** Newest first, ties by id. */
|
|
22
|
+
export declare function byRecency(a: {
|
|
23
|
+
mtimeMs: number;
|
|
24
|
+
id: string;
|
|
25
|
+
}, b: {
|
|
26
|
+
mtimeMs: number;
|
|
27
|
+
id: string;
|
|
28
|
+
}): number;
|
|
29
|
+
/**
|
|
30
|
+
* The files to read: the newest `maxReads` of all, and besides them the newest `maxReads` that `priority` picks (this
|
|
31
|
+
* folder's, for Claude Code), however old, so this folder's list is never empty for an old project nor takes the
|
|
32
|
+
* reads All folders needs; at most twice `maxReads` in all, even where every file is this folder's (the home folder).
|
|
33
|
+
* The picked ones are read first, then the rest; each group newest first.
|
|
34
|
+
*/
|
|
35
|
+
export declare function chooseReads(candidates: readonly SessionCandidate[], options?: {
|
|
36
|
+
maxReads?: number;
|
|
37
|
+
priority?: (candidate: SessionCandidate) => boolean;
|
|
38
|
+
}): SessionCandidate[];
|
|
39
|
+
/**
|
|
40
|
+
* One row per session in each sign-in's store, from its newest file there: a session copied into a profile's store is
|
|
41
|
+
* listed in both, so either can be opened. Newest first, ties by id, then by store.
|
|
42
|
+
*/
|
|
43
|
+
export declare function orderRows(rows: readonly AgentSessionRow[]): AgentSessionRow[];
|
|
44
|
+
/**
|
|
45
|
+
* Read candidates in order, `atOnce` at a time, starting none after the deadline, and give the listed rows ordered
|
|
46
|
+
* (orderRows), with how many were read and how many of those left out. `partial` says some were left unread at the
|
|
47
|
+
* deadline. What isn't a candidate (`older`, `links`) the caller counts.
|
|
48
|
+
*/
|
|
49
|
+
export declare function readInOrder(candidates: readonly SessionCandidate[], read: (candidate: SessionCandidate) => Promise<CandidateRead>, options?: ScanOptions): Promise<SessionListing>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading session heads for the picker: which files to read, in what order, how many at once and until when, and how
|
|
3
|
+
* the rows they give are ordered. Shared by the Claude Code and Codex readers.
|
|
4
|
+
*/
|
|
5
|
+
import { HEAD_READS_PER_OPEN, READS_AT_ONCE, SCAN_DEADLINE_MS } from './limits.js';
|
|
6
|
+
/** Newest first, ties by id. */
|
|
7
|
+
export function byRecency(a, b) {
|
|
8
|
+
return b.mtimeMs - a.mtimeMs || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The files to read: the newest `maxReads` of all, and besides them the newest `maxReads` that `priority` picks (this
|
|
12
|
+
* folder's, for Claude Code), however old, so this folder's list is never empty for an old project nor takes the
|
|
13
|
+
* reads All folders needs; at most twice `maxReads` in all, even where every file is this folder's (the home folder).
|
|
14
|
+
* The picked ones are read first, then the rest; each group newest first.
|
|
15
|
+
*/
|
|
16
|
+
export function chooseReads(candidates, options = {}) {
|
|
17
|
+
const limit = Math.max(0, options.maxReads ?? HEAD_READS_PER_OPEN);
|
|
18
|
+
const sorted = [...candidates].sort(byRecency);
|
|
19
|
+
const picked = options.priority ? sorted.filter(options.priority).slice(0, limit) : [];
|
|
20
|
+
const chosen = new Set(picked);
|
|
21
|
+
return [...picked, ...sorted.slice(0, limit).filter(candidate => !chosen.has(candidate))];
|
|
22
|
+
}
|
|
23
|
+
/** This computer's own store first, then the profiles' by name. */
|
|
24
|
+
function byStore(a, b) {
|
|
25
|
+
if (a.profile === b.profile)
|
|
26
|
+
return 0;
|
|
27
|
+
if (a.profile === null)
|
|
28
|
+
return -1;
|
|
29
|
+
if (b.profile === null)
|
|
30
|
+
return 1;
|
|
31
|
+
return a.profile < b.profile ? -1 : 1;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* One row per session in each sign-in's store, from its newest file there: a session copied into a profile's store is
|
|
35
|
+
* listed in both, so either can be opened. Newest first, ties by id, then by store.
|
|
36
|
+
*/
|
|
37
|
+
export function orderRows(rows) {
|
|
38
|
+
const newest = new Map();
|
|
39
|
+
for (const row of rows) {
|
|
40
|
+
// A profile's name has no ':' (agent_profiles.ts), so the key can't be mistaken.
|
|
41
|
+
const key = `${row.cli}:${row.profile ?? ''}:${row.id}`;
|
|
42
|
+
const known = newest.get(key);
|
|
43
|
+
if (!known || row.mtimeMs > known.mtimeMs)
|
|
44
|
+
newest.set(key, row);
|
|
45
|
+
}
|
|
46
|
+
return [...newest.values()].sort((a, b) => byRecency(a, b) || byStore(a, b));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Read candidates in order, `atOnce` at a time, starting none after the deadline, and give the listed rows ordered
|
|
50
|
+
* (orderRows), with how many were read and how many of those left out. `partial` says some were left unread at the
|
|
51
|
+
* deadline. What isn't a candidate (`older`, `links`) the caller counts.
|
|
52
|
+
*/
|
|
53
|
+
export async function readInOrder(candidates, read, options = {}) {
|
|
54
|
+
const now = options.now ?? Date.now;
|
|
55
|
+
const started = now();
|
|
56
|
+
const deadline = options.deadlineMs ?? SCAN_DEADLINE_MS;
|
|
57
|
+
const rows = [];
|
|
58
|
+
let unreadable = 0;
|
|
59
|
+
let skipped = 0;
|
|
60
|
+
let next = 0;
|
|
61
|
+
const worker = async () => {
|
|
62
|
+
while (next < candidates.length && now() - started < deadline) {
|
|
63
|
+
const candidate = candidates[next++];
|
|
64
|
+
let result;
|
|
65
|
+
try {
|
|
66
|
+
result = await read(candidate);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
result = null;
|
|
70
|
+
}
|
|
71
|
+
if (!result) {
|
|
72
|
+
unreadable += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!result.listed) {
|
|
76
|
+
skipped += 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
rows.push(result.row);
|
|
80
|
+
options.onRow?.(result.row);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const workers = Math.max(1, Math.min(options.atOnce ?? READS_AT_ONCE, candidates.length));
|
|
84
|
+
await Promise.all(Array.from({ length: workers }, () => worker()));
|
|
85
|
+
return { rows: orderRows(rows), unreadable, partial: next < candidates.length, read: next, skipped, older: 0, links: 0 };
|
|
86
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The filesystem as the session readers see it: listing a folder, looking at a path without following it, and opening
|
|
3
|
+
* a regular file to read part of it. Every read names its position and length, so a reader can never take more than
|
|
4
|
+
* it asks for, and a test can wrap this to record exactly what was opened and read.
|
|
5
|
+
*
|
|
6
|
+
* A path is read only when it is a regular file reached without a symbolic link (O_NOFOLLOW) and with no other name
|
|
7
|
+
* (one link): a link in a session store, symbolic or hard, could lead to a sign-in file. A FIFO or a device is never
|
|
8
|
+
* read (O_NONBLOCK, then fstat), and a file with a second name is closed unread.
|
|
9
|
+
*/
|
|
10
|
+
export type SessionPathKind = 'file' | 'directory' | 'link' | 'other';
|
|
11
|
+
export interface SessionDirEntry {
|
|
12
|
+
name: string;
|
|
13
|
+
kind: SessionPathKind;
|
|
14
|
+
}
|
|
15
|
+
export interface SessionPathInfo {
|
|
16
|
+
kind: SessionPathKind;
|
|
17
|
+
size: number;
|
|
18
|
+
mtimeMs: number;
|
|
19
|
+
}
|
|
20
|
+
export interface SessionFile {
|
|
21
|
+
readonly size: number;
|
|
22
|
+
/** Up to `length` bytes from `position`: fewer at the end of the file. */
|
|
23
|
+
read(position: number, length: number): Promise<Buffer>;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export interface SessionStoreFs {
|
|
27
|
+
/** A folder's entries, links unfollowed; none when it can't be listed. */
|
|
28
|
+
list(dir: string): Promise<SessionDirEntry[]>;
|
|
29
|
+
/** What is at `path`, the link itself for a link; null when nothing is. */
|
|
30
|
+
lstat(path: string): Promise<SessionPathInfo | null>;
|
|
31
|
+
/** A regular file with one name, opened to read; null for anything else, a path through a link or a hard link. */
|
|
32
|
+
open(path: string): Promise<SessionFile | null>;
|
|
33
|
+
}
|
|
34
|
+
/** The real filesystem, through `fs.promises`, read at the moment of each call. */
|
|
35
|
+
export declare const nodeSessionStoreFs: SessionStoreFs;
|
|
36
|
+
/**
|
|
37
|
+
* The first `maxBytes` of a regular file, or all of it when shorter (`whole`), in bounded reads that never pass
|
|
38
|
+
* `maxBytes`. Null when it isn't a regular file or can't be read.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readFileHead(store: SessionStoreFs, path: string, maxBytes: number): Promise<{
|
|
41
|
+
bytes: Buffer;
|
|
42
|
+
whole: boolean;
|
|
43
|
+
} | null>;
|
|
44
|
+
/**
|
|
45
|
+
* The last `maxBytes` of a regular file, or all of it when shorter (`whole`), in bounded reads. Null when it isn't a
|
|
46
|
+
* regular file or can't be read.
|
|
47
|
+
*/
|
|
48
|
+
export declare function readFileTail(store: SessionStoreFs, path: string, maxBytes: number): Promise<{
|
|
49
|
+
bytes: Buffer;
|
|
50
|
+
whole: boolean;
|
|
51
|
+
} | null>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The filesystem as the session readers see it: listing a folder, looking at a path without following it, and opening
|
|
3
|
+
* a regular file to read part of it. Every read names its position and length, so a reader can never take more than
|
|
4
|
+
* it asks for, and a test can wrap this to record exactly what was opened and read.
|
|
5
|
+
*
|
|
6
|
+
* A path is read only when it is a regular file reached without a symbolic link (O_NOFOLLOW) and with no other name
|
|
7
|
+
* (one link): a link in a session store, symbolic or hard, could lead to a sign-in file. A FIFO or a device is never
|
|
8
|
+
* read (O_NONBLOCK, then fstat), and a file with a second name is closed unread.
|
|
9
|
+
*/
|
|
10
|
+
import fs, { constants } from 'node:fs';
|
|
11
|
+
function kindOf(entry) {
|
|
12
|
+
if (entry.isSymbolicLink())
|
|
13
|
+
return 'link';
|
|
14
|
+
if (entry.isFile())
|
|
15
|
+
return 'file';
|
|
16
|
+
if (entry.isDirectory())
|
|
17
|
+
return 'directory';
|
|
18
|
+
return 'other';
|
|
19
|
+
}
|
|
20
|
+
const OPEN_FLAGS = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
|
|
21
|
+
/** The real filesystem, through `fs.promises`, read at the moment of each call. */
|
|
22
|
+
export const nodeSessionStoreFs = {
|
|
23
|
+
async list(dir) {
|
|
24
|
+
try {
|
|
25
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
26
|
+
return entries.map(entry => ({ name: entry.name, kind: kindOf(entry) }));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
async lstat(path) {
|
|
33
|
+
try {
|
|
34
|
+
const info = await fs.promises.lstat(path);
|
|
35
|
+
return { kind: kindOf(info), size: info.size, mtimeMs: info.mtimeMs };
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
async open(path) {
|
|
42
|
+
let handle;
|
|
43
|
+
try {
|
|
44
|
+
handle = await fs.promises.open(path, OPEN_FLAGS);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const info = await handle.stat();
|
|
51
|
+
if (!info.isFile() || info.nlink !== 1) {
|
|
52
|
+
await handle.close();
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
size: info.size,
|
|
57
|
+
async read(position, length) {
|
|
58
|
+
const buffer = Buffer.alloc(Math.max(0, length));
|
|
59
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, position);
|
|
60
|
+
return buffer.subarray(0, bytesRead);
|
|
61
|
+
},
|
|
62
|
+
close: () => handle.close(),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
await handle.close().catch(() => { });
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
/** Reads that size a chunk: a reader asks for at most this much at a time. */
|
|
72
|
+
const CHUNK_BYTES = 64 * 1024;
|
|
73
|
+
/**
|
|
74
|
+
* The first `maxBytes` of a regular file, or all of it when shorter (`whole`), in bounded reads that never pass
|
|
75
|
+
* `maxBytes`. Null when it isn't a regular file or can't be read.
|
|
76
|
+
*/
|
|
77
|
+
export async function readFileHead(store, path, maxBytes) {
|
|
78
|
+
const file = await store.open(path);
|
|
79
|
+
if (!file)
|
|
80
|
+
return null;
|
|
81
|
+
try {
|
|
82
|
+
const limit = Math.min(file.size, Math.max(0, maxBytes));
|
|
83
|
+
const chunks = [];
|
|
84
|
+
let read = 0;
|
|
85
|
+
while (read < limit) {
|
|
86
|
+
const chunk = await file.read(read, Math.min(CHUNK_BYTES, limit - read));
|
|
87
|
+
if (chunk.length === 0)
|
|
88
|
+
break;
|
|
89
|
+
chunks.push(chunk);
|
|
90
|
+
read += chunk.length;
|
|
91
|
+
}
|
|
92
|
+
return { bytes: Buffer.concat(chunks), whole: file.size <= maxBytes && read === file.size };
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
await file.close().catch(() => { });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The last `maxBytes` of a regular file, or all of it when shorter (`whole`), in bounded reads. Null when it isn't a
|
|
103
|
+
* regular file or can't be read.
|
|
104
|
+
*/
|
|
105
|
+
export async function readFileTail(store, path, maxBytes) {
|
|
106
|
+
const file = await store.open(path);
|
|
107
|
+
if (!file)
|
|
108
|
+
return null;
|
|
109
|
+
try {
|
|
110
|
+
const start = Math.max(0, file.size - Math.max(0, maxBytes));
|
|
111
|
+
const chunks = [];
|
|
112
|
+
let at = start;
|
|
113
|
+
while (at < file.size) {
|
|
114
|
+
const chunk = await file.read(at, Math.min(CHUNK_BYTES, file.size - at));
|
|
115
|
+
if (chunk.length === 0)
|
|
116
|
+
break;
|
|
117
|
+
chunks.push(chunk);
|
|
118
|
+
at += chunk.length;
|
|
119
|
+
}
|
|
120
|
+
return { bytes: Buffer.concat(chunks), whole: start === 0 };
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
await file.close().catch(() => { });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where Claude Code and Codex keep the sessions a person can resume: this computer's own config directory for each
|
|
3
|
+
* CLI, and each ZTC sign-in profile's (panes/agent_profiles.ts).
|
|
4
|
+
*
|
|
5
|
+
* A store is a config directory and the one folder of it that holds sessions: `projects/` for Claude Code, `sessions/`
|
|
6
|
+
* for Codex. Only that folder is ever listed, and only when it is a real folder: one that is a symbolic link could
|
|
7
|
+
* lead anywhere, so it is skipped, and said (agentSessionStoreLinks). Nothing here creates or changes anything. The
|
|
8
|
+
* only other file of a config directory a reader opens is Codex's session_index.jsonl, for names (codex_store.ts).
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentCliId } from '../agent_cli.js';
|
|
11
|
+
import { type RegisteredProfileDirs } from '../agent_profiles.js';
|
|
12
|
+
export interface AgentSessionStore {
|
|
13
|
+
cli: AgentCliId;
|
|
14
|
+
/** The ZTC sign-in profile the store belongs to; null for this computer's own sign-in. */
|
|
15
|
+
profile: string | null;
|
|
16
|
+
/** The CLI's config directory: ~/.claude or CLAUDE_CONFIG_DIR, ~/.codex or CODEX_HOME, or the profile's. */
|
|
17
|
+
configDir: string;
|
|
18
|
+
/** Where its sessions are: `<configDir>/projects` for Claude Code, `<configDir>/sessions` for Codex. */
|
|
19
|
+
sessionsDir: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SessionStoreLookup {
|
|
22
|
+
env: NodeJS.ProcessEnv;
|
|
23
|
+
home: string;
|
|
24
|
+
/** Profiles registered on directories of their own (panes.agentProfileDirs[cli]). */
|
|
25
|
+
registered?: RegisteredProfileDirs;
|
|
26
|
+
}
|
|
27
|
+
/** The CLI's own config directory on this computer: its variable's, else ~/.claude or ~/.codex. */
|
|
28
|
+
export declare function ownAgentConfigDir(cli: AgentCliId, lookup: SessionStoreLookup): string;
|
|
29
|
+
/**
|
|
30
|
+
* The CLI's session stores: this computer's own first, then each ZTC profile's by name, the ones under
|
|
31
|
+
* ~/.ztc/agent-profiles/<cli>/ and the registered ones alike. Each config directory counts once (a profile registered
|
|
32
|
+
* on ~/.claude is the own store), and a store whose sessions folder is missing, or is a link, is left out.
|
|
33
|
+
*/
|
|
34
|
+
export declare function agentSessionStores(cli: AgentCliId, lookup: SessionStoreLookup): AgentSessionStore[];
|
|
35
|
+
/** The sessions folders, of this computer's own store and each profile's, that are symbolic links, which are never followed. */
|
|
36
|
+
export declare function agentSessionStoreLinks(cli: AgentCliId, lookup: SessionStoreLookup): string[];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where Claude Code and Codex keep the sessions a person can resume: this computer's own config directory for each
|
|
3
|
+
* CLI, and each ZTC sign-in profile's (panes/agent_profiles.ts).
|
|
4
|
+
*
|
|
5
|
+
* A store is a config directory and the one folder of it that holds sessions: `projects/` for Claude Code, `sessions/`
|
|
6
|
+
* for Codex. Only that folder is ever listed, and only when it is a real folder: one that is a symbolic link could
|
|
7
|
+
* lead anywhere, so it is skipped, and said (agentSessionStoreLinks). Nothing here creates or changes anything. The
|
|
8
|
+
* only other file of a config directory a reader opens is Codex's session_index.jsonl, for names (codex_store.ts).
|
|
9
|
+
*/
|
|
10
|
+
import { lstatSync, realpathSync } from 'node:fs';
|
|
11
|
+
import { join, resolve } from 'node:path';
|
|
12
|
+
import { agentProfileDir, listAgentProfiles } from '../agent_profiles.js';
|
|
13
|
+
/** The variable each CLI reads its config directory from, and the folder it uses without one. */
|
|
14
|
+
const CONFIG_HOME = Object.freeze({
|
|
15
|
+
claude: { variable: 'CLAUDE_CONFIG_DIR', folder: '.claude', sessions: 'projects' },
|
|
16
|
+
codex: { variable: 'CODEX_HOME', folder: '.codex', sessions: 'sessions' },
|
|
17
|
+
});
|
|
18
|
+
/** The CLI's own config directory on this computer: its variable's, else ~/.claude or ~/.codex. */
|
|
19
|
+
export function ownAgentConfigDir(cli, lookup) {
|
|
20
|
+
const { variable, folder } = CONFIG_HOME[cli];
|
|
21
|
+
const set = lookup.env[variable];
|
|
22
|
+
return set ? resolve(set) : join(lookup.home, folder);
|
|
23
|
+
}
|
|
24
|
+
/** Whether `path` is a folder itself, not a symbolic link to one. */
|
|
25
|
+
function isRealFolder(path) {
|
|
26
|
+
try {
|
|
27
|
+
return lstatSync(path).isDirectory();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** The folder a path names once links are followed, to tell one folder reached two ways apart from two. */
|
|
34
|
+
function sameFolderKey(path) {
|
|
35
|
+
try {
|
|
36
|
+
return realpathSync(path);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return resolve(path);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Whether `path` is a symbolic link itself. */
|
|
43
|
+
function isLink(path) {
|
|
44
|
+
try {
|
|
45
|
+
return lstatSync(path).isSymbolicLink();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Each config directory the CLI may keep sessions in, once: this computer's own, then each ZTC profile's by name. */
|
|
52
|
+
function storeCandidates(cli, lookup) {
|
|
53
|
+
const registered = lookup.registered ?? {};
|
|
54
|
+
const candidates = [{ profile: null, configDir: ownAgentConfigDir(cli, lookup) }];
|
|
55
|
+
for (const profile of listAgentProfiles(cli, lookup.home, registered)) {
|
|
56
|
+
let configDir;
|
|
57
|
+
try {
|
|
58
|
+
configDir = agentProfileDir(cli, profile, lookup.home, registered);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
candidates.push({ profile, configDir });
|
|
64
|
+
}
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
const unique = [];
|
|
67
|
+
for (const candidate of candidates) {
|
|
68
|
+
const key = sameFolderKey(candidate.configDir);
|
|
69
|
+
if (seen.has(key))
|
|
70
|
+
continue;
|
|
71
|
+
seen.add(key);
|
|
72
|
+
unique.push({ ...candidate, sessionsDir: join(candidate.configDir, CONFIG_HOME[cli].sessions) });
|
|
73
|
+
}
|
|
74
|
+
return unique;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The CLI's session stores: this computer's own first, then each ZTC profile's by name, the ones under
|
|
78
|
+
* ~/.ztc/agent-profiles/<cli>/ and the registered ones alike. Each config directory counts once (a profile registered
|
|
79
|
+
* on ~/.claude is the own store), and a store whose sessions folder is missing, or is a link, is left out.
|
|
80
|
+
*/
|
|
81
|
+
export function agentSessionStores(cli, lookup) {
|
|
82
|
+
return storeCandidates(cli, lookup)
|
|
83
|
+
.filter(candidate => isRealFolder(candidate.sessionsDir))
|
|
84
|
+
.map(candidate => ({ cli, profile: candidate.profile, configDir: candidate.configDir, sessionsDir: candidate.sessionsDir }));
|
|
85
|
+
}
|
|
86
|
+
/** The sessions folders, of this computer's own store and each profile's, that are symbolic links, which are never followed. */
|
|
87
|
+
export function agentSessionStoreLinks(cli, lookup) {
|
|
88
|
+
return storeCandidates(cli, lookup).filter(candidate => isLink(candidate.sessionsDir)).map(candidate => candidate.sessionsDir);
|
|
89
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A session's title as the picker shows it: one clean line, at most TITLE_CODE_POINTS code points and "…".
|
|
3
|
+
*
|
|
4
|
+
* A title comes from a file someone else's program wrote, so nothing in it may act on the terminal: controls (C0, C1,
|
|
5
|
+
* DEL) and the bidirectional controls that reorder the text after them are dropped, lone surrogates too, and every run
|
|
6
|
+
* of whitespace, line breaks included, becomes one space.
|
|
7
|
+
*/
|
|
8
|
+
/** One line of a session's name, title or prompt, or null when nothing printable is left. */
|
|
9
|
+
export declare function sessionTitle(text: unknown): string | null;
|