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
|
@@ -111,6 +111,18 @@ export const CLI_COMMANDS = [
|
|
|
111
111
|
example: 'sideby trust on',
|
|
112
112
|
feature: 'setting.trust',
|
|
113
113
|
},
|
|
114
|
+
{
|
|
115
|
+
id: 'memory',
|
|
116
|
+
group: 'accounts',
|
|
117
|
+
usage: 'sideby memory [on|off] [--dir <path>] [--yes]',
|
|
118
|
+
help: "let every Claude account use the main account's memory of a project: sessions sideby starts read and write it, and doctor --fix moves memory an account wrote on its own into the main account (on|off, shows the change first)",
|
|
119
|
+
summary: {
|
|
120
|
+
en: 'Let every Claude account remember what the others learned about a project',
|
|
121
|
+
zh: '让每个 Claude 账号记得其他账号对项目学到的东西',
|
|
122
|
+
},
|
|
123
|
+
example: 'sideby memory on',
|
|
124
|
+
feature: 'setting.memory',
|
|
125
|
+
},
|
|
114
126
|
{
|
|
115
127
|
id: 'edit',
|
|
116
128
|
group: 'accounts',
|
|
@@ -586,7 +598,7 @@ export const CLI_COMMANDS = [
|
|
|
586
598
|
id: 'unattended',
|
|
587
599
|
group: 'health',
|
|
588
600
|
usage: 'sideby unattended [on|off]',
|
|
589
|
-
help: 'nobody is here: sessions sideby starts do not stop to ask; on takes --for 4h, --until 07:30 or --slot-end (schedule add|remove|preset weeknights, pending [done <id>|--all], defer "<text>"); run --unattended for one session',
|
|
601
|
+
help: 'nobody is here: sessions sideby starts do not stop to ask; on takes --for 4h, --until 07:30 or --slot-end (schedule add|remove|preset weeknights, pending [--project <name>] [done <id>|--ids|--all|--replied] [reopen <id>], defer "<text>"); run --unattended for one session',
|
|
590
602
|
summary: { en: 'Nobody is here: sessions do not stop to ask', zh: '无人值守:会话不停下来问你' },
|
|
591
603
|
example: 'sideby unattended on --until 07:30',
|
|
592
604
|
feature: 'page.unattended',
|
|
@@ -890,9 +902,10 @@ export function cliHelp(list = CLI_COMMANDS) {
|
|
|
890
902
|
const HELP_TAIL = `Options:
|
|
891
903
|
--json machine-readable output (list, new, next, alias, doctor, quota, tune, model, advisor, remote-control, handoff,
|
|
892
904
|
families, commands, plugins, app, desktop, sessions, history, send, messages, edit, browser, update, local, ask,
|
|
893
|
-
terminal, key, try, autostart, menubar, config, network, unattended, progress, trust)
|
|
905
|
+
terminal, key, try, autostart, menubar, config, network, unattended, progress, trust, memory)
|
|
894
906
|
-h, --help show this help; \`sideby <command> --help\` for new, alias, login, doctor, families, commands, desktop, edit, browser,
|
|
895
|
-
autostart, menubar, config, sessions, history, send, messages, network, unattended, progress, trust
|
|
907
|
+
autostart, menubar, config, sessions, history, send, messages, network, unattended, progress, trust,
|
|
908
|
+
memory
|
|
896
909
|
-v, --version show the version
|
|
897
910
|
|
|
898
911
|
An <account> is <family>:<name> (claude:work) or just <name> when it is unique.
|
|
@@ -124,6 +124,7 @@ export declare const ConfigSchema: Type.TObject<{
|
|
|
124
124
|
claude: Type.TOptional<Type.TObject<{
|
|
125
125
|
apiBetasOff: Type.TOptional<Type.TBoolean>;
|
|
126
126
|
carryTrust: Type.TOptional<Type.TBoolean>;
|
|
127
|
+
shareMemory: Type.TOptional<Type.TBoolean>;
|
|
127
128
|
}>>;
|
|
128
129
|
unattended: Type.TOptional<Type.TObject<{
|
|
129
130
|
schedule: Type.TOptional<Type.TArray<Type.TObject<{
|
|
@@ -161,6 +162,22 @@ export type Config = Static<typeof ConfigSchema>;
|
|
|
161
162
|
export declare function handoffSettings(config: Config): HandoffSettings;
|
|
162
163
|
export declare class ConfigError extends UserError {
|
|
163
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* What `sideby list` and `sideby doctor` say about a key this sideby does not know (ADR-0080): why it is there and
|
|
167
|
+
* what to do. Never printed by `loadConfig`, which hooks and `--json` commands use too.
|
|
168
|
+
*/
|
|
169
|
+
export declare function unknownConfigKeyNote(key: string, version: string): string;
|
|
170
|
+
export interface ConfigRead {
|
|
171
|
+
config: Config;
|
|
172
|
+
/** Keys in the file this sideby does not know, as dot paths (`claude.someKey`); left out of `config`. */
|
|
173
|
+
unknownKeys: string[];
|
|
174
|
+
}
|
|
175
|
+
/** `loadConfig`, and also the keys in the file this sideby does not know. */
|
|
176
|
+
export declare function readConfig(file: string): Promise<ConfigRead>;
|
|
177
|
+
/**
|
|
178
|
+
* Reads the config file; a missing file is `{}`. Keys this sideby does not know are left out and not an error
|
|
179
|
+
* (`readConfig` lists them); a known key with a wrong value is. Prints nothing.
|
|
180
|
+
*/
|
|
164
181
|
export declare function loadConfig(file: string): Promise<Config>;
|
|
165
182
|
export type HandoffConfig = NonNullable<Config['handoff']>;
|
|
166
183
|
/**
|
package/dist/src/core/config.js
CHANGED
|
@@ -253,9 +253,12 @@ export const ConfigSchema = Type.Object({
|
|
|
253
253
|
carryTrust: Type.Optional(Type.Boolean({
|
|
254
254
|
description: 'Carry folder trust between Claude accounts (spec §3.43, ADR-0078): before sideby starts an interactive Claude session in a folder this account has not trusted yet, when another Claude account of yours already trusts it (the folder, a parent folder outside any git repository, or the repository\'s main checkout), sideby copies that one trust mark (`projects["<path>"].hasTrustDialogAccepted`) into this account\'s `.claude.json`, so Claude Code does not ask again. It never adds trust no account gave. Off by default; turning it off does not remove marks already copied (`sideby trust undo` does).',
|
|
255
255
|
})),
|
|
256
|
+
shareMemory: Type.Optional(Type.Boolean({
|
|
257
|
+
description: "Shared Project Memory (spec §3.44, ADR-0081): every interactive Claude session sideby starts in an account other than the main one reads and writes the main account's auto memory for its project (`~/.claude/projects/<project>/memory`, passed as `autoMemoryDirectory` through sideby's `--settings`), and `sideby doctor --fix` moves memory an account wrote on its own into the main account. Off by default; turning it off stops passing the folder and leaves the memory where it is.",
|
|
258
|
+
})),
|
|
256
259
|
}, {
|
|
257
260
|
additionalProperties: false,
|
|
258
|
-
description: 'Claude Code launches (spec §3.41, ADR-0074; `carryTrust`: spec §3.43, ADR-0078).',
|
|
261
|
+
description: 'Claude Code launches (spec §3.41, ADR-0074; `carryTrust`: spec §3.43, ADR-0078; `shareMemory`: spec §3.44, ADR-0081).',
|
|
259
262
|
})),
|
|
260
263
|
unattended: Type.Optional(Type.Object({
|
|
261
264
|
schedule: Type.Optional(Type.Array(UnattendedSlotSchema, {
|
|
@@ -341,28 +344,179 @@ export function handoffSettings(config) {
|
|
|
341
344
|
}
|
|
342
345
|
export class ConfigError extends UserError {
|
|
343
346
|
}
|
|
344
|
-
|
|
347
|
+
// ---- Keys this sideby does not know (spec §3.10, ADR-0080). A newer sideby, or a typo, may leave a key the schema
|
|
348
|
+
// does not have. Reading ignores it and reports it; writing keeps it where it was; only `config set` refuses a new one.
|
|
349
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
350
|
+
/**
|
|
351
|
+
* The node whose keys are walked; none inside a union. An alias is a ref or `{ account, args }`, and anything else in
|
|
352
|
+
* that object stays an error (ADR-0005 keeps `env` out of aliases), as does every other value of a union.
|
|
353
|
+
*/
|
|
354
|
+
const objectForm = (node) => (node.anyOf ? undefined : node);
|
|
355
|
+
const recordChild = (node, key) => Object.entries(node.patternProperties ?? {}).find(([re]) => new RegExp(re).test(key))?.[1];
|
|
356
|
+
/** Whether `key` is one a closed object node does not declare. Record keys are the user's own names, never unknown. */
|
|
357
|
+
const unknownIn = (node, key) => !!node.properties && !Object.hasOwn(node.properties, key) && node.additionalProperties === false;
|
|
358
|
+
/** The paths of keys in `value` that `node` does not declare, walking objects, records and arrays. */
|
|
359
|
+
function findUnknown(node, value, path, out) {
|
|
360
|
+
if (Array.isArray(value)) {
|
|
361
|
+
if (node.items)
|
|
362
|
+
for (const [i, v] of value.entries())
|
|
363
|
+
findUnknown(node.items, v, [...path, String(i)], out);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const form = isObj(value) ? objectForm(node) : undefined;
|
|
367
|
+
if (!form || !isObj(value))
|
|
368
|
+
return;
|
|
369
|
+
for (const [k, v] of Object.entries(value)) {
|
|
370
|
+
if (unknownIn(form, k))
|
|
371
|
+
out.push([...path, k]);
|
|
372
|
+
else {
|
|
373
|
+
const child = form.properties && Object.hasOwn(form.properties, k) ? form.properties[k] : recordChild(form, k);
|
|
374
|
+
if (child)
|
|
375
|
+
findUnknown(child, v, [...path, k], out);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/** A copy of `value` without the keys `node` does not declare. */
|
|
380
|
+
function stripUnknown(node, value) {
|
|
381
|
+
if (Array.isArray(value))
|
|
382
|
+
return node.items ? value.map((v) => stripUnknown(node.items, v)) : value;
|
|
383
|
+
const form = isObj(value) ? objectForm(node) : undefined;
|
|
384
|
+
if (!form || !isObj(value))
|
|
385
|
+
return value;
|
|
386
|
+
const out = {};
|
|
387
|
+
for (const [k, v] of Object.entries(value)) {
|
|
388
|
+
if (unknownIn(form, k))
|
|
389
|
+
continue;
|
|
390
|
+
const child = form.properties && Object.hasOwn(form.properties, k) ? form.properties[k] : recordChild(form, k);
|
|
391
|
+
out[k] = child ? stripUnknown(child, v) : v;
|
|
392
|
+
}
|
|
393
|
+
return out;
|
|
394
|
+
}
|
|
395
|
+
const hasUnknown = (node, value) => {
|
|
396
|
+
const found = [];
|
|
397
|
+
findUnknown(node, value, [], found);
|
|
398
|
+
return found.length > 0;
|
|
399
|
+
};
|
|
400
|
+
/**
|
|
401
|
+
* Puts the unknown keys of `orig` back into `edited`, which an edit made from `orig` without them. An unknown key stays
|
|
402
|
+
* after the same sibling it followed; the known keys keep the edit's order. An object the edit removed keeps just its
|
|
403
|
+
* unknown keys (a section emptied of known keys is not the user asking to drop a newer sideby's setting), but a record
|
|
404
|
+
* entry the edit removed, or a list item it removed or changed, goes with its unknown keys (a list item has no name to
|
|
405
|
+
* match it by). `drop` is the path `config unset` named: there nothing is put back.
|
|
406
|
+
*/
|
|
407
|
+
function graftUnknown(node, orig, edited, drop) {
|
|
408
|
+
if ((drop && drop.length === 0) || !hasUnknown(node, orig))
|
|
409
|
+
return edited;
|
|
410
|
+
if (Array.isArray(orig)) {
|
|
411
|
+
if (!Array.isArray(edited) || !node.items)
|
|
412
|
+
return edited;
|
|
413
|
+
const used = new Set();
|
|
414
|
+
return edited.map((e) => {
|
|
415
|
+
const same = JSON.stringify(e);
|
|
416
|
+
const i = orig.findIndex((o, j) => !used.has(j) && JSON.stringify(stripUnknown(node.items, o)) === same);
|
|
417
|
+
if (i < 0)
|
|
418
|
+
return e;
|
|
419
|
+
used.add(i);
|
|
420
|
+
return orig[i];
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
const form = objectForm(node);
|
|
424
|
+
if (!form || !isObj(orig))
|
|
425
|
+
return edited;
|
|
426
|
+
const sub = (k) => (drop && drop[0] === k ? drop.slice(1) : null);
|
|
427
|
+
if (form.patternProperties && !form.properties) {
|
|
428
|
+
if (!isObj(edited))
|
|
429
|
+
return edited;
|
|
430
|
+
const out = {};
|
|
431
|
+
for (const [k, v] of Object.entries(edited)) {
|
|
432
|
+
const child = recordChild(form, k);
|
|
433
|
+
out[k] = child && Object.hasOwn(orig, k) ? graftUnknown(child, orig[k], v, sub(k)) : v;
|
|
434
|
+
}
|
|
435
|
+
return out;
|
|
436
|
+
}
|
|
437
|
+
if (!form.properties || (edited !== undefined && !isObj(edited)))
|
|
438
|
+
return edited;
|
|
439
|
+
const now = edited ?? {};
|
|
440
|
+
// Each kept key of `orig` that the edit does not have goes after the last key before it that the edit kept.
|
|
441
|
+
const after = new Map();
|
|
442
|
+
let anchor = null;
|
|
443
|
+
for (const [k, v] of Object.entries(orig)) {
|
|
444
|
+
if (Object.hasOwn(now, k)) {
|
|
445
|
+
anchor = k;
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
let kept;
|
|
449
|
+
if (unknownIn(form, k))
|
|
450
|
+
kept = sub(k)?.length === 0 ? undefined : v;
|
|
451
|
+
else if (form.properties[k])
|
|
452
|
+
kept = graftUnknown(form.properties[k], v, undefined, sub(k));
|
|
453
|
+
if (kept !== undefined)
|
|
454
|
+
after.set(anchor, [...(after.get(anchor) ?? []), [k, kept]]);
|
|
455
|
+
}
|
|
456
|
+
const out = Object.fromEntries(after.get(null) ?? []);
|
|
457
|
+
for (const [k, v] of Object.entries(now)) {
|
|
458
|
+
const child = form.properties[k];
|
|
459
|
+
out[k] = child && Object.hasOwn(orig, k) ? graftUnknown(child, orig[k], v, sub(k)) : v;
|
|
460
|
+
for (const [uk, uv] of after.get(k) ?? [])
|
|
461
|
+
out[uk] = uv;
|
|
462
|
+
}
|
|
463
|
+
return edited === undefined && Object.keys(out).length === 0 ? undefined : out;
|
|
464
|
+
}
|
|
465
|
+
/** The first way `data` (unknown keys already left out) does not match the schema, or null. */
|
|
466
|
+
function schemaProblem(data) {
|
|
467
|
+
if (Value.Check(ConfigSchema, data))
|
|
468
|
+
return null;
|
|
469
|
+
const first = [...Value.Errors(ConfigSchema, data)][0];
|
|
470
|
+
// A key the schema does not have shows up as "schema is false" or "must not have additional properties".
|
|
471
|
+
const extra = first?.message === 'schema is false' || first?.keyword === 'additionalProperties';
|
|
472
|
+
return {
|
|
473
|
+
where: first?.instancePath || '/',
|
|
474
|
+
message: extra ? 'is not a config key' : (first?.message ?? 'is invalid'),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* What `sideby list` and `sideby doctor` say about a key this sideby does not know (ADR-0080): why it is there and
|
|
479
|
+
* what to do. Never printed by `loadConfig`, which hooks and `--json` commands use too.
|
|
480
|
+
*/
|
|
481
|
+
export function unknownConfigKeyNote(key, version) {
|
|
482
|
+
return `config key "${key}" is not one sideby ${version} knows, so it is ignored: a newer sideby wrote it, or it is a typo. Run \`sideby update\` to get the newer sideby, or remove it with \`sideby config unset ${key} --yes\``;
|
|
483
|
+
}
|
|
484
|
+
/** `loadConfig`, and also the keys in the file this sideby does not know. */
|
|
485
|
+
export async function readConfig(file) {
|
|
345
486
|
let raw;
|
|
346
487
|
try {
|
|
347
488
|
raw = await readFile(file, 'utf8');
|
|
348
489
|
}
|
|
349
490
|
catch (err) {
|
|
350
491
|
if (err.code === 'ENOENT')
|
|
351
|
-
return {};
|
|
492
|
+
return { config: {}, unknownKeys: [] };
|
|
352
493
|
throw new ConfigError(`cannot read ${file}: ${err.message}`);
|
|
353
494
|
}
|
|
354
|
-
let
|
|
495
|
+
let parsed;
|
|
355
496
|
try {
|
|
356
|
-
|
|
497
|
+
parsed = parseJsonSafely(raw, file);
|
|
357
498
|
}
|
|
358
499
|
catch {
|
|
359
500
|
throw new ConfigError(`${file} is not valid JSON; fix the syntax or delete the file`);
|
|
360
501
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
502
|
+
const schema = ConfigSchema;
|
|
503
|
+
const found = [];
|
|
504
|
+
findUnknown(schema, parsed, [], found);
|
|
505
|
+
const data = found.length ? stripUnknown(schema, parsed) : parsed;
|
|
506
|
+
const problem = schemaProblem(data);
|
|
507
|
+
if (problem)
|
|
508
|
+
throw new ConfigError(`${file}: ${problem.where} ${problem.message}; see schemas/config.json`);
|
|
509
|
+
const config = checkLoaded(file, data);
|
|
510
|
+
return { config, unknownKeys: found.map((p) => p.join('.')) };
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Reads the config file; a missing file is `{}`. Keys this sideby does not know are left out and not an error
|
|
514
|
+
* (`readConfig` lists them); a known key with a wrong value is. Prints nothing.
|
|
515
|
+
*/
|
|
516
|
+
export async function loadConfig(file) {
|
|
517
|
+
return (await readConfig(file)).config;
|
|
518
|
+
}
|
|
519
|
+
function checkLoaded(file, data) {
|
|
366
520
|
const handoff = handoffSettings(data);
|
|
367
521
|
if (handoff.prepareAt >= handoff.threshold)
|
|
368
522
|
throw new ConfigError(`${file}: handoff.prepareAt (${handoff.prepareAt}) must be lower than handoff.threshold (${handoff.threshold}); lower prepareAt or raise threshold`);
|
|
@@ -406,44 +560,25 @@ async function configTarget(file) {
|
|
|
406
560
|
* `retry` names what to do again after a fix.
|
|
407
561
|
*/
|
|
408
562
|
async function editConfigKey(file, key, retry, edit, opts = {}) {
|
|
409
|
-
const target = await
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (err.code !== 'ENOENT')
|
|
416
|
-
throw new ConfigError(`cannot read ${file}: ${err.message}`);
|
|
417
|
-
}
|
|
418
|
-
let data = {};
|
|
419
|
-
if (raw !== null) {
|
|
420
|
-
let parsed;
|
|
421
|
-
try {
|
|
422
|
-
parsed = parseJsonSafely(raw, file);
|
|
423
|
-
}
|
|
424
|
-
catch {
|
|
425
|
-
throw new ConfigError(`${file} is not valid JSON; nothing was changed. Fix the syntax and ${retry} again`);
|
|
426
|
-
}
|
|
427
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
428
|
-
throw new ConfigError(`${file} is not a JSON object; nothing was changed. Fix it and ${retry} again`);
|
|
429
|
-
if (!Value.Check(ConfigSchema, parsed))
|
|
430
|
-
throw new ConfigError(`${file} does not match schemas/config.json; nothing was changed. Run \`sideby list\` to see why`);
|
|
431
|
-
data = parsed;
|
|
432
|
-
}
|
|
433
|
-
const before = data[key];
|
|
563
|
+
const { target, raw, data } = await readConfigForEdit(file, retry);
|
|
564
|
+
// The edit and every check see only the keys this sideby knows; the others go back in when the file is written
|
|
565
|
+
// (ADR-0080), so a key the edit adds that the schema does not have is still refused.
|
|
566
|
+
const schema = ConfigSchema;
|
|
567
|
+
const known = stripUnknown(schema, data);
|
|
568
|
+
const before = known[key];
|
|
434
569
|
const after = edit(before);
|
|
435
570
|
if (after === null || JSON.stringify(after) === JSON.stringify(before))
|
|
436
571
|
return { changed: false, before, after: before };
|
|
437
572
|
// A new file gets the schema link editors use for completion; an existing file keeps its keys in order.
|
|
438
573
|
const next = raw === null
|
|
439
574
|
? { $schema: 'https://unpkg.com/sideby/schemas/config.json', [key]: after }
|
|
440
|
-
: { ...
|
|
575
|
+
: { ...known, [key]: after };
|
|
441
576
|
if (after === undefined)
|
|
442
577
|
delete next[key];
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const where =
|
|
446
|
-
throw new ConfigError(`${where} ${
|
|
578
|
+
const problem = schemaProblem(next);
|
|
579
|
+
if (problem) {
|
|
580
|
+
const where = problem.where.replace(/^\//, '').split('/').join('.') || key;
|
|
581
|
+
throw new ConfigError(`${where} ${problem.message}, so nothing was changed; \`sideby config get\` lists the keys and the values they take`, { code: 'bad-value' });
|
|
447
582
|
}
|
|
448
583
|
for (const alias of Object.keys(next.aliases ?? {})) {
|
|
449
584
|
const problem = aliasProblem(alias);
|
|
@@ -458,15 +593,90 @@ async function editConfigKey(file, key, retry, edit, opts = {}) {
|
|
|
458
593
|
const h = handoffSettings(next);
|
|
459
594
|
if (h.prepareAt >= h.threshold)
|
|
460
595
|
throw new ConfigError(`handoff.prepareAt must be lower than handoff.threshold; fix them in ${file} and ${retry} again`);
|
|
596
|
+
let out = next;
|
|
597
|
+
if (raw !== null) {
|
|
598
|
+
const kept = schema.properties?.[key]
|
|
599
|
+
? graftUnknown(schema.properties[key], data[key], after, opts.drop ?? null)
|
|
600
|
+
: after;
|
|
601
|
+
// A section that holds only keys this sideby does not know stays as it is: nothing changes.
|
|
602
|
+
if (JSON.stringify(kept) === JSON.stringify(data[key]))
|
|
603
|
+
return { changed: false, before, after: before };
|
|
604
|
+
out = { ...data, [key]: kept };
|
|
605
|
+
if (kept === undefined)
|
|
606
|
+
delete out[key];
|
|
607
|
+
}
|
|
461
608
|
if (opts.dryRun)
|
|
462
609
|
return { changed: true, before, after };
|
|
610
|
+
await writeConfigFile(file, target, raw, out);
|
|
611
|
+
return { changed: true, before, after };
|
|
612
|
+
}
|
|
613
|
+
/** The config file for a change: its real path, its text (null when missing) and the JSON object in it. */
|
|
614
|
+
async function readConfigForEdit(file, retry) {
|
|
615
|
+
const target = await configTarget(file);
|
|
616
|
+
let raw = null;
|
|
617
|
+
try {
|
|
618
|
+
raw = await readFile(target, 'utf8');
|
|
619
|
+
}
|
|
620
|
+
catch (err) {
|
|
621
|
+
if (err.code !== 'ENOENT')
|
|
622
|
+
throw new ConfigError(`cannot read ${file}: ${err.message}`);
|
|
623
|
+
}
|
|
624
|
+
if (raw === null)
|
|
625
|
+
return { target, raw, data: {} };
|
|
626
|
+
let parsed;
|
|
627
|
+
try {
|
|
628
|
+
parsed = parseJsonSafely(raw, file);
|
|
629
|
+
}
|
|
630
|
+
catch {
|
|
631
|
+
throw new ConfigError(`${file} is not valid JSON; nothing was changed. Fix the syntax and ${retry} again`);
|
|
632
|
+
}
|
|
633
|
+
if (!isObj(parsed))
|
|
634
|
+
throw new ConfigError(`${file} is not a JSON object; nothing was changed. Fix it and ${retry} again`);
|
|
635
|
+
const problem = schemaProblem(stripUnknown(ConfigSchema, parsed));
|
|
636
|
+
if (problem) {
|
|
637
|
+
const where = problem.where.replace(/^\//, '').split('/').join('.') || 'the file';
|
|
638
|
+
throw new ConfigError(`${file}: ${where} ${problem.message}, so nothing was changed. Fix it in the file (schemas/config.json lists the values it takes) and ${retry} again`);
|
|
639
|
+
}
|
|
640
|
+
return { target, raw, data: parsed };
|
|
641
|
+
}
|
|
642
|
+
/** Writes `data` as 2-space JSON atomically, keeping the file's mode (0600 for a new file), only if it did not change. */
|
|
643
|
+
async function writeConfigFile(file, target, raw, data) {
|
|
463
644
|
const st = raw === null ? null : await lstatOrNull(target);
|
|
464
645
|
if (raw === null)
|
|
465
646
|
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
466
|
-
const written = await writeIfUnchanged(target, raw === null ? null : sha256(raw), `${JSON.stringify(
|
|
647
|
+
const written = await writeIfUnchanged(target, raw === null ? null : sha256(raw), `${JSON.stringify(data, null, 2)}\n`, st ? st.mode & 0o777 : 0o600);
|
|
467
648
|
if (!written)
|
|
468
649
|
throw new ConfigError(`${file} changed while sideby was writing it; nothing was changed. Try again`);
|
|
469
|
-
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* `sideby config unset <key>` for a key in the file this sideby does not know (ADR-0080): removes just that key, and
|
|
653
|
+
* objects it leaves empty. Null when the file has no such unknown key.
|
|
654
|
+
*/
|
|
655
|
+
async function unsetUnknownKey(file, key, opts) {
|
|
656
|
+
const { target, raw, data } = await readConfigForEdit(file, 'run the command');
|
|
657
|
+
const found = [];
|
|
658
|
+
findUnknown(ConfigSchema, data, [], found);
|
|
659
|
+
const path = found.find((p) => p.join('.') === key);
|
|
660
|
+
if (!path)
|
|
661
|
+
return null;
|
|
662
|
+
const before = getIn(data, path);
|
|
663
|
+
if (!opts.dryRun) {
|
|
664
|
+
const next = structuredClone(data);
|
|
665
|
+
const chain = [next];
|
|
666
|
+
for (const seg of path.slice(0, -1))
|
|
667
|
+
chain.push(chain.at(-1)[seg]);
|
|
668
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
669
|
+
const parent = chain[i];
|
|
670
|
+
const child = parent[path[i]];
|
|
671
|
+
if (i < path.length - 1 && !isEmptyObject(child))
|
|
672
|
+
break;
|
|
673
|
+
if (Array.isArray(parent))
|
|
674
|
+
break;
|
|
675
|
+
delete parent[path[i]];
|
|
676
|
+
}
|
|
677
|
+
await writeConfigFile(file, target, raw, next);
|
|
678
|
+
}
|
|
679
|
+
return { key, before, after: undefined, changed: true };
|
|
470
680
|
}
|
|
471
681
|
async function editConfigAliases(file, retry, edit) {
|
|
472
682
|
const r = await editConfigKey(file, 'aliases', retry, (current) => edit(current ?? {}));
|
|
@@ -873,6 +1083,17 @@ const isEmptyObject = (v) => typeof v === 'object' && v !== null && !Array.isArr
|
|
|
873
1083
|
* every other config change (see `editConfigKey`); `dryRun` shows the change without writing.
|
|
874
1084
|
*/
|
|
875
1085
|
export async function editConfigPath(file, key, value, opts = {}) {
|
|
1086
|
+
// A key this sideby does not know (ADR-0080) can only be removed, and only where the file has it.
|
|
1087
|
+
const segs = key.split('.');
|
|
1088
|
+
if (value === undefined &&
|
|
1089
|
+
key &&
|
|
1090
|
+
!segs.some((p) => !p || BAD_SEGMENT.has(p)) &&
|
|
1091
|
+
segs[0] !== '$schema' &&
|
|
1092
|
+
segs[0] !== 'plugins') {
|
|
1093
|
+
const removed = await unsetUnknownKey(file, key, opts);
|
|
1094
|
+
if (removed)
|
|
1095
|
+
return removed;
|
|
1096
|
+
}
|
|
876
1097
|
const path = configKeyPath(key);
|
|
877
1098
|
if (path[0] === 'plugins' && value !== undefined && typeof value !== 'boolean')
|
|
878
1099
|
throw new ConfigError(`${key} takes true or false`, { code: 'bad-value' });
|
|
@@ -885,7 +1106,9 @@ export async function editConfigPath(file, key, value, opts = {}) {
|
|
|
885
1106
|
if (top === 'handoff')
|
|
886
1107
|
opts.checkHandoff?.(current, result);
|
|
887
1108
|
return result;
|
|
888
|
-
},
|
|
1109
|
+
},
|
|
1110
|
+
// `config unset` of a section removes it whole, also keys this sideby does not know; anything else keeps them.
|
|
1111
|
+
{ ...opts, ...(value === undefined ? { drop: path.slice(1) } : {}) });
|
|
889
1112
|
const inner = path.slice(1);
|
|
890
1113
|
return { key, before: getIn(r.before, inner), after: getIn(r.after, inner), changed: r.changed };
|
|
891
1114
|
}
|
|
@@ -7,7 +7,21 @@ export interface Project {
|
|
|
7
7
|
/** Resolves Projects, remembering each working directory for the life of this object. */
|
|
8
8
|
export declare class ProjectResolver {
|
|
9
9
|
#private;
|
|
10
|
+
/**
|
|
11
|
+
* With `nearest`, a working directory that is gone counts as the repository of its nearest folder that is still
|
|
12
|
+
* there, when that folder is in one (a deleted worktree under `<repo>/.worktrees/` folds back into the repository;
|
|
13
|
+
* Pending Decisions, ADR-0078). Without it, as Session History has it: the root the Host recorded, else itself.
|
|
14
|
+
*/
|
|
15
|
+
constructor(opts?: {
|
|
16
|
+
nearest?: boolean;
|
|
17
|
+
});
|
|
10
18
|
resolve(cwd: string | undefined, hostRoot?: string): Promise<Project>;
|
|
11
19
|
}
|
|
12
20
|
/** A short name for a Project: its folder name, with as many parent folders as it takes to tell it from another Project of the same name. */
|
|
13
21
|
export declare function projectNames(paths: Iterable<string>): Map<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* The Projects a name given to `--project` may mean: the one whose shown name it is, else every Project whose path
|
|
24
|
+
* ends with it. A shown name is unique, so it wins over a path tail it shares with a longer path (`a/app` for
|
|
25
|
+
* `/a/app` beside `/x/a/app`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function projectsNamed(names: ReadonlyMap<string, string>, p: string): string[];
|
|
@@ -30,6 +30,15 @@ async function worktreeMain(gitFile) {
|
|
|
30
30
|
/** Resolves Projects, remembering each working directory for the life of this object. */
|
|
31
31
|
export class ProjectResolver {
|
|
32
32
|
#memo = new Map();
|
|
33
|
+
#nearest;
|
|
34
|
+
/**
|
|
35
|
+
* With `nearest`, a working directory that is gone counts as the repository of its nearest folder that is still
|
|
36
|
+
* there, when that folder is in one (a deleted worktree under `<repo>/.worktrees/` folds back into the repository;
|
|
37
|
+
* Pending Decisions, ADR-0078). Without it, as Session History has it: the root the Host recorded, else itself.
|
|
38
|
+
*/
|
|
39
|
+
constructor(opts = {}) {
|
|
40
|
+
this.#nearest = Boolean(opts.nearest);
|
|
41
|
+
}
|
|
33
42
|
resolve(cwd, hostRoot) {
|
|
34
43
|
const key = `${cwd ?? ''}\0${hostRoot ?? ''}`;
|
|
35
44
|
let p = this.#memo.get(key);
|
|
@@ -46,19 +55,28 @@ export class ProjectResolver {
|
|
|
46
55
|
// resolve() drops a trailing separator (Grok records `<repo>/`), so it groups with the live folder's Project.
|
|
47
56
|
const root = resolve(hostRoot && isAbsolute(hostRoot) ? hostRoot : cwd);
|
|
48
57
|
const main = (await kind(join(root, '.git'))) === 'file' ? await worktreeMain(join(root, '.git')) : undefined;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (git === 'file')
|
|
56
|
-
return { path: (await worktreeMain(join(dir, '.git'))) ?? dir, gone: false };
|
|
57
|
-
const up = dirname(dir);
|
|
58
|
-
if (up === dir)
|
|
59
|
-
return { path: resolve(cwd), gone: false };
|
|
60
|
-
dir = up;
|
|
58
|
+
if (main || !this.#nearest)
|
|
59
|
+
return { path: main ?? root, gone: true };
|
|
60
|
+
let there = dirname(root);
|
|
61
|
+
while ((await kind(there)) !== 'dir' && dirname(there) !== there)
|
|
62
|
+
there = dirname(there);
|
|
63
|
+
return { path: (await repoOf(there)) ?? root, gone: true };
|
|
61
64
|
}
|
|
65
|
+
return { path: (await repoOf(resolve(cwd))) ?? resolve(cwd), gone: false };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** The repository `dir` is in (a worktree's main repository), or undefined outside any. */
|
|
69
|
+
async function repoOf(dir) {
|
|
70
|
+
for (let at = dir;;) {
|
|
71
|
+
const git = await kind(join(at, '.git'));
|
|
72
|
+
if (git === 'dir')
|
|
73
|
+
return at;
|
|
74
|
+
if (git === 'file')
|
|
75
|
+
return (await worktreeMain(join(at, '.git'))) ?? at;
|
|
76
|
+
const up = dirname(at);
|
|
77
|
+
if (up === at)
|
|
78
|
+
return undefined;
|
|
79
|
+
at = up;
|
|
62
80
|
}
|
|
63
81
|
}
|
|
64
82
|
/** A short name for a Project: its folder name, with as many parent folders as it takes to tell it from another Project of the same name. */
|
|
@@ -98,3 +116,15 @@ export function projectNames(paths) {
|
|
|
98
116
|
}
|
|
99
117
|
return out;
|
|
100
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The Projects a name given to `--project` may mean: the one whose shown name it is, else every Project whose path
|
|
121
|
+
* ends with it. A shown name is unique, so it wins over a path tail it shares with a longer path (`a/app` for
|
|
122
|
+
* `/a/app` beside `/x/a/app`).
|
|
123
|
+
*/
|
|
124
|
+
export function projectsNamed(names, p) {
|
|
125
|
+
const all = [...names.keys()];
|
|
126
|
+
const named = all.filter((x) => names.get(x) === p);
|
|
127
|
+
if (named.length === 1)
|
|
128
|
+
return named;
|
|
129
|
+
return all.filter((x) => names.get(x) === p || x.endsWith(`/${p}`));
|
|
130
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Runtime } from '../runtime.ts';
|
|
2
2
|
import { type GroupBy } from './history-group.ts';
|
|
3
|
+
import { projectsNamed } from './history-project.ts';
|
|
4
|
+
export { projectsNamed };
|
|
3
5
|
export type IndexState = 'building' | 'ready' | 'off' | 'unavailable';
|
|
4
6
|
export interface HistorySource {
|
|
5
7
|
account: string;
|
|
@@ -101,6 +103,8 @@ export interface HistoryQuery {
|
|
|
101
103
|
limit?: number;
|
|
102
104
|
offset?: number;
|
|
103
105
|
}
|
|
106
|
+
/** What a Session id may look like: the Hosts use UUIDs and similar plain names. */
|
|
107
|
+
export declare const SAFE_ID: RegExp;
|
|
104
108
|
export declare const historyIndexPath: (rt: Pick<Runtime, 'paths'>) => string;
|
|
105
109
|
/** Closes the History Index of `rt` (tests), after the open, sync and reads in flight end. */
|
|
106
110
|
export declare function closeHistory(rt: Runtime): Promise<void>;
|
|
@@ -118,12 +122,6 @@ export declare const FIRST_ANSWER_MS = 2500;
|
|
|
118
122
|
export declare function syncHistoryInBackground(rt: Runtime): void;
|
|
119
123
|
/** True once a first build finished (the Panel then answers without waiting). */
|
|
120
124
|
export declare const historyBuilt: (rt: Runtime) => boolean;
|
|
121
|
-
/**
|
|
122
|
-
* The Projects a name given to `--project` may mean: the one whose shown name it is, else every Project whose path
|
|
123
|
-
* ends with it. A shown name is unique, so it wins over a path tail it shares with a longer path (`a/app` for
|
|
124
|
-
* `/a/app` beside `/x/a/app`).
|
|
125
|
-
*/
|
|
126
|
-
export declare function projectsNamed(names: ReadonlyMap<string, string>, p: string): string[];
|
|
127
125
|
/**
|
|
128
126
|
* A snippet of `text`, about 40 characters each side of what was searched: the first place where the most of
|
|
129
127
|
* `words` stand within 80 characters of each other, so two words show together when the text has them together.
|
package/dist/src/core/history.js
CHANGED
|
@@ -9,8 +9,10 @@ import { cutText, SESSION_TEXT_MAX } from '../families/shared/history-text.js';
|
|
|
9
9
|
import { UserError } from './errors.js';
|
|
10
10
|
import { DAY_GROUPS, dayGroup, GROUP_BYS, orderGroups, } from './history-group.js';
|
|
11
11
|
import { HistoryIndex, } from './history-index.js';
|
|
12
|
-
import { ProjectResolver, projectNames } from './history-project.js';
|
|
12
|
+
import { ProjectResolver, projectNames, projectsNamed } from './history-project.js';
|
|
13
13
|
import { accountLabels, hostResumeArgs, liveKey, referenceText } from './live-sessions.js';
|
|
14
|
+
// The Project helpers live in history-project.ts; `projectsNamed` stays importable from here.
|
|
15
|
+
export { projectsNamed };
|
|
14
16
|
const DAY = 86_400_000;
|
|
15
17
|
/** How old a Session is when its age has halved its search score; older ones go on falling, more slowly. */
|
|
16
18
|
const RECENCY = 30 * DAY;
|
|
@@ -30,7 +32,7 @@ function fence(key, work) {
|
|
|
30
32
|
return done;
|
|
31
33
|
}
|
|
32
34
|
/** What a Session id may look like: the Hosts use UUIDs and similar plain names. */
|
|
33
|
-
const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
35
|
+
export const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
34
36
|
export const historyIndexPath = (rt) => join(rt.paths.stateDir, 'history', 'index.sqlite');
|
|
35
37
|
const enabled = (rt) => rt.config.history?.index !== false;
|
|
36
38
|
/** `dev:ino` of the file at `path`, or '' when there is none. */
|
|
@@ -462,18 +464,6 @@ async function resolveProject(idx, p, home) {
|
|
|
462
464
|
throw new UserError(`"${p}" names ${hit.length} projects (${hit.join(', ')}); give the full path`);
|
|
463
465
|
throw new UserError(`no project named "${p}"; run \`sideby history projects\` to see them`);
|
|
464
466
|
}
|
|
465
|
-
/**
|
|
466
|
-
* The Projects a name given to `--project` may mean: the one whose shown name it is, else every Project whose path
|
|
467
|
-
* ends with it. A shown name is unique, so it wins over a path tail it shares with a longer path (`a/app` for
|
|
468
|
-
* `/a/app` beside `/x/a/app`).
|
|
469
|
-
*/
|
|
470
|
-
export function projectsNamed(names, p) {
|
|
471
|
-
const all = [...names.keys()];
|
|
472
|
-
const named = all.filter((x) => names.get(x) === p);
|
|
473
|
-
if (named.length === 1)
|
|
474
|
-
return named;
|
|
475
|
-
return all.filter((x) => names.get(x) === p || x.endsWith(`/${p}`));
|
|
476
|
-
}
|
|
477
467
|
const SAFE = /^[\w@%+=:,./-]+$/;
|
|
478
468
|
const shq = (v) => (SAFE.test(v) ? v : `'${v.replaceAll("'", "'\\''")}'`);
|
|
479
469
|
const SNIPPET_SPAN = 80;
|
|
@@ -837,7 +827,7 @@ async function show(rt, s, id, opts) {
|
|
|
837
827
|
const window = [];
|
|
838
828
|
let n = 0;
|
|
839
829
|
try {
|
|
840
|
-
for await (const m of reader.messages(r.path)) {
|
|
830
|
+
for await (const { origin: _, ...m } of reader.messages(r.path)) {
|
|
841
831
|
n++;
|
|
842
832
|
if (opts.before !== undefined && n >= opts.before)
|
|
843
833
|
break;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Env } from '../types.ts';
|
|
2
2
|
import { type AutostartContext } from './autostart.ts';
|
|
3
3
|
import type { Paths } from './paths.ts';
|
|
4
|
+
import { runProgram } from './update.ts';
|
|
4
5
|
import { type LocalBuild } from './version.ts';
|
|
5
6
|
export interface LocalDirs {
|
|
6
7
|
/** `$XDG_DATA_HOME/sideby-dev`: `pkg` (the running build), `old/<id>`, `npm` (the package it replaced). */
|
|
@@ -35,6 +36,17 @@ export declare const keptVersion: (d: LocalDirs) => Promise<string | null>;
|
|
|
35
36
|
* asked), else install `latest`. After a release the kept copy is the version before it.
|
|
36
37
|
*/
|
|
37
38
|
export declare function offPlan(kept: string | null, latest: string | null): 'restore' | 'install';
|
|
39
|
+
/**
|
|
40
|
+
* Whether the sideby in `dir` can read the user's config file (spec §3.10, ADR-0080): runs its `config get --json`,
|
|
41
|
+
* which reads only that file, in `env` so `HOME` and `XDG_CONFIG_HOME` name the same file the user's sideby reads.
|
|
42
|
+
* 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
|
|
43
|
+
* stop at a key they do not know.
|
|
44
|
+
*/
|
|
45
|
+
export declare function configReadProblem(dir: string, env: Env, run?: typeof runProgram): Promise<string | null>;
|
|
46
|
+
/** What `pnpm local` and the switch say when a build cannot read the config: the cause and what to do (`fix`). */
|
|
47
|
+
export declare const configReadRefusal: (who: string, problem: string, fix: string) => string;
|
|
48
|
+
/** The fix for a Local Build older than the config: build it again from a checkout that has the newer code. */
|
|
49
|
+
export declare 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.";
|
|
38
50
|
export interface LocalStatus {
|
|
39
51
|
/** What the global `sideby` runs: the Local Build in `pkg`, an npm package, or neither (not installed, a link elsewhere). */
|
|
40
52
|
running: 'local' | 'npm' | null;
|