sideby 0.41.1 → 0.41.3
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.js +163 -32
- package/dist/src/cli/json-schemas.js +41 -4
- package/dist/src/cli/main.js +17 -6
- package/dist/src/core/cli-commands.js +1 -1
- package/dist/src/core/config.d.ts +16 -0
- package/dist/src/core/config.js +262 -42
- 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 +27 -0
- 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/index.js +1 -0
- 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 +11 -4
- package/dist/src/panel/handler.js +50 -25
- package/dist/src/panel/i18n.d.ts +23 -1
- package/dist/src/panel/i18n.js +48 -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 +140 -36
- package/dist/src/panel/page-styles.js +17 -0
- package/dist/src/unattended/hook.d.ts +10 -5
- package/dist/src/unattended/hook.js +17 -12
- package/package.json +1 -1
- package/schemas/unattended-pending.json +156 -56
- package/skills/sideby/SKILL.md +2 -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/unattended.md +16 -5
package/dist/src/core/config.js
CHANGED
|
@@ -341,28 +341,179 @@ export function handoffSettings(config) {
|
|
|
341
341
|
}
|
|
342
342
|
export class ConfigError extends UserError {
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
// ---- Keys this sideby does not know (spec §3.10, ADR-0080). A newer sideby, or a typo, may leave a key the schema
|
|
345
|
+
// does not have. Reading ignores it and reports it; writing keeps it where it was; only `config set` refuses a new one.
|
|
346
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
347
|
+
/**
|
|
348
|
+
* The node whose keys are walked; none inside a union. An alias is a ref or `{ account, args }`, and anything else in
|
|
349
|
+
* that object stays an error (ADR-0005 keeps `env` out of aliases), as does every other value of a union.
|
|
350
|
+
*/
|
|
351
|
+
const objectForm = (node) => (node.anyOf ? undefined : node);
|
|
352
|
+
const recordChild = (node, key) => Object.entries(node.patternProperties ?? {}).find(([re]) => new RegExp(re).test(key))?.[1];
|
|
353
|
+
/** Whether `key` is one a closed object node does not declare. Record keys are the user's own names, never unknown. */
|
|
354
|
+
const unknownIn = (node, key) => !!node.properties && !Object.hasOwn(node.properties, key) && node.additionalProperties === false;
|
|
355
|
+
/** The paths of keys in `value` that `node` does not declare, walking objects, records and arrays. */
|
|
356
|
+
function findUnknown(node, value, path, out) {
|
|
357
|
+
if (Array.isArray(value)) {
|
|
358
|
+
if (node.items)
|
|
359
|
+
for (const [i, v] of value.entries())
|
|
360
|
+
findUnknown(node.items, v, [...path, String(i)], out);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const form = isObj(value) ? objectForm(node) : undefined;
|
|
364
|
+
if (!form || !isObj(value))
|
|
365
|
+
return;
|
|
366
|
+
for (const [k, v] of Object.entries(value)) {
|
|
367
|
+
if (unknownIn(form, k))
|
|
368
|
+
out.push([...path, k]);
|
|
369
|
+
else {
|
|
370
|
+
const child = form.properties && Object.hasOwn(form.properties, k) ? form.properties[k] : recordChild(form, k);
|
|
371
|
+
if (child)
|
|
372
|
+
findUnknown(child, v, [...path, k], out);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/** A copy of `value` without the keys `node` does not declare. */
|
|
377
|
+
function stripUnknown(node, value) {
|
|
378
|
+
if (Array.isArray(value))
|
|
379
|
+
return node.items ? value.map((v) => stripUnknown(node.items, v)) : value;
|
|
380
|
+
const form = isObj(value) ? objectForm(node) : undefined;
|
|
381
|
+
if (!form || !isObj(value))
|
|
382
|
+
return value;
|
|
383
|
+
const out = {};
|
|
384
|
+
for (const [k, v] of Object.entries(value)) {
|
|
385
|
+
if (unknownIn(form, k))
|
|
386
|
+
continue;
|
|
387
|
+
const child = form.properties && Object.hasOwn(form.properties, k) ? form.properties[k] : recordChild(form, k);
|
|
388
|
+
out[k] = child ? stripUnknown(child, v) : v;
|
|
389
|
+
}
|
|
390
|
+
return out;
|
|
391
|
+
}
|
|
392
|
+
const hasUnknown = (node, value) => {
|
|
393
|
+
const found = [];
|
|
394
|
+
findUnknown(node, value, [], found);
|
|
395
|
+
return found.length > 0;
|
|
396
|
+
};
|
|
397
|
+
/**
|
|
398
|
+
* Puts the unknown keys of `orig` back into `edited`, which an edit made from `orig` without them. An unknown key stays
|
|
399
|
+
* after the same sibling it followed; the known keys keep the edit's order. An object the edit removed keeps just its
|
|
400
|
+
* unknown keys (a section emptied of known keys is not the user asking to drop a newer sideby's setting), but a record
|
|
401
|
+
* entry the edit removed, or a list item it removed or changed, goes with its unknown keys (a list item has no name to
|
|
402
|
+
* match it by). `drop` is the path `config unset` named: there nothing is put back.
|
|
403
|
+
*/
|
|
404
|
+
function graftUnknown(node, orig, edited, drop) {
|
|
405
|
+
if ((drop && drop.length === 0) || !hasUnknown(node, orig))
|
|
406
|
+
return edited;
|
|
407
|
+
if (Array.isArray(orig)) {
|
|
408
|
+
if (!Array.isArray(edited) || !node.items)
|
|
409
|
+
return edited;
|
|
410
|
+
const used = new Set();
|
|
411
|
+
return edited.map((e) => {
|
|
412
|
+
const same = JSON.stringify(e);
|
|
413
|
+
const i = orig.findIndex((o, j) => !used.has(j) && JSON.stringify(stripUnknown(node.items, o)) === same);
|
|
414
|
+
if (i < 0)
|
|
415
|
+
return e;
|
|
416
|
+
used.add(i);
|
|
417
|
+
return orig[i];
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const form = objectForm(node);
|
|
421
|
+
if (!form || !isObj(orig))
|
|
422
|
+
return edited;
|
|
423
|
+
const sub = (k) => (drop && drop[0] === k ? drop.slice(1) : null);
|
|
424
|
+
if (form.patternProperties && !form.properties) {
|
|
425
|
+
if (!isObj(edited))
|
|
426
|
+
return edited;
|
|
427
|
+
const out = {};
|
|
428
|
+
for (const [k, v] of Object.entries(edited)) {
|
|
429
|
+
const child = recordChild(form, k);
|
|
430
|
+
out[k] = child && Object.hasOwn(orig, k) ? graftUnknown(child, orig[k], v, sub(k)) : v;
|
|
431
|
+
}
|
|
432
|
+
return out;
|
|
433
|
+
}
|
|
434
|
+
if (!form.properties || (edited !== undefined && !isObj(edited)))
|
|
435
|
+
return edited;
|
|
436
|
+
const now = edited ?? {};
|
|
437
|
+
// Each kept key of `orig` that the edit does not have goes after the last key before it that the edit kept.
|
|
438
|
+
const after = new Map();
|
|
439
|
+
let anchor = null;
|
|
440
|
+
for (const [k, v] of Object.entries(orig)) {
|
|
441
|
+
if (Object.hasOwn(now, k)) {
|
|
442
|
+
anchor = k;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
let kept;
|
|
446
|
+
if (unknownIn(form, k))
|
|
447
|
+
kept = sub(k)?.length === 0 ? undefined : v;
|
|
448
|
+
else if (form.properties[k])
|
|
449
|
+
kept = graftUnknown(form.properties[k], v, undefined, sub(k));
|
|
450
|
+
if (kept !== undefined)
|
|
451
|
+
after.set(anchor, [...(after.get(anchor) ?? []), [k, kept]]);
|
|
452
|
+
}
|
|
453
|
+
const out = Object.fromEntries(after.get(null) ?? []);
|
|
454
|
+
for (const [k, v] of Object.entries(now)) {
|
|
455
|
+
const child = form.properties[k];
|
|
456
|
+
out[k] = child && Object.hasOwn(orig, k) ? graftUnknown(child, orig[k], v, sub(k)) : v;
|
|
457
|
+
for (const [uk, uv] of after.get(k) ?? [])
|
|
458
|
+
out[uk] = uv;
|
|
459
|
+
}
|
|
460
|
+
return edited === undefined && Object.keys(out).length === 0 ? undefined : out;
|
|
461
|
+
}
|
|
462
|
+
/** The first way `data` (unknown keys already left out) does not match the schema, or null. */
|
|
463
|
+
function schemaProblem(data) {
|
|
464
|
+
if (Value.Check(ConfigSchema, data))
|
|
465
|
+
return null;
|
|
466
|
+
const first = [...Value.Errors(ConfigSchema, data)][0];
|
|
467
|
+
// A key the schema does not have shows up as "schema is false" or "must not have additional properties".
|
|
468
|
+
const extra = first?.message === 'schema is false' || first?.keyword === 'additionalProperties';
|
|
469
|
+
return {
|
|
470
|
+
where: first?.instancePath || '/',
|
|
471
|
+
message: extra ? 'is not a config key' : (first?.message ?? 'is invalid'),
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* What `sideby list` and `sideby doctor` say about a key this sideby does not know (ADR-0080): why it is there and
|
|
476
|
+
* what to do. Never printed by `loadConfig`, which hooks and `--json` commands use too.
|
|
477
|
+
*/
|
|
478
|
+
export function unknownConfigKeyNote(key, version) {
|
|
479
|
+
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\``;
|
|
480
|
+
}
|
|
481
|
+
/** `loadConfig`, and also the keys in the file this sideby does not know. */
|
|
482
|
+
export async function readConfig(file) {
|
|
345
483
|
let raw;
|
|
346
484
|
try {
|
|
347
485
|
raw = await readFile(file, 'utf8');
|
|
348
486
|
}
|
|
349
487
|
catch (err) {
|
|
350
488
|
if (err.code === 'ENOENT')
|
|
351
|
-
return {};
|
|
489
|
+
return { config: {}, unknownKeys: [] };
|
|
352
490
|
throw new ConfigError(`cannot read ${file}: ${err.message}`);
|
|
353
491
|
}
|
|
354
|
-
let
|
|
492
|
+
let parsed;
|
|
355
493
|
try {
|
|
356
|
-
|
|
494
|
+
parsed = parseJsonSafely(raw, file);
|
|
357
495
|
}
|
|
358
496
|
catch {
|
|
359
497
|
throw new ConfigError(`${file} is not valid JSON; fix the syntax or delete the file`);
|
|
360
498
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
499
|
+
const schema = ConfigSchema;
|
|
500
|
+
const found = [];
|
|
501
|
+
findUnknown(schema, parsed, [], found);
|
|
502
|
+
const data = found.length ? stripUnknown(schema, parsed) : parsed;
|
|
503
|
+
const problem = schemaProblem(data);
|
|
504
|
+
if (problem)
|
|
505
|
+
throw new ConfigError(`${file}: ${problem.where} ${problem.message}; see schemas/config.json`);
|
|
506
|
+
const config = checkLoaded(file, data);
|
|
507
|
+
return { config, unknownKeys: found.map((p) => p.join('.')) };
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Reads the config file; a missing file is `{}`. Keys this sideby does not know are left out and not an error
|
|
511
|
+
* (`readConfig` lists them); a known key with a wrong value is. Prints nothing.
|
|
512
|
+
*/
|
|
513
|
+
export async function loadConfig(file) {
|
|
514
|
+
return (await readConfig(file)).config;
|
|
515
|
+
}
|
|
516
|
+
function checkLoaded(file, data) {
|
|
366
517
|
const handoff = handoffSettings(data);
|
|
367
518
|
if (handoff.prepareAt >= handoff.threshold)
|
|
368
519
|
throw new ConfigError(`${file}: handoff.prepareAt (${handoff.prepareAt}) must be lower than handoff.threshold (${handoff.threshold}); lower prepareAt or raise threshold`);
|
|
@@ -406,44 +557,25 @@ async function configTarget(file) {
|
|
|
406
557
|
* `retry` names what to do again after a fix.
|
|
407
558
|
*/
|
|
408
559
|
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];
|
|
560
|
+
const { target, raw, data } = await readConfigForEdit(file, retry);
|
|
561
|
+
// The edit and every check see only the keys this sideby knows; the others go back in when the file is written
|
|
562
|
+
// (ADR-0080), so a key the edit adds that the schema does not have is still refused.
|
|
563
|
+
const schema = ConfigSchema;
|
|
564
|
+
const known = stripUnknown(schema, data);
|
|
565
|
+
const before = known[key];
|
|
434
566
|
const after = edit(before);
|
|
435
567
|
if (after === null || JSON.stringify(after) === JSON.stringify(before))
|
|
436
568
|
return { changed: false, before, after: before };
|
|
437
569
|
// A new file gets the schema link editors use for completion; an existing file keeps its keys in order.
|
|
438
570
|
const next = raw === null
|
|
439
571
|
? { $schema: 'https://unpkg.com/sideby/schemas/config.json', [key]: after }
|
|
440
|
-
: { ...
|
|
572
|
+
: { ...known, [key]: after };
|
|
441
573
|
if (after === undefined)
|
|
442
574
|
delete next[key];
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const where =
|
|
446
|
-
throw new ConfigError(`${where} ${
|
|
575
|
+
const problem = schemaProblem(next);
|
|
576
|
+
if (problem) {
|
|
577
|
+
const where = problem.where.replace(/^\//, '').split('/').join('.') || key;
|
|
578
|
+
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
579
|
}
|
|
448
580
|
for (const alias of Object.keys(next.aliases ?? {})) {
|
|
449
581
|
const problem = aliasProblem(alias);
|
|
@@ -458,15 +590,90 @@ async function editConfigKey(file, key, retry, edit, opts = {}) {
|
|
|
458
590
|
const h = handoffSettings(next);
|
|
459
591
|
if (h.prepareAt >= h.threshold)
|
|
460
592
|
throw new ConfigError(`handoff.prepareAt must be lower than handoff.threshold; fix them in ${file} and ${retry} again`);
|
|
593
|
+
let out = next;
|
|
594
|
+
if (raw !== null) {
|
|
595
|
+
const kept = schema.properties?.[key]
|
|
596
|
+
? graftUnknown(schema.properties[key], data[key], after, opts.drop ?? null)
|
|
597
|
+
: after;
|
|
598
|
+
// A section that holds only keys this sideby does not know stays as it is: nothing changes.
|
|
599
|
+
if (JSON.stringify(kept) === JSON.stringify(data[key]))
|
|
600
|
+
return { changed: false, before, after: before };
|
|
601
|
+
out = { ...data, [key]: kept };
|
|
602
|
+
if (kept === undefined)
|
|
603
|
+
delete out[key];
|
|
604
|
+
}
|
|
461
605
|
if (opts.dryRun)
|
|
462
606
|
return { changed: true, before, after };
|
|
607
|
+
await writeConfigFile(file, target, raw, out);
|
|
608
|
+
return { changed: true, before, after };
|
|
609
|
+
}
|
|
610
|
+
/** The config file for a change: its real path, its text (null when missing) and the JSON object in it. */
|
|
611
|
+
async function readConfigForEdit(file, retry) {
|
|
612
|
+
const target = await configTarget(file);
|
|
613
|
+
let raw = null;
|
|
614
|
+
try {
|
|
615
|
+
raw = await readFile(target, 'utf8');
|
|
616
|
+
}
|
|
617
|
+
catch (err) {
|
|
618
|
+
if (err.code !== 'ENOENT')
|
|
619
|
+
throw new ConfigError(`cannot read ${file}: ${err.message}`);
|
|
620
|
+
}
|
|
621
|
+
if (raw === null)
|
|
622
|
+
return { target, raw, data: {} };
|
|
623
|
+
let parsed;
|
|
624
|
+
try {
|
|
625
|
+
parsed = parseJsonSafely(raw, file);
|
|
626
|
+
}
|
|
627
|
+
catch {
|
|
628
|
+
throw new ConfigError(`${file} is not valid JSON; nothing was changed. Fix the syntax and ${retry} again`);
|
|
629
|
+
}
|
|
630
|
+
if (!isObj(parsed))
|
|
631
|
+
throw new ConfigError(`${file} is not a JSON object; nothing was changed. Fix it and ${retry} again`);
|
|
632
|
+
const problem = schemaProblem(stripUnknown(ConfigSchema, parsed));
|
|
633
|
+
if (problem) {
|
|
634
|
+
const where = problem.where.replace(/^\//, '').split('/').join('.') || 'the file';
|
|
635
|
+
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`);
|
|
636
|
+
}
|
|
637
|
+
return { target, raw, data: parsed };
|
|
638
|
+
}
|
|
639
|
+
/** Writes `data` as 2-space JSON atomically, keeping the file's mode (0600 for a new file), only if it did not change. */
|
|
640
|
+
async function writeConfigFile(file, target, raw, data) {
|
|
463
641
|
const st = raw === null ? null : await lstatOrNull(target);
|
|
464
642
|
if (raw === null)
|
|
465
643
|
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
466
|
-
const written = await writeIfUnchanged(target, raw === null ? null : sha256(raw), `${JSON.stringify(
|
|
644
|
+
const written = await writeIfUnchanged(target, raw === null ? null : sha256(raw), `${JSON.stringify(data, null, 2)}\n`, st ? st.mode & 0o777 : 0o600);
|
|
467
645
|
if (!written)
|
|
468
646
|
throw new ConfigError(`${file} changed while sideby was writing it; nothing was changed. Try again`);
|
|
469
|
-
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* `sideby config unset <key>` for a key in the file this sideby does not know (ADR-0080): removes just that key, and
|
|
650
|
+
* objects it leaves empty. Null when the file has no such unknown key.
|
|
651
|
+
*/
|
|
652
|
+
async function unsetUnknownKey(file, key, opts) {
|
|
653
|
+
const { target, raw, data } = await readConfigForEdit(file, 'run the command');
|
|
654
|
+
const found = [];
|
|
655
|
+
findUnknown(ConfigSchema, data, [], found);
|
|
656
|
+
const path = found.find((p) => p.join('.') === key);
|
|
657
|
+
if (!path)
|
|
658
|
+
return null;
|
|
659
|
+
const before = getIn(data, path);
|
|
660
|
+
if (!opts.dryRun) {
|
|
661
|
+
const next = structuredClone(data);
|
|
662
|
+
const chain = [next];
|
|
663
|
+
for (const seg of path.slice(0, -1))
|
|
664
|
+
chain.push(chain.at(-1)[seg]);
|
|
665
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
666
|
+
const parent = chain[i];
|
|
667
|
+
const child = parent[path[i]];
|
|
668
|
+
if (i < path.length - 1 && !isEmptyObject(child))
|
|
669
|
+
break;
|
|
670
|
+
if (Array.isArray(parent))
|
|
671
|
+
break;
|
|
672
|
+
delete parent[path[i]];
|
|
673
|
+
}
|
|
674
|
+
await writeConfigFile(file, target, raw, next);
|
|
675
|
+
}
|
|
676
|
+
return { key, before, after: undefined, changed: true };
|
|
470
677
|
}
|
|
471
678
|
async function editConfigAliases(file, retry, edit) {
|
|
472
679
|
const r = await editConfigKey(file, 'aliases', retry, (current) => edit(current ?? {}));
|
|
@@ -873,6 +1080,17 @@ const isEmptyObject = (v) => typeof v === 'object' && v !== null && !Array.isArr
|
|
|
873
1080
|
* every other config change (see `editConfigKey`); `dryRun` shows the change without writing.
|
|
874
1081
|
*/
|
|
875
1082
|
export async function editConfigPath(file, key, value, opts = {}) {
|
|
1083
|
+
// A key this sideby does not know (ADR-0080) can only be removed, and only where the file has it.
|
|
1084
|
+
const segs = key.split('.');
|
|
1085
|
+
if (value === undefined &&
|
|
1086
|
+
key &&
|
|
1087
|
+
!segs.some((p) => !p || BAD_SEGMENT.has(p)) &&
|
|
1088
|
+
segs[0] !== '$schema' &&
|
|
1089
|
+
segs[0] !== 'plugins') {
|
|
1090
|
+
const removed = await unsetUnknownKey(file, key, opts);
|
|
1091
|
+
if (removed)
|
|
1092
|
+
return removed;
|
|
1093
|
+
}
|
|
876
1094
|
const path = configKeyPath(key);
|
|
877
1095
|
if (path[0] === 'plugins' && value !== undefined && typeof value !== 'boolean')
|
|
878
1096
|
throw new ConfigError(`${key} takes true or false`, { code: 'bad-value' });
|
|
@@ -885,7 +1103,9 @@ export async function editConfigPath(file, key, value, opts = {}) {
|
|
|
885
1103
|
if (top === 'handoff')
|
|
886
1104
|
opts.checkHandoff?.(current, result);
|
|
887
1105
|
return result;
|
|
888
|
-
},
|
|
1106
|
+
},
|
|
1107
|
+
// `config unset` of a section removes it whole, also keys this sideby does not know; anything else keeps them.
|
|
1108
|
+
{ ...opts, ...(value === undefined ? { drop: path.slice(1) } : {}) });
|
|
889
1109
|
const inner = path.slice(1);
|
|
890
1110
|
return { key, before: getIn(r.before, inner), after: getIn(r.after, inner), changed: r.changed };
|
|
891
1111
|
}
|
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -371,6 +371,33 @@ const ENTRIES = [
|
|
|
371
371
|
target: { action: 'unattended-add-slot', write: true },
|
|
372
372
|
cliCommand: 'sideby unattended schedule add',
|
|
373
373
|
},
|
|
374
|
+
{
|
|
375
|
+
id: 'action.unattended-pending',
|
|
376
|
+
kind: 'action',
|
|
377
|
+
title: { en: 'See what sessions left for you, by project', zh: '按项目看待你决定的事' },
|
|
378
|
+
synonyms: [
|
|
379
|
+
'pending decisions',
|
|
380
|
+
'waiting for you',
|
|
381
|
+
'not handled',
|
|
382
|
+
'wrote in the session afterwards',
|
|
383
|
+
'待你决定',
|
|
384
|
+
'哪些处理了',
|
|
385
|
+
'没处理的',
|
|
386
|
+
'之后说过话',
|
|
387
|
+
],
|
|
388
|
+
panel: at({ en: 'Unattended page', zh: '无人值守页' }, { en: 'Waiting for you', zh: '待你决定' }),
|
|
389
|
+
target: { action: 'unattended-pending', write: false },
|
|
390
|
+
cliCommand: 'sideby unattended pending',
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
id: 'action.unattended-pending-reopen',
|
|
394
|
+
kind: 'action',
|
|
395
|
+
title: { en: 'Reopen a decision marked done by mistake', zh: '重新打开标错的待决事项' },
|
|
396
|
+
synonyms: ['reopen', 'undo done', 'marked done by mistake', '重新打开', '标错了', '撤销已处理'],
|
|
397
|
+
panel: at({ en: 'Unattended page', zh: '无人值守页' }, { en: 'Done', zh: '已处理' }),
|
|
398
|
+
target: { action: 'unattended-pending-done', write: false },
|
|
399
|
+
cliCommand: 'sideby unattended pending reopen',
|
|
400
|
+
},
|
|
374
401
|
{
|
|
375
402
|
id: 'action.unattended-wait',
|
|
376
403
|
kind: 'action',
|