sideby 0.41.2 → 0.42.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.
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +2 -0
- package/dist/src/cli/commands.js +263 -32
- package/dist/src/cli/json-schemas.js +85 -4
- package/dist/src/cli/main.js +49 -7
- package/dist/src/core/claude-memory.d.ts +236 -0
- package/dist/src/core/claude-memory.js +937 -0
- package/dist/src/core/cli-commands.js +16 -3
- package/dist/src/core/config.d.ts +17 -0
- package/dist/src/core/config.js +266 -43
- package/dist/src/core/history-project.d.ts +14 -0
- package/dist/src/core/history-project.js +42 -12
- package/dist/src/core/history.d.ts +4 -6
- package/dist/src/core/history.js +5 -15
- package/dist/src/core/local-build.d.ts +12 -0
- package/dist/src/core/local-build.js +32 -0
- package/dist/src/core/search-catalog.js +49 -0
- package/dist/src/core/session-hooks.d.ts +12 -2
- package/dist/src/core/session-hooks.js +12 -8
- package/dist/src/core/unattended-followup.d.ts +62 -0
- package/dist/src/core/unattended-followup.js +205 -0
- package/dist/src/core/unattended-pending.d.ts +11 -3
- package/dist/src/core/unattended-pending.js +34 -8
- package/dist/src/families/claude/history.js +9 -1
- package/dist/src/families/claude/layout.d.ts +7 -0
- package/dist/src/families/claude/layout.js +17 -0
- package/dist/src/families/claude/live-sessions.js +2 -1
- package/dist/src/families/history.d.ts +22 -2
- package/dist/src/families/history.js +55 -0
- package/dist/src/handoff/messages.js +1 -1
- package/dist/src/panel/handler.d.ts +22 -4
- package/dist/src/panel/handler.js +71 -25
- package/dist/src/panel/i18n.d.ts +35 -1
- package/dist/src/panel/i18n.js +72 -4
- package/dist/src/panel/page-logic.d.ts +53 -0
- package/dist/src/panel/page-logic.js +96 -0
- package/dist/src/panel/page-script.js +174 -36
- package/dist/src/panel/page-styles.js +18 -0
- package/dist/src/runtime.d.ts +30 -0
- package/dist/src/runtime.js +85 -1
- package/dist/src/unattended/hook.d.ts +10 -5
- package/dist/src/unattended/hook.js +17 -12
- package/package.json +1 -1
- package/schemas/config.json +5 -1
- package/schemas/memory-set.json +117 -0
- package/schemas/memory.json +210 -0
- package/schemas/unattended-pending.json +156 -56
- package/skills/sideby/SKILL.md +3 -1
- package/skills/sideby/references/diagnose.md +1 -0
- package/skills/sideby/references/handoff.md +1 -1
- package/skills/sideby/references/panel.md +1 -1
- package/skills/sideby/references/sharing.md +23 -1
- package/skills/sideby/references/unattended.md +16 -5
|
@@ -108,6 +108,35 @@ export function offPlan(kept, latest) {
|
|
|
108
108
|
return 'restore';
|
|
109
109
|
return (compareVersions(kept, latest) ?? -1) >= 0 ? 'restore' : 'install';
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Whether the sideby in `dir` can read the user's config file (spec §3.10, ADR-0080): runs its `config get --json`,
|
|
113
|
+
* which reads only that file, in `env` so `HOME` and `XDG_CONFIG_HOME` name the same file the user's sideby reads.
|
|
114
|
+
* Null when it can, else what it said. A build older than the sideby that wrote the config may not: 0.41.2 and older
|
|
115
|
+
* stop at a key they do not know.
|
|
116
|
+
*/
|
|
117
|
+
export async function configReadProblem(dir, env, run = runProgram) {
|
|
118
|
+
const r = await run(process.execPath, [join(dir, BIN), 'config', 'get', '--json'], {
|
|
119
|
+
env: { ...env, SIDEBY_NO_UPDATE_NOTIFIER: '1' },
|
|
120
|
+
}).catch((e) => ({ code: -1, output: e instanceof Error ? e.message : String(e) }));
|
|
121
|
+
if (r.code === 0)
|
|
122
|
+
return null;
|
|
123
|
+
// A `--json` error is `{ "error": "…" }`; anything else (a crash) is shown as it came, shortened.
|
|
124
|
+
const m = /"error":\s*("(?:[^"\\]|\\.)*")/.exec(r.output);
|
|
125
|
+
let said = r.output.trim();
|
|
126
|
+
if (m) {
|
|
127
|
+
try {
|
|
128
|
+
said = JSON.parse(m[1]);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// keep the raw output
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return said.slice(0, 1000) || `it exited with code ${r.code}`;
|
|
135
|
+
}
|
|
136
|
+
/** What `pnpm local` and the switch say when a build cannot read the config: the cause and what to do (`fix`). */
|
|
137
|
+
export const configReadRefusal = (who, problem, fix) => `${who} cannot read your sideby config, so the running build was kept. It said: ${problem}. If a newer sideby wrote that config, ${fix} If the config file itself is wrong, fix what the message names first.`;
|
|
138
|
+
/** The fix for a Local Build older than the config: build it again from a checkout that has the newer code. */
|
|
139
|
+
export const REBUILD_FIX = 'this build is older than it: rebase the sideby checkout onto main (`git fetch origin && git rebase origin/main`) and run `pnpm local` again.';
|
|
111
140
|
export async function localStatus(d) {
|
|
112
141
|
const k = await kind(globalPkg(d));
|
|
113
142
|
const running = k === 'link'
|
|
@@ -192,6 +221,9 @@ export async function switchLocal(paths, d, to, env, opts = {}) {
|
|
|
192
221
|
let message;
|
|
193
222
|
try {
|
|
194
223
|
if (to === 'local') {
|
|
224
|
+
const problem = await configReadProblem(pkgDir(d), env);
|
|
225
|
+
if (problem)
|
|
226
|
+
return fail(configReadRefusal('The local build', problem, REBUILD_FIX));
|
|
195
227
|
await linkGlobal(d);
|
|
196
228
|
message = `the global sideby runs the local build ${before.local?.commit ?? ''}`.trim();
|
|
197
229
|
}
|
|
@@ -228,6 +228,28 @@ const ENTRIES = [
|
|
|
228
228
|
target: { settings: 'trust', find: 'trust' },
|
|
229
229
|
cliCommand: 'sideby trust',
|
|
230
230
|
},
|
|
231
|
+
{
|
|
232
|
+
id: 'setting.memory',
|
|
233
|
+
kind: 'setting',
|
|
234
|
+
title: { en: 'Shared memory', zh: '共享记忆' },
|
|
235
|
+
synonyms: [
|
|
236
|
+
'memory',
|
|
237
|
+
'auto memory',
|
|
238
|
+
'project memory',
|
|
239
|
+
'shared memory',
|
|
240
|
+
'remember',
|
|
241
|
+
'MEMORY.md',
|
|
242
|
+
'autoMemoryDirectory',
|
|
243
|
+
'记忆',
|
|
244
|
+
'项目记忆',
|
|
245
|
+
'共享项目记忆',
|
|
246
|
+
'自动记忆',
|
|
247
|
+
'记不住',
|
|
248
|
+
],
|
|
249
|
+
panel: at(SET, { en: 'Shared memory', zh: '共享记忆' }),
|
|
250
|
+
target: { settings: 'memory', find: 'memory' },
|
|
251
|
+
cliCommand: 'sideby memory',
|
|
252
|
+
},
|
|
231
253
|
{
|
|
232
254
|
id: 'setting.quota-checks',
|
|
233
255
|
kind: 'setting',
|
|
@@ -371,6 +393,33 @@ const ENTRIES = [
|
|
|
371
393
|
target: { action: 'unattended-add-slot', write: true },
|
|
372
394
|
cliCommand: 'sideby unattended schedule add',
|
|
373
395
|
},
|
|
396
|
+
{
|
|
397
|
+
id: 'action.unattended-pending',
|
|
398
|
+
kind: 'action',
|
|
399
|
+
title: { en: 'See what sessions left for you, by project', zh: '按项目看待你决定的事' },
|
|
400
|
+
synonyms: [
|
|
401
|
+
'pending decisions',
|
|
402
|
+
'waiting for you',
|
|
403
|
+
'not handled',
|
|
404
|
+
'wrote in the session afterwards',
|
|
405
|
+
'待你决定',
|
|
406
|
+
'哪些处理了',
|
|
407
|
+
'没处理的',
|
|
408
|
+
'之后说过话',
|
|
409
|
+
],
|
|
410
|
+
panel: at({ en: 'Unattended page', zh: '无人值守页' }, { en: 'Waiting for you', zh: '待你决定' }),
|
|
411
|
+
target: { action: 'unattended-pending', write: false },
|
|
412
|
+
cliCommand: 'sideby unattended pending',
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
id: 'action.unattended-pending-reopen',
|
|
416
|
+
kind: 'action',
|
|
417
|
+
title: { en: 'Reopen a decision marked done by mistake', zh: '重新打开标错的待决事项' },
|
|
418
|
+
synonyms: ['reopen', 'undo done', 'marked done by mistake', '重新打开', '标错了', '撤销已处理'],
|
|
419
|
+
panel: at({ en: 'Unattended page', zh: '无人值守页' }, { en: 'Done', zh: '已处理' }),
|
|
420
|
+
target: { action: 'unattended-pending-done', write: false },
|
|
421
|
+
cliCommand: 'sideby unattended pending reopen',
|
|
422
|
+
},
|
|
374
423
|
{
|
|
375
424
|
id: 'action.unattended-wait',
|
|
376
425
|
kind: 'action',
|
|
@@ -7,6 +7,13 @@ export interface SessionHookPart {
|
|
|
7
7
|
claude: ClaudeHooks;
|
|
8
8
|
/** Per Codex event, the inline TOML tables of its list, such as `{matcher="…",hooks=[{type="command",command="…"}]}`. */
|
|
9
9
|
codex: Record<string, string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Other top-level Claude settings it adds to the same file, such as `autoMemoryDirectory` (Shared Project Memory,
|
|
12
|
+
* ADR-0081). Claude only.
|
|
13
|
+
*/
|
|
14
|
+
settings?: Record<string, unknown>;
|
|
15
|
+
/** Added to the file's name when `settings` differ per Launch, so two Launches never share one file. */
|
|
16
|
+
fileKey?: string;
|
|
10
17
|
}
|
|
11
18
|
/**
|
|
12
19
|
* The command a Host runs for a hook entry: this Node and this sideby by absolute path, never `sideby` by name. A
|
|
@@ -30,7 +37,9 @@ export declare function sessionHookArgs(family: string, stateDir: string, parts:
|
|
|
30
37
|
* Auto Handoff's Claude hook arguments with `extra` hooks added to its `--settings` file, written as `out` (Claude
|
|
31
38
|
* Code takes one `--settings`). Auto Handoff's own hooks and options come first and are kept as they are.
|
|
32
39
|
*/
|
|
33
|
-
export declare function withClaudeHooks(hookArgs: readonly string[], extra: ClaudeHooks, out: string
|
|
40
|
+
export declare function withClaudeHooks(hookArgs: readonly string[], extra: ClaudeHooks, out: string,
|
|
41
|
+
/** Other top-level settings to add, such as the session's `autoMemoryDirectory` (ADR-0081). */
|
|
42
|
+
more?: Record<string, unknown>): Promise<string[]>;
|
|
34
43
|
/**
|
|
35
44
|
* Claude `--settings` arguments with `dirs` added to the file's `permissions.additionalDirectories`, written as `out`.
|
|
36
45
|
* Claude Code 2.1.326 asks the user to trust every `--add-dir` folder it has not seen before the session starts, and
|
|
@@ -40,6 +49,7 @@ export declare function withClaudeHooks(hookArgs: readonly string[], extra: Clau
|
|
|
40
49
|
export declare function withClaudeDirs(args: readonly string[], dirs: readonly string[], out: string): Promise<string[]>;
|
|
41
50
|
/**
|
|
42
51
|
* Auto Handoff's Claude hook arguments with the session's own sideby hooks (`sessionArgs`, from `sessionHookArgs`)
|
|
43
|
-
* merged into one `--settings` file, written next to the session's file with `-handoff` added to its name.
|
|
52
|
+
* merged into one `--settings` file, written next to the session's file with `-handoff` added to its name. The
|
|
53
|
+
* session file's other settings (`autoMemoryDirectory`, ADR-0081) come along.
|
|
44
54
|
*/
|
|
45
55
|
export declare function withClaudeSessionHooks(hookArgs: readonly string[], sessionArgs: readonly string[]): Promise<string[]>;
|
|
@@ -51,11 +51,12 @@ export async function sessionHookArgs(family, stateDir, parts) {
|
|
|
51
51
|
// A real folder of the user that nobody else can write to, so the file is never written through a link.
|
|
52
52
|
const dir = (await ownedFolder(stateDir, [parts[0].id], { create: true, private: true }));
|
|
53
53
|
const name = `claude-settings${parts
|
|
54
|
-
.
|
|
55
|
-
.map((p) => `-${p.id}`)
|
|
54
|
+
.map((p, i) => `${i ? `-${p.id}` : ''}${p.fileKey ? `-${p.fileKey}` : ''}`)
|
|
56
55
|
.join('')}.json`;
|
|
57
56
|
const hooks = mergeClaudeHooks(...parts.map((p) => p.claude));
|
|
58
|
-
|
|
57
|
+
const settings = Object.assign({}, ...parts.map((p) => p.settings ?? {}));
|
|
58
|
+
const body = { ...(Object.keys(hooks).length ? { hooks } : {}), ...settings };
|
|
59
|
+
await writeFileAtomic(join(dir, name), `${JSON.stringify(body, null, 2)}\n`, 0o600);
|
|
59
60
|
return ['--settings', join(dir, name)];
|
|
60
61
|
}
|
|
61
62
|
if (family === 'codex') {
|
|
@@ -84,11 +85,13 @@ async function settingsOf(args) {
|
|
|
84
85
|
* Auto Handoff's Claude hook arguments with `extra` hooks added to its `--settings` file, written as `out` (Claude
|
|
85
86
|
* Code takes one `--settings`). Auto Handoff's own hooks and options come first and are kept as they are.
|
|
86
87
|
*/
|
|
87
|
-
export async function withClaudeHooks(hookArgs, extra, out
|
|
88
|
+
export async function withClaudeHooks(hookArgs, extra, out,
|
|
89
|
+
/** Other top-level settings to add, such as the session's `autoMemoryDirectory` (ADR-0081). */
|
|
90
|
+
more = {}) {
|
|
88
91
|
const settings = await settingsOf(hookArgs);
|
|
89
92
|
const hooks = mergeClaudeHooks(settings.hooks ?? {}, extra);
|
|
90
93
|
await mkdir(dirname(out), { recursive: true, mode: 0o700 });
|
|
91
|
-
await writeFileAtomic(out, `${JSON.stringify({ ...settings, hooks }, null, 2)}\n`, 0o600);
|
|
94
|
+
await writeFileAtomic(out, `${JSON.stringify({ ...settings, ...more, hooks }, null, 2)}\n`, 0o600);
|
|
92
95
|
const at = hookArgs.indexOf('--settings');
|
|
93
96
|
return at === -1 ? [...hookArgs, '--settings', out] : hookArgs.map((a, i) => (i === at + 1 ? out : a));
|
|
94
97
|
}
|
|
@@ -121,13 +124,14 @@ export async function withClaudeDirs(args, dirs, out) {
|
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
126
|
* Auto Handoff's Claude hook arguments with the session's own sideby hooks (`sessionArgs`, from `sessionHookArgs`)
|
|
124
|
-
* merged into one `--settings` file, written next to the session's file with `-handoff` added to its name.
|
|
127
|
+
* merged into one `--settings` file, written next to the session's file with `-handoff` added to its name. The
|
|
128
|
+
* session file's other settings (`autoMemoryDirectory`, ADR-0081) come along.
|
|
125
129
|
*/
|
|
126
130
|
export async function withClaudeSessionHooks(hookArgs, sessionArgs) {
|
|
127
131
|
const at = sessionArgs.indexOf('--settings');
|
|
128
132
|
const file = at === -1 ? undefined : sessionArgs[at + 1];
|
|
129
133
|
if (!file)
|
|
130
134
|
return [...hookArgs];
|
|
131
|
-
const extra =
|
|
132
|
-
return withClaudeHooks(hookArgs, extra, join(dirname(file), `${basename(file, '.json')}-handoff.json`));
|
|
135
|
+
const { hooks: extra = {}, ...more } = await settingsOf(sessionArgs);
|
|
136
|
+
return withClaudeHooks(hookArgs, extra, join(dirname(file), `${basename(file, '.json')}-handoff.json`), more);
|
|
133
137
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Account } from '../types.ts';
|
|
2
|
+
import type { PendingDecision } from './unattended-pending.ts';
|
|
3
|
+
/**
|
|
4
|
+
* done: marked done; replied: not marked, and the user typed in the session after it was kept (which does not tell
|
|
5
|
+
* whether it was finished: the user looks before marking it done); open: not marked, and nothing typed after it.
|
|
6
|
+
*/
|
|
7
|
+
export type PendingState = 'open' | 'replied' | 'done';
|
|
8
|
+
/** One Pending Decision as it is listed: with its Project, its state, and when the user replied. */
|
|
9
|
+
export interface PendingRow extends PendingDecision {
|
|
10
|
+
/** The Project's path (spec §3.33), or '' when the decision has no folder. */
|
|
11
|
+
project: string;
|
|
12
|
+
/** The Project's short name, or '' when it has none. */
|
|
13
|
+
projectName: string;
|
|
14
|
+
state: PendingState;
|
|
15
|
+
/** The first message the user typed in the session after `at` (ISO); only when `state` is `replied`. */
|
|
16
|
+
repliedAt?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Why sideby could not tell whether the user replied: no-record, the session's record was not found; unsupported,
|
|
19
|
+
* sideby reads no session records of this Family. Only on an open decision with a session id.
|
|
20
|
+
*/
|
|
21
|
+
replyCheck?: 'no-record' | 'unsupported';
|
|
22
|
+
}
|
|
23
|
+
/** One Project's counts, in the order the Panel lists them. */
|
|
24
|
+
export interface PendingProject {
|
|
25
|
+
project: string;
|
|
26
|
+
projectName: string;
|
|
27
|
+
open: number;
|
|
28
|
+
replied: number;
|
|
29
|
+
done: number;
|
|
30
|
+
}
|
|
31
|
+
export interface PendingOverview {
|
|
32
|
+
/** In the order given (oldest first). */
|
|
33
|
+
rows: PendingRow[];
|
|
34
|
+
projects: PendingProject[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Marks of the notes sideby puts into a session, should a Host keep one as a message from the user: Unattended Mode's
|
|
38
|
+
* reasons and wake-ups (src/unattended/hook.ts, core/unattended-retry.ts), in English and Chinese, and the Progress
|
|
39
|
+
* Reminder. Claude Code keeps them as `isMeta` lines or `<task-notification>`s, which Session History's reader leaves
|
|
40
|
+
* out already; these catch any Host that does not.
|
|
41
|
+
*/
|
|
42
|
+
export declare const SIDEBY_NOTE_MARKS: readonly string[];
|
|
43
|
+
/**
|
|
44
|
+
* Whether a message Session History's reader gives as the user's counts as a reply to a Pending Decision. When unsure
|
|
45
|
+
* it does not, so a decision is shown as untouched rather than as written in afterwards.
|
|
46
|
+
*/
|
|
47
|
+
export declare function typedReply(text: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Each Pending Decision with its Project, state and reply (in the order given), and every Project's counts in the
|
|
50
|
+
* order the Panel lists them. `accounts` are where session records are looked for; `stateDir` holds the memo cache.
|
|
51
|
+
*/
|
|
52
|
+
export declare function pendingOverview(opts: {
|
|
53
|
+
decisions: readonly PendingDecision[];
|
|
54
|
+
accounts: readonly Account[];
|
|
55
|
+
stateDir: string;
|
|
56
|
+
}): Promise<PendingOverview>;
|
|
57
|
+
/**
|
|
58
|
+
* The Projects a `--project` value names among `projects`, as Session History's `--project` reads one: a path
|
|
59
|
+
* (absolute, or from `~`) names the Project it is, or the one it is in; a name is a short name, else the end of a
|
|
60
|
+
* Project's path.
|
|
61
|
+
*/
|
|
62
|
+
export declare function pendingProjectsNamed(projects: readonly PendingProject[], name: string, home: string): Promise<string[]>;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Pending Decisions by Project, and whether the user wrote in the session afterwards (spec §3.37 "按项目看",
|
|
2
|
+
// ADR-0078). The CLI's `sideby unattended pending` and the Panel's Unattended page list them through `pendingOverview`.
|
|
3
|
+
//
|
|
4
|
+
// A Pending Decision is `replied` when the session's own record holds a message the user typed later than the decision
|
|
5
|
+
// was kept: the record is found by the session id in the decision's Account (then the Family's other Accounts) and
|
|
6
|
+
// read read-only with Session History's reader, which gives only what a person typed. Of each record only the times
|
|
7
|
+
// of those messages are kept (per file version, in a FileMemo), never their text. Nothing is written into a Host
|
|
8
|
+
// directory, no credential is read and no model is called.
|
|
9
|
+
import { stat } from 'node:fs/promises';
|
|
10
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
11
|
+
import { findsSessionRecords, historyReader, sessionRecords, } from '../families/history.js';
|
|
12
|
+
import { uaGroupByProject } from '../panel/page-logic.js';
|
|
13
|
+
import { FileMemo } from './file-memo.js';
|
|
14
|
+
import { SAFE_ID } from './history.js';
|
|
15
|
+
import { ProjectResolver, projectNames, projectsNamed } from './history-project.js';
|
|
16
|
+
import { memoStore } from './memo-store.js';
|
|
17
|
+
import { hostMade, PROGRESS_MARK, sidebyMessage } from './prompt-origin.js';
|
|
18
|
+
/**
|
|
19
|
+
* The times of the messages the user typed in each session record, by file version. Kept in the memo cache file with
|
|
20
|
+
* the usage readers' memos (times only), so a restarted Panel does not read every record again.
|
|
21
|
+
*/
|
|
22
|
+
const replyMemo = new FileMemo({ name: 'pending-replies', version: 2 });
|
|
23
|
+
const MEMO_SCOPE = 'pending-replies';
|
|
24
|
+
/**
|
|
25
|
+
* Marks of the notes sideby puts into a session, should a Host keep one as a message from the user: Unattended Mode's
|
|
26
|
+
* reasons and wake-ups (src/unattended/hook.ts, core/unattended-retry.ts), in English and Chinese, and the Progress
|
|
27
|
+
* Reminder. Claude Code keeps them as `isMeta` lines or `<task-notification>`s, which Session History's reader leaves
|
|
28
|
+
* out already; these catch any Host that does not.
|
|
29
|
+
*/
|
|
30
|
+
export const SIDEBY_NOTE_MARKS = [
|
|
31
|
+
"sideby's Unattended Mode is on",
|
|
32
|
+
"sideby's Unattended Mode: ",
|
|
33
|
+
'sideby 无人值守已开启',
|
|
34
|
+
'sideby 无人值守:',
|
|
35
|
+
PROGRESS_MARK,
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Lines a person did not type as a reply: a slash command, a `!` shell line, a summary of an earlier conversation,
|
|
39
|
+
* and sideby's own notes, should a Host keep one as the user's: Auto Handoff's all start with `sideby: `, and the first
|
|
40
|
+
* prompt of the session a task was handed to starts the same way every time (src/handoff/messages.ts).
|
|
41
|
+
*/
|
|
42
|
+
const NOT_TYPED = /^\s*(?:[/!]|This session is being continued|sideby: |This task was handed over from \S+ by sideby\b)/;
|
|
43
|
+
/**
|
|
44
|
+
* Whether a message Session History's reader gives as the user's counts as a reply to a Pending Decision. When unsure
|
|
45
|
+
* it does not, so a decision is shown as untouched rather than as written in afterwards.
|
|
46
|
+
*/
|
|
47
|
+
export function typedReply(text) {
|
|
48
|
+
if (!text.trim() || NOT_TYPED.test(text))
|
|
49
|
+
return false;
|
|
50
|
+
if (hostMade(text) || sidebyMessage(text))
|
|
51
|
+
return false;
|
|
52
|
+
return !SIDEBY_NOTE_MARKS.some((m) => text.includes(m));
|
|
53
|
+
}
|
|
54
|
+
/** The times (ms) of the messages the user typed in one session record, oldest first. */
|
|
55
|
+
async function replyTimes(family, path) {
|
|
56
|
+
const reader = historyReader(family);
|
|
57
|
+
if (!reader)
|
|
58
|
+
return [];
|
|
59
|
+
const out = [];
|
|
60
|
+
for await (const m of reader.messages(path)) {
|
|
61
|
+
// A person's message: Claude Code marks one `human`, and a notification or a peer's message as something else.
|
|
62
|
+
if (m.role !== 'user' || !m.at || (m.origin && m.origin !== 'human') || !typedReply(m.text))
|
|
63
|
+
continue;
|
|
64
|
+
const t = Date.parse(m.at);
|
|
65
|
+
if (Number.isFinite(t))
|
|
66
|
+
out.push(t);
|
|
67
|
+
}
|
|
68
|
+
return out.sort((a, b) => a - b);
|
|
69
|
+
}
|
|
70
|
+
/** Lists each Account's Session records at most once per overview, however many sessions are looked up in it. */
|
|
71
|
+
function recordLists() {
|
|
72
|
+
const listed = new Map();
|
|
73
|
+
return (a) => {
|
|
74
|
+
let got = listed.get(a.ref);
|
|
75
|
+
if (!got) {
|
|
76
|
+
got = sessionRecords(a.family, a).catch(() => undefined);
|
|
77
|
+
listed.set(a.ref, got);
|
|
78
|
+
}
|
|
79
|
+
return got;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The session's record: in the decision's Account first, then in the Family's other Accounts. Undefined when none has
|
|
84
|
+
* it, or the session id is not of the plain form Session History accepts.
|
|
85
|
+
*/
|
|
86
|
+
async function findRecord(d, accounts, recordsOf) {
|
|
87
|
+
if (!d.sessionId || !SAFE_ID.test(d.sessionId))
|
|
88
|
+
return undefined;
|
|
89
|
+
const own = accounts.filter((a) => a.family === d.family);
|
|
90
|
+
const ordered = [...own.filter((a) => a.ref === d.account), ...own.filter((a) => a.ref !== d.account)];
|
|
91
|
+
for (const a of ordered) {
|
|
92
|
+
const path = (await recordsOf(a))?.find(d.sessionId);
|
|
93
|
+
if (path)
|
|
94
|
+
return path;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* When the user replied after each open decision of one session: the first typed message later than its `at`, or
|
|
100
|
+
* undefined. The record is read only when it was written after the earliest of them.
|
|
101
|
+
*/
|
|
102
|
+
async function sessionReplies(family, path, decisions, pass) {
|
|
103
|
+
const out = new Map();
|
|
104
|
+
const st = await stat(path);
|
|
105
|
+
const earliest = Math.min(...decisions.map((d) => Date.parse(d.at)));
|
|
106
|
+
const times = st.mtimeMs <= earliest ? [] : await pass.get(path, st, () => replyTimes(family, path));
|
|
107
|
+
for (const d of decisions)
|
|
108
|
+
out.set(d.id, times.find((t) => t > Date.parse(d.at)));
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Each Pending Decision with its Project, state and reply (in the order given), and every Project's counts in the
|
|
113
|
+
* order the Panel lists them. `accounts` are where session records are looked for; `stateDir` holds the memo cache.
|
|
114
|
+
*/
|
|
115
|
+
export async function pendingOverview(opts) {
|
|
116
|
+
const resolver = new ProjectResolver({ nearest: true });
|
|
117
|
+
const projectOf = new Map();
|
|
118
|
+
await Promise.all(opts.decisions.map(async (d) => {
|
|
119
|
+
projectOf.set(d.id, d.cwd ? (await resolver.resolve(d.cwd)).path : '');
|
|
120
|
+
}));
|
|
121
|
+
const names = projectNames([...projectOf.values()].filter(Boolean));
|
|
122
|
+
// Open decisions with a session id, by Family and session.
|
|
123
|
+
const bySession = new Map();
|
|
124
|
+
for (const d of opts.decisions)
|
|
125
|
+
if (!d.doneAt && d.sessionId) {
|
|
126
|
+
const key = `${d.family}\0${d.sessionId}`;
|
|
127
|
+
bySession.set(key, [...(bySession.get(key) ?? []), d]);
|
|
128
|
+
}
|
|
129
|
+
const replied = new Map();
|
|
130
|
+
const check = new Map();
|
|
131
|
+
if (bySession.size) {
|
|
132
|
+
const store = memoStore(opts.stateDir);
|
|
133
|
+
await store.ready();
|
|
134
|
+
const pass = replyMemo.pass(MEMO_SCOPE);
|
|
135
|
+
const recordsOf = recordLists();
|
|
136
|
+
await eachAtMost(READ_AT_ONCE, [...bySession.values()], async (list) => {
|
|
137
|
+
const first = list[0];
|
|
138
|
+
if (!findsSessionRecords(first.family)) {
|
|
139
|
+
for (const d of list)
|
|
140
|
+
check.set(d.id, 'unsupported');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const found = await findRecord(first, opts.accounts, recordsOf);
|
|
144
|
+
const got = found
|
|
145
|
+
? await sessionReplies(first.family, found, list, pass).catch(() => undefined)
|
|
146
|
+
: undefined;
|
|
147
|
+
if (!got)
|
|
148
|
+
for (const d of list)
|
|
149
|
+
check.set(d.id, 'no-record');
|
|
150
|
+
else
|
|
151
|
+
for (const [id, t] of got)
|
|
152
|
+
replied.set(id, t);
|
|
153
|
+
});
|
|
154
|
+
pass.done();
|
|
155
|
+
if (replyMemo.dirty)
|
|
156
|
+
store.saveSoon();
|
|
157
|
+
}
|
|
158
|
+
const rows = opts.decisions.map((d) => {
|
|
159
|
+
const project = projectOf.get(d.id) ?? '';
|
|
160
|
+
const at = replied.get(d.id);
|
|
161
|
+
const state = d.doneAt ? 'done' : at !== undefined ? 'replied' : 'open';
|
|
162
|
+
const why = check.get(d.id);
|
|
163
|
+
return {
|
|
164
|
+
...d,
|
|
165
|
+
project,
|
|
166
|
+
projectName: project ? (names.get(project) ?? project) : '',
|
|
167
|
+
state,
|
|
168
|
+
...(state === 'replied' ? { repliedAt: new Date(at).toISOString() } : {}),
|
|
169
|
+
...(state === 'open' && why ? { replyCheck: why } : {}),
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
const projects = uaGroupByProject(rows).map((g) => ({
|
|
173
|
+
project: g.project,
|
|
174
|
+
projectName: g.name,
|
|
175
|
+
open: g.open,
|
|
176
|
+
replied: g.replied,
|
|
177
|
+
done: g.done,
|
|
178
|
+
}));
|
|
179
|
+
return { rows, projects };
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The Projects a `--project` value names among `projects`, as Session History's `--project` reads one: a path
|
|
183
|
+
* (absolute, or from `~`) names the Project it is, or the one it is in; a name is a short name, else the end of a
|
|
184
|
+
* Project's path.
|
|
185
|
+
*/
|
|
186
|
+
export async function pendingProjectsNamed(projects, name, home) {
|
|
187
|
+
const paths = projects.filter((p) => p.project);
|
|
188
|
+
if (isAbsolute(name) || name === '~' || name.startsWith('~/')) {
|
|
189
|
+
const abs = resolve(name.startsWith('~') ? join(home, name.slice(1)) : name);
|
|
190
|
+
if (paths.some((p) => p.project === abs))
|
|
191
|
+
return [abs];
|
|
192
|
+
const found = (await new ProjectResolver({ nearest: true }).resolve(abs)).path;
|
|
193
|
+
return paths.some((p) => p.project === found) ? [found] : [];
|
|
194
|
+
}
|
|
195
|
+
return projectsNamed(new Map(paths.map((p) => [p.project, p.projectName])), name.replace(/\/+$/, ''));
|
|
196
|
+
}
|
|
197
|
+
/** How many session records are read at once. */
|
|
198
|
+
const READ_AT_ONCE = 4;
|
|
199
|
+
async function eachAtMost(n, items, fn) {
|
|
200
|
+
let next = 0;
|
|
201
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => {
|
|
202
|
+
while (next < items.length)
|
|
203
|
+
await fn(items[next++]);
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
@@ -59,10 +59,18 @@ opts?: {
|
|
|
59
59
|
}): Promise<PendingDecision[]>;
|
|
60
60
|
/** Opens a Pending Decision marked done again (the Panel's Undo after "Done"); throws when there is no such id. */
|
|
61
61
|
export declare function reopenPendingDecision(stateDir: string, id: string): Promise<PendingDecision>;
|
|
62
|
+
/**
|
|
63
|
+
* Opens Pending Decisions marked done again, reading the folder once (the Panel's Undo after a bulk "Done", and
|
|
64
|
+
* `sideby unattended pending reopen`). Ids no Pending Decision has, and ones that are open already, are left out:
|
|
65
|
+
* it returns only the ones it opened. When none of the ids is there it throws.
|
|
66
|
+
*/
|
|
67
|
+
export declare function reopenPendingDecisions(stateDir: string, ids: readonly string[]): Promise<PendingDecision[]>;
|
|
62
68
|
/** The open Pending Decision an id names: the whole id, or a start of it that only one has. */
|
|
63
69
|
export declare function findPendingDecision(stateDir: string, id: string): Promise<PendingDecision | undefined>;
|
|
64
70
|
/**
|
|
65
|
-
* Marks Pending Decisions done: one by id (or a unique start of it),
|
|
66
|
-
*
|
|
71
|
+
* Marks Pending Decisions done: one by id (or a unique start of it), every open one with `'all'`, or a list of whole
|
|
72
|
+
* ids read in one go (ADR-0078; ids no Pending Decision has, and ones done already, are left out, so a list returns
|
|
73
|
+
* only the ones this call marked). An id, or a list, that names no Pending Decision throws an Error whose message
|
|
74
|
+
* says how to list them.
|
|
67
75
|
*/
|
|
68
|
-
export declare function markPendingDone(stateDir: string, id: string | 'all', at?: Date): Promise<PendingDecision[]>;
|
|
76
|
+
export declare function markPendingDone(stateDir: string, id: string | 'all' | readonly string[], at?: Date): Promise<PendingDecision[]>;
|
|
@@ -171,6 +171,27 @@ export async function reopenPendingDecision(stateDir, id) {
|
|
|
171
171
|
await writeFileAtomic(fileOf(stateDir, d.id), `${JSON.stringify(open)}\n`, 0o600);
|
|
172
172
|
return open;
|
|
173
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Opens Pending Decisions marked done again, reading the folder once (the Panel's Undo after a bulk "Done", and
|
|
176
|
+
* `sideby unattended pending reopen`). Ids no Pending Decision has, and ones that are open already, are left out:
|
|
177
|
+
* it returns only the ones it opened. When none of the ids is there it throws.
|
|
178
|
+
*/
|
|
179
|
+
export async function reopenPendingDecisions(stateDir, ids) {
|
|
180
|
+
const want = new Set(ids);
|
|
181
|
+
const found = (await readAll(stateDir)).filter((d) => want.has(d.id));
|
|
182
|
+
if (!found.length)
|
|
183
|
+
throw new Error(`no Pending Decision has the id "${ids[0] ?? ''}"; \`sideby unattended pending --all\` lists them`);
|
|
184
|
+
const out = [];
|
|
185
|
+
for (const d of found) {
|
|
186
|
+
if (!d.doneAt)
|
|
187
|
+
continue;
|
|
188
|
+
const { doneAt: _, ...open } = d;
|
|
189
|
+
await ensureDir(stateDir);
|
|
190
|
+
await writeFileAtomic(fileOf(stateDir, d.id), `${JSON.stringify(open)}\n`, 0o600);
|
|
191
|
+
out.push(open);
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
174
195
|
/** The open Pending Decision an id names: the whole id, or a start of it that only one has. */
|
|
175
196
|
export async function findPendingDecision(stateDir, id) {
|
|
176
197
|
const all = await readAll(stateDir);
|
|
@@ -181,23 +202,28 @@ export async function findPendingDecision(stateDir, id) {
|
|
|
181
202
|
return starts.length === 1 ? starts[0] : undefined;
|
|
182
203
|
}
|
|
183
204
|
/**
|
|
184
|
-
* Marks Pending Decisions done: one by id (or a unique start of it),
|
|
185
|
-
*
|
|
205
|
+
* Marks Pending Decisions done: one by id (or a unique start of it), every open one with `'all'`, or a list of whole
|
|
206
|
+
* ids read in one go (ADR-0078; ids no Pending Decision has, and ones done already, are left out, so a list returns
|
|
207
|
+
* only the ones this call marked). An id, or a list, that names no Pending Decision throws an Error whose message
|
|
208
|
+
* says how to list them.
|
|
186
209
|
*/
|
|
187
210
|
export async function markPendingDone(stateDir, id, at = new Date()) {
|
|
211
|
+
const many = typeof id !== 'string';
|
|
212
|
+
const listed = new Set(many ? id : []);
|
|
188
213
|
const targets = id === 'all'
|
|
189
214
|
? (await readAll(stateDir)).filter((d) => !d.doneAt)
|
|
190
|
-
:
|
|
191
|
-
|
|
192
|
-
|
|
215
|
+
: many
|
|
216
|
+
? (await readAll(stateDir)).filter((d) => listed.has(d.id))
|
|
217
|
+
: [await findPendingDecision(stateDir, id)].filter((d) => d !== undefined);
|
|
218
|
+
if (id !== 'all' && !targets.length && (!many || id.length))
|
|
219
|
+
throw new Error(`no Pending Decision has the id "${many ? (id[0] ?? '') : id}"; \`sideby unattended pending --all\` lists them`);
|
|
193
220
|
if (targets.length)
|
|
194
221
|
await ensureDir(stateDir);
|
|
195
222
|
const out = [];
|
|
196
223
|
for (const d of targets) {
|
|
197
|
-
|
|
198
|
-
|
|
224
|
+
// Only the ones this call marks: one done already (elsewhere, a moment ago) is left out, so an Undo never opens it.
|
|
225
|
+
if (d.doneAt)
|
|
199
226
|
continue;
|
|
200
|
-
}
|
|
201
227
|
const done = { ...d, doneAt: at.toISOString() };
|
|
202
228
|
await writeFileAtomic(fileOf(stateDir, d.id), `${JSON.stringify(done)}\n`, 0o600);
|
|
203
229
|
out.push(done);
|
|
@@ -162,8 +162,16 @@ export const claudeHistory = {
|
|
|
162
162
|
const at = isoTime(rec.timestamp);
|
|
163
163
|
if (rec.type === 'user') {
|
|
164
164
|
const text = userText(rec);
|
|
165
|
+
// Who made it, as Claude Code records it (seen in 2.1.312 to 2.1.325): `human` for a person, else a notification
|
|
166
|
+
// or a peer's message.
|
|
167
|
+
const origin = str(rec.origin?.kind);
|
|
165
168
|
if (text)
|
|
166
|
-
yield {
|
|
169
|
+
yield {
|
|
170
|
+
role: 'user',
|
|
171
|
+
text,
|
|
172
|
+
...(at ? { at } : {}),
|
|
173
|
+
...(origin ? { origin } : {}),
|
|
174
|
+
};
|
|
167
175
|
}
|
|
168
176
|
else if (rec.type === 'assistant') {
|
|
169
177
|
const text = assistantText(rec);
|
|
@@ -4,3 +4,10 @@ export declare const CLAUDE_LAYOUT: {
|
|
|
4
4
|
main: string;
|
|
5
5
|
account: string;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* The folder Claude Code keeps a path's sessions and memory in under `projects/`: every character that is not an
|
|
9
|
+
* ASCII letter or digit becomes `-`; a name longer than 200 characters is cut there and gets `-` and a base-36 hash
|
|
10
|
+
* of the whole path (the 32-bit `(h << 5) - h + c` string hash, UTF-16 units). Read from Claude Code 2.1.328 on
|
|
11
|
+
* 2026-11-20 (ADR-0081).
|
|
12
|
+
*/
|
|
13
|
+
export declare function claudeProjectDirName(path: string): string;
|
|
@@ -3,3 +3,20 @@
|
|
|
3
3
|
export const CLAUDE_MAIN_DIR = '.claude';
|
|
4
4
|
export const CLAUDE_ACCOUNT_PREFIX = '.claude-';
|
|
5
5
|
export const CLAUDE_LAYOUT = { main: CLAUDE_MAIN_DIR, account: `${CLAUDE_ACCOUNT_PREFIX}<name>` };
|
|
6
|
+
/** The longest folder name Claude Code keeps under `projects/` before it shortens one and adds a hash. */
|
|
7
|
+
const PROJECT_NAME_MAX = 200;
|
|
8
|
+
/**
|
|
9
|
+
* The folder Claude Code keeps a path's sessions and memory in under `projects/`: every character that is not an
|
|
10
|
+
* ASCII letter or digit becomes `-`; a name longer than 200 characters is cut there and gets `-` and a base-36 hash
|
|
11
|
+
* of the whole path (the 32-bit `(h << 5) - h + c` string hash, UTF-16 units). Read from Claude Code 2.1.328 on
|
|
12
|
+
* 2026-11-20 (ADR-0081).
|
|
13
|
+
*/
|
|
14
|
+
export function claudeProjectDirName(path) {
|
|
15
|
+
const name = path.replace(/[^a-zA-Z0-9]/g, '-');
|
|
16
|
+
if (name.length <= PROJECT_NAME_MAX)
|
|
17
|
+
return name;
|
|
18
|
+
let h = 0;
|
|
19
|
+
for (let i = 0; i < path.length; i++)
|
|
20
|
+
h = ((h << 5) - h + path.charCodeAt(i)) | 0;
|
|
21
|
+
return `${name.slice(0, PROJECT_NAME_MAX)}-${Math.abs(h).toString(36)}`;
|
|
22
|
+
}
|
|
@@ -5,6 +5,7 @@ import { readdir } from 'node:fs/promises';
|
|
|
5
5
|
import { basename, join } from 'node:path';
|
|
6
6
|
import { statOrNull } from '../../core/fs-safe.js';
|
|
7
7
|
import { isoOf } from '../../core/live-sessions-procs.js';
|
|
8
|
+
import { claudeProjectDirName } from './layout.js';
|
|
8
9
|
import { readSessionRecord, recordRunsOn, recordStart, tailLinesWith } from './session-files.js';
|
|
9
10
|
const PID_FILE = /^(\d+)\.json$/;
|
|
10
11
|
/** Claude Code's `status`: `busy` and `shell` run, `idle` waits for a prompt, a blocked one waits for the user. */
|
|
@@ -38,7 +39,7 @@ export function claudeStartedFrom(v) {
|
|
|
38
39
|
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
|
|
39
40
|
const str = (v) => (typeof v === 'string' && v ? v : undefined);
|
|
40
41
|
/** The transcript Claude Code writes for a session: `projects/<cwd with every other character as ->/<id>.jsonl`. */
|
|
41
|
-
export const claudeTranscript = (dir, cwd, id) => join(dir, 'projects', cwd
|
|
42
|
+
export const claudeTranscript = (dir, cwd, id) => join(dir, 'projects', claudeProjectDirName(cwd), `${id}.jsonl`);
|
|
42
43
|
const titleMemo = new Map();
|
|
43
44
|
/**
|
|
44
45
|
* The title Claude Code gave the session itself (the one it shows as the terminal tab title): the last `ai-title`
|