sideby 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +3 -1
  2. package/ai-tasks.json +90 -0
  3. package/dist/build.json +1 -1
  4. package/dist/src/cli/commands.d.ts +9 -1
  5. package/dist/src/cli/commands.js +349 -14
  6. package/dist/src/cli/json-schemas.js +157 -18
  7. package/dist/src/cli/main.js +56 -7
  8. package/dist/src/core/after-install.d.ts +54 -0
  9. package/dist/src/core/after-install.js +78 -0
  10. package/dist/src/core/ask.d.ts +73 -1
  11. package/dist/src/core/ask.js +106 -6
  12. package/dist/src/core/autostart.d.ts +38 -8
  13. package/dist/src/core/autostart.js +85 -39
  14. package/dist/src/core/brand-mark.d.ts +49 -11
  15. package/dist/src/core/brand-mark.js +116 -38
  16. package/dist/src/core/config.d.ts +5 -0
  17. package/dist/src/core/config.js +11 -1
  18. package/dist/src/core/desktop-app.d.ts +1 -1
  19. package/dist/src/core/desktop-app.js +2 -2
  20. package/dist/src/core/edit-settings.d.ts +24 -0
  21. package/dist/src/core/edit-settings.js +97 -0
  22. package/dist/src/core/handoff-brief.d.ts +4 -2
  23. package/dist/src/core/handoff-brief.js +6 -1
  24. package/dist/src/core/handoff-chain.d.ts +24 -0
  25. package/dist/src/core/handoff-chain.js +2 -0
  26. package/dist/src/core/handoff-run.d.ts +4 -3
  27. package/dist/src/core/handoff-run.js +14 -9
  28. package/dist/src/core/launch.d.ts +2 -0
  29. package/dist/src/core/launch.js +14 -10
  30. package/dist/src/core/local-build.d.ts +12 -5
  31. package/dist/src/core/local-build.js +49 -31
  32. package/dist/src/core/lock.d.ts +30 -0
  33. package/dist/src/core/lock.js +143 -0
  34. package/dist/src/core/quota-levels.d.ts +6 -1
  35. package/dist/src/core/quota-levels.js +16 -5
  36. package/dist/src/core/task-spec.d.ts +95 -0
  37. package/dist/src/core/task-spec.js +209 -0
  38. package/dist/src/core/terminal.js +6 -1
  39. package/dist/src/core/update.d.ts +27 -16
  40. package/dist/src/core/update.js +67 -93
  41. package/dist/src/desktop/icon.js +12 -15
  42. package/dist/src/families/claude/ai-task.d.ts +8 -0
  43. package/dist/src/families/claude/ai-task.js +38 -0
  44. package/dist/src/families/claude/handoff-hook.js +4 -4
  45. package/dist/src/families/claude/index.js +3 -0
  46. package/dist/src/families/codex/handoff-hook.js +4 -4
  47. package/dist/src/families/codex/index.js +9 -0
  48. package/dist/src/families/grok/handoff-hook.js +4 -4
  49. package/dist/src/families/grok/index.js +1 -0
  50. package/dist/src/families/pi/index.js +1 -0
  51. package/dist/src/handoff/hook.js +51 -30
  52. package/dist/src/handoff/levels.d.ts +24 -0
  53. package/dist/src/handoff/levels.js +70 -0
  54. package/dist/src/handoff/messages.d.ts +6 -3
  55. package/dist/src/handoff/messages.js +20 -7
  56. package/dist/src/handoff/reader.d.ts +6 -3
  57. package/dist/src/menubar/agent.d.ts +3 -0
  58. package/dist/src/menubar/agent.js +21 -0
  59. package/dist/src/menubar/script.d.ts +8 -0
  60. package/dist/src/menubar/script.js +457 -0
  61. package/dist/src/menubar/snapshot.d.ts +115 -0
  62. package/dist/src/menubar/snapshot.js +255 -0
  63. package/dist/src/menubar/strings.d.ts +87 -0
  64. package/dist/src/menubar/strings.js +88 -0
  65. package/dist/src/panel/background.js +12 -19
  66. package/dist/src/panel/handler.d.ts +12 -0
  67. package/dist/src/panel/handler.js +80 -80
  68. package/dist/src/panel/i18n.d.ts +33 -0
  69. package/dist/src/panel/i18n.js +66 -0
  70. package/dist/src/panel/page-logic.d.ts +105 -0
  71. package/dist/src/panel/page-logic.js +170 -15
  72. package/dist/src/panel/page-script.js +238 -109
  73. package/dist/src/panel/page-styles.js +42 -13
  74. package/dist/src/panel/page.d.ts +7 -0
  75. package/dist/src/panel/page.js +5 -0
  76. package/dist/src/runtime.d.ts +9 -1
  77. package/dist/src/runtime.js +11 -3
  78. package/dist/src/types.d.ts +14 -0
  79. package/package.json +4 -3
  80. package/schemas/ask-choices.json +168 -0
  81. package/schemas/ask-print.json +87 -0
  82. package/schemas/config.json +17 -1
  83. package/schemas/edit.json +119 -0
  84. package/schemas/error.json +4 -0
  85. package/schemas/families.json +4 -0
  86. package/schemas/list.json +4 -0
  87. package/schemas/local.json +1 -1
  88. package/schemas/menubar-snapshot.json +646 -0
  89. package/schemas/menubar-start.json +112 -0
  90. package/schemas/menubar.json +165 -0
  91. package/skills/sideby/SKILL.md +6 -2
  92. package/skills/sideby/references/ai-tasks.md +10 -0
  93. package/skills/sideby/references/handoff.md +3 -1
  94. package/skills/sideby/references/panel.md +6 -0
  95. package/skills/sideby/references/update.md +1 -1
@@ -1,8 +1,10 @@
1
1
  // The sideby mark: two buddies side by side, the amber one behind on the left and the blue one in front on the right,
2
2
  // looking at each other (ADR-0022, the characters of the intro film). One source for the Panel header, the empty
3
3
  // state, the Portal icon, the favicon and the app icon.
4
- // One buddy is drawn on a 64-unit grid; the mark places two of them with a translate and a scale.
5
- /** Back to front: feet, arms, body, then the face. */
4
+ // One buddy is drawn on a 64-unit grid; the mark places two of them with a translate and a scale. Both share one
5
+ // gumdrop body; what tells them apart is a pair of props each, from the brand design sheet (ADR-0022 amendment):
6
+ // Sai, the blue one, wears a gold crown and a red cape; Bai, the amber one, a bent antenna and a spare battery.
7
+ /** The body both buddies share, back to front: feet, arms, body; then the eyes. No forehead `>`: that belongs to Nika. */
6
8
  export const BUDDY = {
7
9
  paths: [
8
10
  { d: 'M17 48 Q15 58 22 57 Q27 57 27 50 M37 50 Q37 57 42 57 Q49 58 47 48', fill: 'shade' },
@@ -11,14 +13,49 @@ export const BUDDY = {
11
13
  d: 'M12 37 C12 27 17 23 25 23 H39 C47 23 52 27 52 37 C52 48 45 53 32 53 C19 53 12 48 12 37 Z',
12
14
  fill: 'body',
13
15
  },
14
- { d: 'M30 27 L34 29.31 L30 31.62', fill: 'none', stroke: 'chevron', width: 2.5 },
15
- { d: 'M29 46 Q32 49 35 46', fill: 'none', width: 2.5 },
16
16
  ],
17
17
  eyes: [
18
18
  { cx: 22, cy: 38.5, rx: 4.5, ry: 6, fill: 'ink' },
19
19
  { cx: 42, cy: 38.5, rx: 4.5, ry: 6, fill: 'ink' },
20
20
  ],
21
21
  };
22
+ const RED = '#e0685a';
23
+ const GOLD = '#ffd977';
24
+ const GREEN = '#5bb06a';
25
+ /** Sai (blue): a red cape behind the shoulders, a gold crown with a red jewel, a small smile. */
26
+ export const SAI = {
27
+ behind: [
28
+ { d: 'M19 29 Q10 27 9 34 L4 53 Q13 57 22 50 L42 50 Q51 57 60 53 L55 34 Q54 27 45 29 Z', fill: RED },
29
+ ],
30
+ mouth: { d: 'M29 46 Q32 49 35 46', fill: 'none', width: 2.5 },
31
+ above: [
32
+ { d: 'M20 23 L17 10 L27 15 L32 6 L37 15 L47 10 L44 23 Z', fill: GOLD },
33
+ {
34
+ d: 'M35 19 C35 20.66 33.66 22 32 22 C30.34 22 29 20.66 29 19 C29 17.34 30.34 16 32 16 C33.66 16 35 17.34 35 19 Z',
35
+ fill: RED,
36
+ stroke: 'none',
37
+ },
38
+ ],
39
+ };
40
+ /** Bai (amber): a green spare battery on its back, a bent antenna with a ball, an open laugh. */
41
+ export const BAI = {
42
+ behind: [
43
+ {
44
+ d: 'M52 23 H56 C58.21 23 60 24.79 60 27 L60 48 C60 50.21 58.21 52 56 52 H52 C49.79 52 48 50.21 48 48 L48 27 C48 24.79 49.79 23 52 23 Z',
45
+ fill: GREEN,
46
+ },
47
+ { d: 'M52 23 L52 19 H57 L57 23', fill: GREEN },
48
+ { d: 'M51 32 H57 M54 29 L54 35', fill: 'none', stroke: 'light', width: 2 },
49
+ ],
50
+ mouth: { d: 'M29 46 Q32 52 35 46 Z', fill: 'ink', width: 2.5 },
51
+ above: [
52
+ { d: 'M31 24 C24 17 26 9 36 10', fill: 'none', stroke: GREEN, width: 4 },
53
+ {
54
+ d: 'M44 10 C44 12.76 41.76 15 39 15 C36.24 15 34 12.76 34 10 C34 7.24 36.24 5 39 5 C41.76 5 44 7.24 44 10 Z',
55
+ fill: GREEN,
56
+ },
57
+ ],
58
+ };
22
59
  /** The eye highlights sit towards where the buddy looks: `1` right, `-1` left. */
23
60
  export function highlights(look) {
24
61
  return BUDDY.eyes.map((e) => ({
@@ -30,8 +67,8 @@ export function highlights(look) {
30
67
  }));
31
68
  }
32
69
  export const MARK_COLORS = {
33
- blue: { body: '#3f8fc4', shade: '#29658e', chevron: '#f2b35e' },
34
- amber: { body: '#f2b35e', shade: '#c98a35', chevron: '#3f8fc4' },
70
+ blue: { body: '#3f8fc4', shade: '#29658e' },
71
+ amber: { body: '#f2b35e', shade: '#c98a35' },
35
72
  ink: '#1e2a44',
36
73
  light: '#f6f0e5',
37
74
  };
@@ -41,39 +78,76 @@ export const MARK = {
41
78
  line: 2.75,
42
79
  /** Outline width of a placed buddy before its scale, so the outline stays about 2.5 mark units. */
43
80
  placedLine: 3.6,
44
- back: { colors: MARK_COLORS.amber, look: 1, x: -2, y: 2, scale: 0.7 },
45
- front: { colors: MARK_COLORS.blue, look: -1, x: 22, y: 16, scale: 0.7 },
81
+ back: { colors: MARK_COLORS.amber, props: BAI, look: 1, mirror: true, x: -2, y: 2, scale: 0.7 },
82
+ front: { colors: MARK_COLORS.blue, props: SAI, look: -1, x: 22, y: 16, scale: 0.7 },
46
83
  };
47
84
  /** The square the pair is drawn in, in mark units (the Panel's 40 px tile and the app icon tile). */
48
85
  export const MARK_VIEWBOX = { x: -2.5, y: 3, size: 69 };
49
- function buddySvg(b, line, bodyFill) {
50
- const color = (fill) => {
51
- if (fill === 'none')
52
- return ' fill="none"';
53
- if (fill === 'shade')
54
- return ` fill="${b.colors.shade}"`;
55
- return bodyFill === null ? '' : ` fill="${bodyFill ?? b.colors.body}"`;
86
+ /** Path data mirrored on the 64-unit grid (x → 64 − x); absolute M, L, H, Q, C, Z only. */
87
+ export function mirrorPath(d) {
88
+ let cmd = '';
89
+ let n = 0;
90
+ return d.replace(/[MLHQCZ]|-?\d*\.?\d+/g, (t) => {
91
+ if (/[A-Z]/.test(t)) {
92
+ cmd = t;
93
+ n = 0;
94
+ return t;
95
+ }
96
+ const isX = cmd === 'H' || n++ % 2 === 0;
97
+ return isX ? String(Math.round((64 - Number(t)) * 1000) / 1000) : t;
98
+ });
99
+ }
100
+ const paint = (p) => (p === 'ink' ? MARK_COLORS.ink : p === 'light' ? MARK_COLORS.light : p);
101
+ /**
102
+ * One buddy's shapes, back to front: the props behind, the body, the mouth, the eyes, the props above.
103
+ * `bodyFill`: `undefined` keeps the buddy's body colour, `null` leaves the body unfilled so it inherits.
104
+ */
105
+ export function buddyShapes(b, bodyFill) {
106
+ const resolve = (p) => {
107
+ const fill = p.fill === 'none'
108
+ ? 'none'
109
+ : p.fill === 'shade'
110
+ ? b.colors.shade
111
+ : p.fill === 'body'
112
+ ? bodyFill === null
113
+ ? undefined
114
+ : (bodyFill ?? b.colors.body)
115
+ : paint(p.fill);
116
+ const stroke = p.stroke === undefined ? MARK_COLORS.ink : p.stroke === 'none' ? 'none' : paint(p.stroke);
117
+ return { d: p.d, fill, stroke, ...(p.width ? { width: p.width } : {}) };
56
118
  };
57
- const paths = BUDDY.paths
58
- .map((p) => {
59
- const stroke = p.stroke === 'chevron' ? ` stroke="${b.colors.chevron}"` : '';
60
- const width = p.width ? ` stroke-width="${p.width}"` : '';
61
- return `<path d="${p.d}"${color(p.fill)}${stroke}${width}/>`;
62
- })
63
- .join('');
64
- const dots = [...BUDDY.eyes, ...highlights(b.look)]
119
+ const prop = (p) => {
120
+ const s = resolve(p);
121
+ return b.mirror ? { ...s, d: mirrorPath(s.d) } : s;
122
+ };
123
+ return {
124
+ paths: [...b.props.behind.map(prop), ...BUDDY.paths.map(resolve), resolve(b.props.mouth)],
125
+ dots: [...BUDDY.eyes, ...highlights(b.look)],
126
+ above: b.props.above.map(prop),
127
+ };
128
+ }
129
+ function shapeSvg(s) {
130
+ const fill = s.fill === undefined ? '' : ` fill="${s.fill}"`;
131
+ const stroke = s.stroke === MARK_COLORS.ink ? '' : ` stroke="${s.stroke}"`;
132
+ const width = s.width ? ` stroke-width="${s.width}"` : '';
133
+ return `<path d="${s.d}"${fill}${stroke}${width}/>`;
134
+ }
135
+ /** One placed buddy as SVG, drawn inside a group that sets the ink outline (`MARK_OUTLINE`). */
136
+ export function buddySvg(b, line, bodyFill) {
137
+ const { paths, dots, above } = buddyShapes(b, bodyFill);
138
+ const eyes = dots
65
139
  .map((e) => `<ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" fill="${e.fill === 'ink' ? MARK_COLORS.ink : MARK_COLORS.light}"/>`)
66
140
  .join('');
67
141
  const transform = b.scale === 1 && b.x === 0 && b.y === 0 ? '' : ` transform="translate(${b.x} ${b.y}) scale(${b.scale})"`;
68
- return `<g${transform} stroke-width="${line}">${paths}<g stroke="none">${dots}</g></g>`;
142
+ return `<g${transform} stroke-width="${line}">${paths.map(shapeSvg).join('')}<g stroke="none">${eyes}</g>${above.map(shapeSvg).join('')}</g>`;
69
143
  }
70
- const OUTLINE = `stroke="${MARK_COLORS.ink}" stroke-linecap="round" stroke-linejoin="round"`;
144
+ export const MARK_OUTLINE = `stroke="${MARK_COLORS.ink}" stroke-linecap="round" stroke-linejoin="round"`;
71
145
  /**
72
146
  * The mark as SVG children (no outer <svg>). With `front` omitted the blue buddy's body has no fill of its own, so it
73
147
  * takes the surrounding `fill` (the Panel's `--logo-fg`, which Portals set with `logoColor`); everything else is fixed.
74
148
  */
75
149
  export function markSvgBody(front) {
76
- return `<g ${OUTLINE}>${buddySvg(MARK.back, MARK.placedLine)}${buddySvg(MARK.front, MARK.placedLine, front ?? null)}</g>`;
150
+ return `<g ${MARK_OUTLINE}>${buddySvg(MARK.back, MARK.placedLine)}${buddySvg(MARK.front, MARK.placedLine, front ?? null)}</g>`;
77
151
  }
78
152
  const viewBox = (v) => `${v.x} ${v.y} ${v.size} ${v.size}`;
79
153
  /** The Panel's header logo: the mark sized for its 40 px tile. */
@@ -82,20 +156,24 @@ export const MARK_SVG = `<svg viewBox="${viewBox(MARK_VIEWBOX)}">${markSvgBody()
82
156
  export const ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${viewBox(MARK_VIEWBOX)}" role="img" aria-label="sideby">` +
83
157
  `${markSvgBody(MARK_COLORS.blue.body)}</svg>`;
84
158
  /**
85
- * `<basePath>/favicon.svg`: the small cut for sizes below about 24 px, redrawn for a 16 pt browser tab (ADR-0022):
86
- * the blue buddy alone on a 32 grid, its body filling the width, short feet and no arms, `>` or mouth, bigger eyes,
87
- * and a 2-unit outline (about 6% of the canvas). The same rules as the Local tools Portal's tab icons.
159
+ * `<basePath>/favicon.svg`: the small cut for sizes below about 24 px, for a 16 pt browser tab (ADR-0022): Sai alone
160
+ * on a 32 grid at half scale, his body, eyes, cape and crown; no feet, arms or mouth. The same cut as the tab icons
161
+ * of the brand design sheet.
88
162
  */
89
163
  export const FAVICON_SVG = (() => {
90
- const blue = MARK_COLORS.blue;
91
- const ink = MARK_COLORS.ink;
92
- const light = MARK_COLORS.light;
164
+ const sai = { ...MARK.front, x: 0, y: 0, scale: 1 };
165
+ const { paths, dots, above } = buddyShapes(sai);
93
166
  const body = BUDDY.paths[2].d;
167
+ const keep = paths.filter((p) => p.d === body || SAI.behind.some((q) => q.d === p.d));
168
+ const eyes = dots
169
+ .map((e) => `<ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" fill="${e.fill === 'ink' ? MARK_COLORS.ink : MARK_COLORS.light}"/>`)
170
+ .join('');
94
171
  return (`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" role="img" aria-label="sideby">` +
95
- `<g stroke-linecap="round" stroke-linejoin="round" transform="translate(0 -1.3)">` +
96
- `<path d="M8.5 25 Q7.6 31 11.5 30.6 Q14 30.4 14 26.6 M18 26.6 Q18 30.4 20.5 30.6 Q24.4 31 23.5 25" fill="${blue.shade}" stroke="${ink}" stroke-width="2"/>` +
97
- `<g transform="translate(-7.2 -12.675) scale(0.725)"><path d="${body}" fill="${blue.body}" stroke="${ink}" stroke-width="2.759"/>` +
98
- `<ellipse cx="22.5" cy="38" rx="5.5" ry="7" fill="${ink}"/><ellipse cx="41.5" cy="38" rx="5.5" ry="7" fill="${ink}"/>` +
99
- `<ellipse cx="20.6" cy="35.4" rx="2.1" ry="2.6" fill="${light}"/><ellipse cx="39.6" cy="35.4" rx="2.1" ry="2.6" fill="${light}"/>` +
100
- `</g></g></svg>`);
172
+ `<g transform="translate(0 -1) scale(.5)"><g ${MARK_OUTLINE} stroke-width="${MARK.line}">` +
173
+ `${keep.map(shapeSvg).join('')}<g stroke="none">${eyes}</g>${above.map(shapeSvg).join('')}</g></g></svg>`);
101
174
  })();
175
+ /**
176
+ * The Menu Bar Item's icon (spec §3.31): the favicon's small cut of Sai in colour, 18 pt square. It keeps its colours
177
+ * in light and dark mode, as the brand's tab icons do; the body's dark outline keeps it visible on both.
178
+ */
179
+ export const MENUBAR_ICON_SVG = FAVICON_SVG.replace('<svg ', '<svg width="18" height="18" ');
@@ -21,6 +21,7 @@ export interface HandoffSettings {
21
21
  sameFamily: boolean;
22
22
  prepareAt: number;
23
23
  threshold: number;
24
+ adaptive: boolean;
24
25
  waitIfResetWithinMinutes: number;
25
26
  countdownSeconds: number;
26
27
  crossOrganization: string[];
@@ -35,6 +36,9 @@ export declare const ConfigSchema: Type.TObject<{
35
36
  theme: Type.TOptional<Type.TString>;
36
37
  language: Type.TOptional<Type.TString>;
37
38
  }>>;
39
+ menubar: Type.TOptional<Type.TObject<{
40
+ hotkey: Type.TOptional<Type.TString>;
41
+ }>>;
38
42
  terminal: Type.TOptional<Type.TObject<{
39
43
  preferred: Type.TOptional<Type.TString>;
40
44
  custom: Type.TOptional<Type.TString>;
@@ -65,6 +69,7 @@ export declare const ConfigSchema: Type.TObject<{
65
69
  sameFamily: Type.TOptional<Type.TBoolean>;
66
70
  prepareAt: Type.TOptional<Type.TInteger>;
67
71
  threshold: Type.TOptional<Type.TInteger>;
72
+ adaptive: Type.TOptional<Type.TBoolean>;
68
73
  waitIfResetWithinMinutes: Type.TOptional<Type.TInteger>;
69
74
  countdownSeconds: Type.TOptional<Type.TInteger>;
70
75
  crossOrganization: Type.TOptional<Type.TArray<Type.TString>>;
@@ -55,7 +55,10 @@ const HandoffSchema = Type.Object({
55
55
  description: 'Also hand off to an account of the same family (cc001 → cc002). The kind vendors are most likely to act on. Off by default.',
56
56
  })),
57
57
  prepareAt: Percent('Quota Pressure at which the session starts keeping a Handoff Brief (default 80).'),
58
- threshold: Percent('Quota Pressure at which the Handoff begins (default 95).'),
58
+ threshold: Percent('Quota Pressure at which the Handoff begins (default 95). With `adaptive`, a window uses it until the run has measured a turn of it.'),
59
+ adaptive: Type.Optional(Type.Boolean({
60
+ description: 'Hand over by each window’s own pace: when it has less room left than 1.5 times its largest recent turn, between `prepareAt` and 99 (default true; ADR-0032). False uses `threshold` for every window.',
61
+ })),
59
62
  waitIfResetWithinMinutes: Type.Optional(Type.Integer({
60
63
  minimum: 0,
61
64
  description: 'Stay and wait when the full window resets within this many minutes (default 30; 0 never waits).',
@@ -88,6 +91,12 @@ export const ConfigSchema = Type.Object({
88
91
  description: "Panel language: the browser's (default), English, or Chinese.",
89
92
  })),
90
93
  }, { additionalProperties: false, description: 'How the Panel looks (spec §3.29).' })),
94
+ menubar: Type.Optional(Type.Object({
95
+ hotkey: Type.Optional(Type.String({
96
+ pattern: '^(off|((ctrl|opt|cmd|shift)\\+)+[a-z0-9])$',
97
+ description: 'The shortcut that opens the menu bar item from anywhere, such as `opt+cmd+s` (default), or `off`.',
98
+ })),
99
+ }, { additionalProperties: false, description: 'The Menu Bar Item on macOS (spec §3.31).' })),
91
100
  terminal: Type.Optional(Type.Object({
92
101
  preferred: Type.Optional(Type.String({
93
102
  enum: ['terminal', 'iterm2', 'ghostty', 'orca', 'wezterm', 'kitty', 'alacritty', 'custom'],
@@ -174,6 +183,7 @@ export function handoffSettings(config) {
174
183
  sameFamily: h.sameFamily ?? false,
175
184
  prepareAt: h.prepareAt ?? 80,
176
185
  threshold: h.threshold ?? 95,
186
+ adaptive: h.adaptive ?? true,
177
187
  waitIfResetWithinMinutes: h.waitIfResetWithinMinutes ?? 30,
178
188
  countdownSeconds: h.countdownSeconds ?? 10,
179
189
  crossOrganization: [...(h.crossOrganization ?? [])],
@@ -112,4 +112,4 @@ export declare function withDesktopApps<T extends {
112
112
  * Account. Results are named `app-data/<path>` and are not counted in `shared`. The App Data is the repair boundary:
113
113
  * a fix may only add a missing link inside it or sync a file's `key` there, never replace a real file.
114
114
  */
115
- export declare function checkAppData(plugins: readonly LoadedPlugin[], home: string, account: Account): Promise<CheckResult[]>;
115
+ export declare function checkAppData(plugins: readonly LoadedPlugin[], home: string, account: Account, force?: boolean): Promise<CheckResult[]>;
@@ -369,7 +369,7 @@ export async function withDesktopApps(rt, accounts, statuses) {
369
369
  * Account. Results are named `app-data/<path>` and are not counted in `shared`. The App Data is the repair boundary:
370
370
  * a fix may only add a missing link inside it or sync a file's `key` there, never replace a real file.
371
371
  */
372
- export async function checkAppData(plugins, home, account) {
372
+ export async function checkAppData(plugins, home, account, force = false) {
373
373
  if (account.isMain || account.kind === 'api')
374
374
  return [];
375
375
  const def = desktopAppOf(plugins, account.family);
@@ -383,7 +383,7 @@ export async function checkAppData(plugins, home, account) {
383
383
  const item = { path: f.path, mode: 'link' };
384
384
  const mainPath = join(home, f.mainPath);
385
385
  const p = join(dir, item.path);
386
- const ctx = { account, item, mainPath, accountPath: p, accountDir: dir, force: false };
386
+ const ctx = { account, item, mainPath, accountPath: p, accountDir: dir, force };
387
387
  let res = await checkItem(ctx);
388
388
  // The Desktop App writes its own file when the Main Account had none at first open, and replaces the link when
389
389
  // it saves its preferences: not the user's doing, and a new link would be replaced again. With a `key`, only
@@ -0,0 +1,24 @@
1
+ import type { Runtime } from '../runtime.ts';
2
+ import type { FamilyDef } from '../types.ts';
3
+ export interface EditSettingsResult {
4
+ schemaVersion: 1;
5
+ ref: string;
6
+ family: string;
7
+ /** The file as the Family names it, such as `settings.json`. */
8
+ file: string;
9
+ /** The file inside the account directory. */
10
+ path: string;
11
+ /** Where the file really is, only when `path` is a link. */
12
+ target?: string;
13
+ /** Other Accounts of the Family whose settings file is this same file. */
14
+ sharedWith: string[];
15
+ /** False with `--path`, which only says where the file is. */
16
+ opened: boolean;
17
+ /** The program and arguments that opened it. */
18
+ command?: string[];
19
+ }
20
+ /** The Family's settings file when it names a relative path that stays inside the account directory. */
21
+ export declare function hostSettingsFile(def: Pick<FamilyDef, 'settingsFile'> | undefined): string | undefined;
22
+ export declare function editSettings(rt: Runtime, ref: string, opts?: {
23
+ open?: boolean;
24
+ }): Promise<EditSettingsResult>;
@@ -0,0 +1,97 @@
1
+ // Opens an Account's Host settings file in the user's editor (spec §3.30, ADR-0033). sideby reads none of the file:
2
+ // it checks that the file is there and, for a link, where it really is and which Accounts share it. Every program
3
+ // it runs goes through `DesktopDeps.exec`, so tests start nothing.
4
+ import { realpath } from 'node:fs/promises';
5
+ import { isAbsolute, join } from 'node:path';
6
+ import { depsFor } from './desktop-app.js';
7
+ import { UserError } from './errors.js';
8
+ import { lstatOrNull } from './fs-safe.js';
9
+ /** The Family's settings file when it names a relative path that stays inside the account directory. */
10
+ export function hostSettingsFile(def) {
11
+ const f = def?.settingsFile;
12
+ if (typeof f !== 'string' || !f || isAbsolute(f) || f.split(/[\\/]/).includes('..'))
13
+ return undefined;
14
+ return f;
15
+ }
16
+ async function realOrNull(path) {
17
+ try {
18
+ return await realpath(path);
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ }
24
+ export async function editSettings(rt, ref, opts = {}) {
25
+ const account = await rt.resolve(ref);
26
+ const def = rt.families.get(account.family);
27
+ const file = hostSettingsFile(def);
28
+ if (!file)
29
+ throw new UserError(`${account.ref}: ${def?.title ?? account.family} names no settings file; its folder is ${account.dir}`, { code: 'no-settings-file' });
30
+ const path = join(account.dir, file);
31
+ const real = await realOrNull(path);
32
+ if (!real) {
33
+ const link = await lstatOrNull(path);
34
+ throw new UserError(link?.isSymbolicLink()
35
+ ? `${path} links to a file that is not there; run \`sideby doctor ${account.ref}\` to see what it should point to`
36
+ : `${account.ref} has no ${file} yet (${path}); \`sideby doctor ${account.ref} --fix\` links the main account's when they share it, or create the file in your editor`, { code: 'settings-missing' });
37
+ }
38
+ const sharedWith = [];
39
+ for (const other of await rt.accounts()) {
40
+ if (other.family !== account.family || other.ref === account.ref)
41
+ continue;
42
+ if ((await realOrNull(join(other.dir, file))) === real)
43
+ sharedWith.push(other.ref);
44
+ }
45
+ const base = {
46
+ schemaVersion: 1,
47
+ ref: account.ref,
48
+ family: account.family,
49
+ file,
50
+ path,
51
+ ...(real !== path && (await lstatOrNull(path))?.isSymbolicLink() ? { target: real } : {}),
52
+ sharedWith,
53
+ };
54
+ if (opts.open === false)
55
+ return { ...base, opened: false };
56
+ return { ...base, opened: true, command: await openWithDefault(rt, real) };
57
+ }
58
+ /** Opens `file` with the system's default program; returns the command, or throws what to do instead. */
59
+ async function openWithDefault(rt, file) {
60
+ const deps = depsFor(rt);
61
+ const yourself = `open ${file} in your editor yourself`;
62
+ if (deps.platform === 'darwin') {
63
+ const r = await deps.exec('/usr/bin/open', ['-t', file]);
64
+ if (r.code !== 0)
65
+ throw new UserError(`macOS could not open the file; ${yourself}`, { code: 'open-failed' });
66
+ return ['/usr/bin/open', '-t', file];
67
+ }
68
+ if (deps.platform === 'linux' && deps.wslMount) {
69
+ const w = await deps.exec('wslpath', ['-w', file]);
70
+ const win = w.stdout.trim();
71
+ if (w.code !== 0 || !win)
72
+ throw new UserError(`wslpath could not name the file for Windows; ${yourself}`, { code: 'open-failed' });
73
+ // `start` hands the file to its Windows default program; explorer.exe opens one only now and then. cmd reads
74
+ // these characters itself, so a path with one is left to the user.
75
+ if (/[&|<>^%"]/.test(win))
76
+ throw new UserError(`the path has a character cmd.exe reads itself; ${yourself}`, {
77
+ code: 'open-failed',
78
+ });
79
+ const cmd = `${deps.wslMount}/c/Windows/System32/cmd.exe`;
80
+ const args = ['/c', 'start', '', win];
81
+ const r = await deps.exec(cmd, args);
82
+ if (r.code !== 0)
83
+ throw new UserError(`Windows could not open the file; ${yourself}`, { code: 'open-failed' });
84
+ return [cmd, ...args];
85
+ }
86
+ if (deps.platform === 'linux') {
87
+ const r = await deps.exec('xdg-open', [file]);
88
+ if (r.code !== 0)
89
+ throw new UserError(`xdg-open could not open the file; install xdg-utils, or ${yourself}`, {
90
+ code: 'open-failed',
91
+ });
92
+ return ['xdg-open', file];
93
+ }
94
+ throw new UserError(`sideby cannot open files on ${deps.platform} yet; ${yourself}`, {
95
+ code: 'open-failed',
96
+ });
97
+ }
@@ -1,10 +1,12 @@
1
- import type { ReadyFile } from './handoff-chain.ts';
1
+ import { type ReadyFile } from './handoff-chain.ts';
2
2
  /** Branch, uncommitted files and `git diff --stat`, as Markdown; '' outside a git work tree. Never commits or stashes. */
3
3
  export declare function gitSection(cwd: string): Promise<string>;
4
4
  export declare const ASSEMBLED_NOTE = "> Put together by sideby from the previous session\u2019s records, without a model; it may be incomplete. Check the repository before continuing.";
5
+ export declare const UNFINISHED_NOTE = "> The previous session did not finish the brief above. sideby added what it found in the session\u2019s records below.";
5
6
  /**
6
7
  * Writes the final Brief to `target` (mode 600) and says where it came from: the user's or the session's Brief
7
- * named in `ready`, the session's Brief already at `target`, else `assembled`, plus the repository state.
8
+ * named in `ready`, the session's Brief already at `target`, else `assembled`, plus the repository state. A session's
9
+ * Brief without `BRIEF_DONE` is kept, with `assembled` added under it (ADR-0032).
8
10
  */
9
11
  export declare function finishBrief(opts: {
10
12
  target: string;
@@ -4,6 +4,7 @@ import { execFile } from 'node:child_process';
4
4
  import { readFile } from 'node:fs/promises';
5
5
  import { promisify } from 'node:util';
6
6
  import { writeFileAtomic } from './fs-safe.js';
7
+ import { BRIEF_DONE } from './handoff-chain.js';
7
8
  const run = promisify(execFile);
8
9
  const GIT_TIMEOUT_MS = 3000;
9
10
  const MAX_STATUS_LINES = 50;
@@ -54,9 +55,11 @@ async function nonEmpty(path) {
54
55
  }
55
56
  }
56
57
  export const ASSEMBLED_NOTE = '> Put together by sideby from the previous session’s records, without a model; it may be incomplete. Check the repository before continuing.';
58
+ export const UNFINISHED_NOTE = '> The previous session did not finish the brief above. sideby added what it found in the session’s records below.';
57
59
  /**
58
60
  * Writes the final Brief to `target` (mode 600) and says where it came from: the user's or the session's Brief
59
- * named in `ready`, the session's Brief already at `target`, else `assembled`, plus the repository state.
61
+ * named in `ready`, the session's Brief already at `target`, else `assembled`, plus the repository state. A session's
62
+ * Brief without `BRIEF_DONE` is kept, with `assembled` added under it (ADR-0032).
60
63
  */
61
64
  export async function finishBrief(opts) {
62
65
  let body = await nonEmpty(opts.ready.brief);
@@ -69,6 +72,8 @@ export async function finishBrief(opts) {
69
72
  source = 'sideby';
70
73
  body = `${ASSEMBLED_NOTE}\n\n${opts.assembled ?? 'sideby could not read the previous session’s records.\n'}`;
71
74
  }
75
+ else if (source === 'agent' && !body.includes(BRIEF_DONE) && opts.assembled)
76
+ body = `${body.trimEnd()}\n\n${UNFINISHED_NOTE}\n\n${opts.assembled}`;
72
77
  const repo = await gitSection(opts.cwd);
73
78
  await writeFileAtomic(opts.target, `${body.trimEnd()}\n${repo ? `\n${repo}` : ''}`, 0o600);
74
79
  return { path: opts.target, source };
@@ -5,6 +5,15 @@ export declare const HANDOFF_ENV: {
5
5
  readonly dir: 'SIDEBY_HANDOFF_DIR';
6
6
  };
7
7
  export type HandoffTrigger = 'threshold' | 'limit' | 'manual';
8
+ /** The last line of a Brief the session finished (ADR-0032); a Brief without it is treated as unfinished. */
9
+ export declare const BRIEF_DONE = "<!-- handoff brief complete -->";
10
+ /** One Quota window as the hook read it: which window, how full, when it resets. */
11
+ export interface WindowReading {
12
+ /** `5h`, `7d` or `<n>m`, as `QuotaWindow.label`. */
13
+ label: string;
14
+ usedPercent: number;
15
+ resetsAt: string;
16
+ }
8
17
  /** What the parent decided the next Handoff would do, refreshed while the Host runs. */
9
18
  export interface PlanFile {
10
19
  /** The run this plan is for; a plan left by an earlier hop of the chain is ignored. */
@@ -18,6 +27,8 @@ export interface PlanFile {
18
27
  until?: string;
19
28
  prepareAt: number;
20
29
  threshold: number;
30
+ /** Each window hands over at its own pace (ADR-0032); missing (an older parent) means every window uses `threshold`. */
31
+ adaptive?: boolean;
21
32
  /** False when the session cannot write its Brief: no preparing step, and the threshold only ends the turn. */
22
33
  agentBrief?: boolean;
23
34
  /** The parent reads `to` from a manual request; a parent from before 0.9.3 does not write it and ignores `to`. */
@@ -30,6 +41,15 @@ export interface RunState {
30
41
  stopBlocked?: boolean;
31
42
  /** The user was told this run waits for a reset instead of moving on (ADR-0018). */
32
43
  waitNoticeSentAt?: string;
44
+ /** The window that reached its Hand-over Level, when the threshold message went out. */
45
+ thresholdWindow?: WindowReading;
46
+ /** Each window at the last `Stop`, by label: where the next turn's growth is measured from (ADR-0032). */
47
+ turnMark?: Record<string, {
48
+ usedPercent: number;
49
+ resetsAt: string;
50
+ }>;
51
+ /** Each window's growth in the run's last finished turns, newest last, by label. */
52
+ turnUse?: Record<string, number[]>;
33
53
  sessionId?: string;
34
54
  transcriptPath?: string;
35
55
  }
@@ -41,6 +61,8 @@ export interface ReadyFile {
41
61
  /** The Brief file, when the session or the user wrote one. */
42
62
  brief?: string;
43
63
  briefSource?: 'agent' | 'user';
64
+ /** The window that started a `threshold` or `limit` Handoff. */
65
+ window?: WindowReading;
44
66
  /** `sideby handoff ready --to`: the Account ref to hand over to. */
45
67
  to?: string;
46
68
  sessionId?: string;
@@ -59,6 +81,8 @@ export interface ChainHop {
59
81
  trigger?: HandoffTrigger;
60
82
  briefSource?: 'agent' | 'sideby' | 'user';
61
83
  brief?: string;
84
+ /** The window that started the Handoff, when the Quota did. */
85
+ window?: WindowReading;
62
86
  }
63
87
  export interface ChainFile {
64
88
  hops: ChainHop[];
@@ -13,6 +13,8 @@ export const HANDOFF_ENV = {
13
13
  family: 'SIDEBY_HANDOFF_FAMILY',
14
14
  dir: 'SIDEBY_HANDOFF_DIR',
15
15
  };
16
+ /** The last line of a Brief the session finished (ADR-0032); a Brief without it is treated as unfinished. */
17
+ export const BRIEF_DONE = '<!-- handoff brief complete -->';
16
18
  export const FILES = {
17
19
  plan: 'plan.json',
18
20
  ready: 'ready.json',
@@ -21,10 +21,11 @@ export declare function hookEntryWorks(env: Env): Promise<boolean>;
21
21
  * Runs `ref` with Auto Handoff when the config, the Family, the run and the terminal allow it, and returns the exit
22
22
  * code of the last Host; null when Auto Handoff does not apply and the caller should run the Host as usual.
23
23
  */
24
- export declare function runWithHandoff(rt: Runtime, ref: string, userArgs: readonly string[], io: HandoffIo,
25
- /** For tests: how long the Host gets to exit after SIGTERM. */
26
- opts?: {
24
+ export declare function runWithHandoff(rt: Runtime, ref: string, userArgs: readonly string[], io: HandoffIo, opts?: {
25
+ /** For tests: how long the Host gets to exit after SIGTERM. */
27
26
  exitGraceMs?: number;
27
+ /** An AI Task (ADR-0031): every Account it hands over to starts without permission bypasses too. */
28
+ aiTask?: boolean;
28
29
  }): Promise<number | null>;
29
30
  /**
30
31
  * For `sideby handoff ready`: where a Handoff from the session running under `env` would go now, using the chain's
@@ -6,7 +6,7 @@ import { watch } from 'node:fs';
6
6
  import { rm } from 'node:fs/promises';
7
7
  import { join } from 'node:path';
8
8
  import { HOOK_FAMILIES } from '../handoff/hook.js';
9
- import { firstPrompt } from '../handoff/messages.js';
9
+ import { firstPrompt, windowText } from '../handoff/messages.js';
10
10
  import { aliasArgs } from './config.js';
11
11
  import { UserError } from './errors.js';
12
12
  import { finishBrief } from './handoff-brief.js';
@@ -147,14 +147,13 @@ async function decide(rt, account, used, to, manual = false) {
147
147
  * Runs `ref` with Auto Handoff when the config, the Family, the run and the terminal allow it, and returns the exit
148
148
  * code of the last Host; null when Auto Handoff does not apply and the caller should run the Host as usual.
149
149
  */
150
- export async function runWithHandoff(rt, ref, userArgs, io,
151
- /** For tests: how long the Host gets to exit after SIGTERM. */
152
- opts = {}) {
150
+ export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
153
151
  const grace = opts.exitGraceMs ?? EXIT_GRACE_MS;
154
152
  const settings = rt.handoffSettings();
155
153
  if (!settings.auto || !io.stdin.isTTY)
156
154
  return null;
157
- const firstLaunch = await rt.prepareLaunch(ref, userArgs, 'run');
155
+ const launchOpts = opts.aiTask ? { aiTask: true } : {};
156
+ const firstLaunch = await rt.prepareLaunch(ref, userArgs, 'run', launchOpts);
158
157
  const firstHandoff = firstLaunch.family.handoff;
159
158
  // Only built-in Families have a hook reader (spec §3.17); a Plugin Family can only take over.
160
159
  if (!firstHandoff?.starts.length || !HOOK_FAMILIES.includes(firstLaunch.family.id))
@@ -183,7 +182,7 @@ opts = {}) {
183
182
  let hop = { ref, args: [...aliasArgs(own), ...userArgs] };
184
183
  let n = 1;
185
184
  for (;;) {
186
- const launch = n === 1 ? firstLaunch : await rt.prepareLaunch(hop.ref, hop.args, 'run');
185
+ const launch = n === 1 ? firstLaunch : await rt.prepareLaunch(hop.ref, hop.args, 'run', launchOpts);
187
186
  const account = launch.account;
188
187
  const h = launch.family.handoff;
189
188
  if (!h)
@@ -236,6 +235,7 @@ opts = {}) {
236
235
  ...(d.kind === 'wait' ? { until: d.until } : {}),
237
236
  prepareAt: settings.prepareAt,
238
237
  threshold: settings.threshold,
238
+ adaptive: settings.adaptive,
239
239
  ...(elig.agentBrief === false ? { agentBrief: false } : {}),
240
240
  acceptsTo: true,
241
241
  };
@@ -316,11 +316,16 @@ opts = {}) {
316
316
  cwd: process.cwd(),
317
317
  });
318
318
  const last = hops.hops[hops.hops.length - 1];
319
- Object.assign(last, { trigger: ready.trigger, briefSource: done.source, brief: done.path });
319
+ Object.assign(last, {
320
+ trigger: ready.trigger,
321
+ briefSource: done.source,
322
+ brief: done.path,
323
+ ...(ready.window ? { window: ready.window } : {}),
324
+ });
320
325
  await writeJsonFile(join(dir, FILES.chain), hops);
321
326
  await rm(join(dir, FILES.ready), { force: true });
322
327
  await rm(join(dir, FILES.request), { force: true });
323
- io.err(`sideby: ${account.ref} saved its session and is handing over because ${WHY[ready.trigger]}; next is ${decision.ref}${skippedText(decision)}. Brief: ${done.path}`);
328
+ io.err(`sideby: ${account.ref} saved its session and is handing over because ${WHY[ready.trigger]}${ready.window ? ` (${windowText(ready.window)})` : ''}; next is ${decision.ref}${skippedText(decision)}. Brief: ${done.path}`);
324
329
  if (settings.countdownSeconds > 0 &&
325
330
  (await countdown(io, settings.countdownSeconds, decision.ref, account.ref))) {
326
331
  io.err(`sideby: staying in ${account.ref}`);
@@ -329,7 +334,7 @@ opts = {}) {
329
334
  return ended.code;
330
335
  }
331
336
  const backArgs = [...h.continueArgs(hop.args), ...h.resumeArgs(ready.sessionId)];
332
- const back = await rt.prepareLaunch(account.ref, backArgs, 'run');
337
+ const back = await rt.prepareLaunch(account.ref, backArgs, 'run', launchOpts);
333
338
  // The same per-Account arguments as before (Grok's leader socket), without sideby's hooks.
334
339
  const backElig = await h.eligibility(back.args, account, back.env);
335
340
  return runHost({ ...back, args: beforeDashes(back.args, backElig.args ?? []) });
@@ -45,6 +45,8 @@ export interface LaunchCommandOptions {
45
45
  accountArgs: readonly string[];
46
46
  userArgs: readonly string[];
47
47
  command: 'run' | 'login';
48
+ /** An AI Task (spec §3.28): the Family's `aiTaskArgs` removes every permission bypass (ADR-0031). */
49
+ aiTask?: boolean;
48
50
  /** Config `accountTitle`: set the terminal title to `[<label>]` and keep the Host from replacing it. */
49
51
  title?: boolean;
50
52
  }