@andorra-labs/code 0.1.14 → 0.1.15

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 (107) hide show
  1. package/dist/src/acp-agent.d.ts +54 -0
  2. package/dist/src/acp-agent.js +991 -0
  3. package/dist/src/agent-execution.js +4 -0
  4. package/dist/src/agent-mcp-catalog.js +2 -0
  5. package/dist/src/agent-mcp.d.ts +2 -0
  6. package/dist/src/agent-mcp.js +84 -2
  7. package/dist/src/andorra/entry.js +21 -3
  8. package/dist/src/andorra/hosted.d.ts +3 -0
  9. package/dist/src/andorra/hosted.js +5 -1
  10. package/dist/src/andorra/notices.d.ts +10 -1
  11. package/dist/src/andorra/notices.js +25 -2
  12. package/dist/src/andorra/terminal.d.ts +2 -0
  13. package/dist/src/andorra/terminal.js +2 -2
  14. package/dist/src/app-server/protocol.d.ts +6 -2
  15. package/dist/src/app-server/protocol.js +1 -1
  16. package/dist/src/app-server/workspace.d.ts +1 -0
  17. package/dist/src/app-server/workspace.js +141 -10
  18. package/dist/src/app-server.d.ts +8 -0
  19. package/dist/src/app-server.js +87 -41
  20. package/dist/src/auth/AuthManager.js +4 -4
  21. package/dist/src/browser-bridge.d.ts +1 -0
  22. package/dist/src/browser-bridge.js +5 -2
  23. package/dist/src/browser-external-app.d.ts +27 -0
  24. package/dist/src/browser-external-app.js +60 -0
  25. package/dist/src/browser-panel-tool.d.ts +6 -0
  26. package/dist/src/browser-panel-tool.js +36 -0
  27. package/dist/src/browser-server.d.ts +5 -0
  28. package/dist/src/browser-server.js +27 -3
  29. package/dist/src/browser-view.d.ts +16 -0
  30. package/dist/src/browser-view.js +60 -2
  31. package/dist/src/bug-report.d.ts +81 -0
  32. package/dist/src/bug-report.js +235 -0
  33. package/dist/src/claude-provider.d.ts +2 -1
  34. package/dist/src/claude-provider.js +10 -8
  35. package/dist/src/cli-sign-in.d.ts +3 -1
  36. package/dist/src/cli-sign-in.js +4 -1
  37. package/dist/src/cli.js +164 -34
  38. package/dist/src/coding-tools.js +7 -7
  39. package/dist/src/command-screens.d.ts +9 -2
  40. package/dist/src/command-screens.js +161 -94
  41. package/dist/src/commands.d.ts +1 -1
  42. package/dist/src/commands.js +1 -0
  43. package/dist/src/completion-gates.d.ts +22 -0
  44. package/dist/src/completion-gates.js +11 -0
  45. package/dist/src/config.d.ts +5 -0
  46. package/dist/src/config.js +48 -0
  47. package/dist/src/google-provider.d.ts +31 -0
  48. package/dist/src/google-provider.js +153 -0
  49. package/dist/src/graph-health.js +1 -1
  50. package/dist/src/graph-manager-chat.js +6 -1
  51. package/dist/src/graph-sync.d.ts +1 -0
  52. package/dist/src/graph-sync.js +93 -34
  53. package/dist/src/graph-tool.d.ts +2 -0
  54. package/dist/src/graph-tool.js +2 -2
  55. package/dist/src/graph-ui/app.js +67 -8
  56. package/dist/src/graph-ui/edge-router.js +121 -53
  57. package/dist/src/graph-visibility.d.ts +31 -0
  58. package/dist/src/graph-visibility.js +102 -0
  59. package/dist/src/live-model.d.ts +24 -0
  60. package/dist/src/live-model.js +37 -0
  61. package/dist/src/managed-sign-in.d.ts +1 -0
  62. package/dist/src/managed-sign-in.js +13 -0
  63. package/dist/src/membership-errors.d.ts +2 -0
  64. package/dist/src/membership-errors.js +5 -1
  65. package/dist/src/membership.d.ts +3 -0
  66. package/dist/src/membership.js +19 -2
  67. package/dist/src/model-health-cache.js +1 -1
  68. package/dist/src/model-metadata.js +8 -1
  69. package/dist/src/paged-transcript.d.ts +2 -0
  70. package/dist/src/paged-transcript.js +16 -0
  71. package/dist/src/provider-connection.js +17 -0
  72. package/dist/src/provider-engine.d.ts +5 -0
  73. package/dist/src/provider-engine.js +3 -3
  74. package/dist/src/provider-import.js +3 -1
  75. package/dist/src/provider-settings.js +14 -2
  76. package/dist/src/providers.d.ts +16 -2
  77. package/dist/src/providers.js +36 -12
  78. package/dist/src/react-runtime.js +21 -5
  79. package/dist/src/read-document-tool.d.ts +2 -0
  80. package/dist/src/read-document-tool.js +6 -6
  81. package/dist/src/remote/engine-pool.js +26 -2
  82. package/dist/src/runtime-environment.d.ts +1 -0
  83. package/dist/src/runtime-environment.js +13 -0
  84. package/dist/src/save-lock.js +14 -7
  85. package/dist/src/session-title.d.ts +3 -0
  86. package/dist/src/session-title.js +5 -2
  87. package/dist/src/sign-in-detection.d.ts +1 -1
  88. package/dist/src/sign-in-detection.js +10 -3
  89. package/dist/src/sign-in-offer.js +1 -1
  90. package/dist/src/skill-commands.js +1 -1
  91. package/dist/src/skills/bundled/bug-report/SKILL.md +80 -0
  92. package/dist/src/skills/bundled/graph-manager/SKILL.md +9 -1
  93. package/dist/src/skills/bundled/graph-manager/errors.md +1 -0
  94. package/dist/src/skills/bundled/provenance.json +7 -2
  95. package/dist/src/skills/runtime-skills.js +1 -0
  96. package/dist/src/telemetry/uploader.d.ts +7 -1
  97. package/dist/src/telemetry/uploader.js +11 -2
  98. package/dist/src/terminal-links.d.ts +16 -0
  99. package/dist/src/terminal-links.js +113 -0
  100. package/dist/src/terminal-ui.d.ts +8 -1
  101. package/dist/src/terminal-ui.js +40 -14
  102. package/dist/src/tool-catalog.js +1 -1
  103. package/dist/src/trajectory.js +6 -1
  104. package/dist/src/transcript.d.ts +2 -0
  105. package/dist/src/transcript.js +2 -1
  106. package/dist/src/types.d.ts +2 -0
  107. package/package.json +2 -1
@@ -3,41 +3,49 @@ globalThis.AndorraEdgeRouter = (() => {
3
3
  const clear = (a, b, boxes) => !boxes.some(r => a.x === b.x
4
4
  ? a.x > r.x && a.x < r.x + r.width && Math.max(a.y,b.y) > r.y && Math.min(a.y,b.y) < r.y+r.height
5
5
  : a.y > r.y && a.y < r.y+r.height && Math.max(a.x,b.x) > r.x && Math.min(a.x,b.x) < r.x+r.width);
6
- const GAP = 8;
7
- const NUDGE = 10, NUDGES = 4;
8
- function collinear(a, b, c, d) {
9
- const shared = (p, q, r, s) => Math.min(Math.max(p,q),Math.max(r,s)) - Math.max(Math.min(p,q),Math.min(r,s)) > 0;
10
- if (a.y === b.y && c.y === d.y && a.x !== b.x && c.x !== d.x) return Math.abs(a.y-c.y) < GAP && shared(a.x,b.x,c.x,d.x);
11
- if (a.x === b.x && c.x === d.x && a.y !== b.y && c.y !== d.y) return Math.abs(a.x-c.x) < GAP && shared(a.y,b.y,c.y,d.y);
12
- return false;
13
- }
14
- function lineIndex(occupied) {
15
- const rows = new Map(), columns = new Map();
16
- for (const route of occupied) for (let i = 1; i < route.length; i++) {
6
+ const GAP = 16;
7
+ const NUDGE = 16, NUDGES = 5, ROWS = 12;
8
+ function addLines(index, route) {
9
+ const { rows, columns } = index;
10
+ index.empty = false;
11
+ for (let i = 1; i < route.length; i++) {
17
12
  const a = route[i-1], b = route[i];
18
13
  if (a.x === b.x && a.y === b.y) continue;
19
- const table = a.y === b.y ? rows : columns, line = a.y === b.y ? a.y : a.x, bucket = Math.floor(line / GAP);
14
+ const flat = a.y === b.y, table = flat ? rows : columns, line = flat ? a.y : a.x, bucket = Math.floor(line / GAP);
20
15
  if (!table.has(bucket)) table.set(bucket, []);
21
- table.get(bucket).push({ a, b, final: i === route.length - 1, end: route.at(-1) });
16
+ table.get(bucket).push({ line, low: flat ? Math.min(a.x,b.x) : Math.min(a.y,b.y), high: flat ? Math.max(a.x,b.x) : Math.max(a.y,b.y), final: i === route.length - 1, end: route.at(-1) });
22
17
  }
23
- return { rows, columns, empty: !occupied.length };
18
+ }
19
+ function lineIndex(occupied) {
20
+ const index = { rows: new Map(), columns: new Map(), empty: true };
21
+ for (const route of occupied) addLines(index, route);
22
+ return index;
24
23
  }
25
24
  function along(index, a, b, final = false, end = undefined) {
26
- if (index.empty || (a.x === b.x && a.y === b.y)) return false;
27
- const table = a.y === b.y ? index.rows : index.columns, bucket = Math.floor((a.y === b.y ? a.y : a.x) / GAP);
28
- for (let near = bucket - 1; near <= bucket + 1; near++) for (const other of table.get(near) || []) {
29
- if (final && other.final && end && other.end.x === end.x && other.end.y === end.y) continue;
30
- if (collinear(a, b, other.a, other.b)) return true;
25
+ if (index.empty || (a.x === b.x && a.y === b.y)) return 0;
26
+ const flat = a.y === b.y, table = flat ? index.rows : index.columns, line = flat ? a.y : a.x, bucket = Math.floor(line / GAP);
27
+ const low = flat ? Math.min(a.x,b.x) : Math.min(a.y,b.y), high = flat ? Math.max(a.x,b.x) : Math.max(a.y,b.y);
28
+ let total = 0;
29
+ for (let near = bucket - 1; near <= bucket + 1; near++) {
30
+ const others = table.get(near);
31
+ if (others) for (const other of others) {
32
+ const apart = Math.abs(line - other.line);
33
+ if (apart >= GAP) continue;
34
+ const run = Math.min(high, other.high) - Math.max(low, other.low);
35
+ if (run <= 0 || (final && other.final && end && other.end.x === end.x && other.end.y === end.y)) continue;
36
+ total += run * (GAP - apart);
37
+ }
31
38
  }
32
- return false;
39
+ return total;
33
40
  }
34
- function crowdsIndex(points, index) {
35
- if (index.empty) return false;
41
+ function crowdsIndex(points, index, limit = Infinity) {
42
+ if (index.empty) return 0;
36
43
  const end = points.at(-1);
37
- for (let i = 1; i < points.length; i++) if (along(index, points[i-1], points[i], i === points.length - 1, end)) return true;
38
- return false;
44
+ let total = 0;
45
+ for (let i = 1; i < points.length && total < limit; i++) total += along(index, points[i-1], points[i], i === points.length - 1, end);
46
+ return total;
39
47
  }
40
- const crowds = (points, occupied) => crowdsIndex(points, lineIndex(occupied));
48
+ const crowds = (points, occupied) => crowdsIndex(points, lineIndex(occupied)) > 0;
41
49
  function routeEdge(source, target, rectangles, lane = 0, padding = 12, occupied = []) {
42
50
  const escape = padding + 2, start = {x:source.x+escape,y:source.y}, end = {x:target.x-escape,y:target.y};
43
51
  const boxes = rectangles.map(r => ({x:r.x-padding,y:r.y-padding,width:r.width+padding*2,height:r.height+padding*2}));
@@ -50,45 +58,59 @@ globalThis.AndorraEdgeRouter = (() => {
50
58
  };
51
59
  const finish = points => simplify([source,...points,target]);
52
60
  const clearOfCards = points => points.every((p,i)=>!i||clear(points[i-1],p,boxes));
53
- const index = lineIndex(occupied);
54
- const verdict = points => !clearOfCards(points) ? 'blocked' : crowdsIndex(finish(points), index) ? 'crowded' : 'ok';
61
+ const index = Array.isArray(occupied) ? lineIndex(occupied) : occupied;
55
62
  const rowNudges = (y, k) => (y <= Math.min(start.y,end.y) ? [-1] : y >= Math.max(start.y,end.y) ? [1] : [1,-1]).map(way=>y+way*NUDGE*k);
56
- let crowdedFallback;
63
+ let leastCrowded;
64
+ const attempt = (points, nudged = false) => {
65
+ if (!nudged && !clearOfCards(points)) return 'blocked';
66
+ const route = finish(points), score = crowdsIndex(route, index, leastCrowded?.score);
67
+ if (nudged && ((leastCrowded && score >= leastCrowded.score) || !clearOfCards(points))) return 'blocked';
68
+ if (!score) return route;
69
+ if (!leastCrowded || score < leastCrowded.score) leastCrowded = { route, score };
70
+ return 'crowded';
71
+ };
57
72
  const corridor = (build, row) => {
58
- const base = build(row, 0), first = verdict(base);
59
- if (first === 'ok') return finish(base);
73
+ const first = attempt(build(row, 0));
60
74
  if (first === 'blocked') return undefined;
75
+ if (first !== 'crowded') return first;
61
76
  for (let k = 1; k <= NUDGES; k++) {
62
77
  for (const points of [...rowNudges(row,k).map(y=>build(y,0)), build(row,NUDGE*k), ...rowNudges(row,k).map(y=>build(y,NUDGE*k))]) {
63
- if (verdict(points) === 'ok') return finish(points);
78
+ const found = attempt(points, true);
79
+ if (typeof found !== 'string') return found;
64
80
  }
65
81
  }
66
- crowdedFallback ??= finish(base);
67
82
  return undefined;
68
83
  };
69
84
  const middleX=(start.x+end.x)/2, middleY=(start.y+end.y)/2;
70
85
  const rowsByDistance=[...new Set([middleY,...ys])].sort((a,b)=>Math.abs(a-start.y)+Math.abs(a-end.y)-Math.abs(b-start.y)-Math.abs(b-end.y));
71
- const rowCandidates=rowsByDistance.slice(0,12);
72
- if (target.x <= source.x) {
73
- const offset=(lane+1)*8;
74
- for (const y of rowCandidates) {
75
- const found=corridor((row,dx)=>{const sx=start.x+offset+dx,tx=end.x-offset-dx;return [start,{x:sx,y:start.y},{x:sx,y:row},{x:tx,y:row},{x:tx,y:end.y},end];},y);
76
- if(found)return found;
77
- }
78
- }
79
- for(const [build,row] of [
80
- [(_,dx)=>[start,{x:middleX+dx,y:start.y},{x:middleX+dx,y:end.y},end],middleY],
81
- [(row)=>[start,{x:start.x,y:row},{x:end.x,y:row},end],middleY],
82
- ...rowCandidates.map(y=>[(row)=>[start,{x:start.x,y:row},{x:end.x,y:row},end],y]),
83
- ]){const found=corridor(build,row);if(found)return found;}
84
86
  const right=xs.filter(x=>x>=start.x&&clear(start,{x,y:start.y},boxes)).sort((a,b)=>a-b);
85
87
  const left=xs.filter(x=>x<=end.x&&clear({x,y:end.y},end,boxes)).sort((a,b)=>b-a);
86
- for(const y of rowCandidates){
87
- const sx=right.find(x=>clear({x,y:start.y},{x,y},boxes));
88
- const tx=left.find(x=>clear({x,y:end.y},{x,y},boxes));
89
- if(sx!==undefined&&tx!==undefined){const found=corridor((row,dx)=>[start,{x:sx+dx,y:start.y},{x:sx+dx,y:row},{x:tx-dx,y:row},{x:tx-dx,y:end.y},end],y);if(found)return found;}
88
+ const search = (rows, direct) => {
89
+ if (target.x <= source.x) {
90
+ const offset=(lane+1)*8;
91
+ for (const y of rows) {
92
+ const found=corridor((row,dx)=>{const sx=start.x+offset+dx,tx=end.x-offset-dx;return [start,{x:sx,y:start.y},{x:sx,y:row},{x:tx,y:row},{x:tx,y:end.y},end];},y);
93
+ if(found)return found;
94
+ }
95
+ }
96
+ for(const [build,row] of [
97
+ ...(direct?[[(_,dx)=>[start,{x:middleX+dx,y:start.y},{x:middleX+dx,y:end.y},end],middleY],
98
+ [(row)=>[start,{x:start.x,y:row},{x:end.x,y:row},end],middleY]]:[]),
99
+ ...rows.map(y=>[(row)=>[start,{x:start.x,y:row},{x:end.x,y:row},end],y]),
100
+ ]){const found=corridor(build,row);if(found)return found;}
101
+ for(const y of rows){
102
+ const sx=right.find(x=>clear({x,y:start.y},{x,y},boxes));
103
+ const tx=left.find(x=>clear({x,y:end.y},{x,y},boxes));
104
+ if(sx!==undefined&&tx!==undefined){const found=corridor((row,dx)=>[start,{x:sx+dx,y:start.y},{x:sx+dx,y:row},{x:tx-dx,y:row},{x:tx-dx,y:end.y},end],y);if(found)return found;}
105
+ }
106
+ return undefined;
107
+ };
108
+ const near=search(rowsByDistance.slice(0,ROWS),true);
109
+ if(near)return near;
110
+ if(leastCrowded){
111
+ const wider=search(rowsByDistance.slice(ROWS,ROWS*2),false);
112
+ return wider||leastCrowded.route;
90
113
  }
91
- if(crowdedFallback)return crowdedFallback;
92
114
  const key=(x,y,dir)=>`${x},${y},${dir}`, heuristic=(x,y)=>Math.abs(xs[x]-end.x)+Math.abs(ys[y]-end.y);
93
115
  const heap=[];
94
116
  function push(item){heap.push(item);let i=heap.length-1;while(i){const p=(i-1)>>1;if(heap[p].score<=item.score)break;heap[i]=heap[p];i=p;}heap[i]=item;}
@@ -117,11 +139,11 @@ globalThis.AndorraEdgeRouter = (() => {
117
139
  return simplify(points);
118
140
  }
119
141
  function routeEdges(entries, rectangles) {
120
- const occupied=[];
142
+ const occupied=lineIndex([]);
121
143
  return entries.map((entry,index)=>{
122
144
  if(!entry)return null;
123
145
  const points=routeEdge(entry.source,entry.target,rectangles,index,undefined,occupied);
124
- occupied.push(points);
146
+ addLines(occupied,points);
125
147
  return points;
126
148
  });
127
149
  }
@@ -152,5 +174,51 @@ globalThis.AndorraEdgeRouter = (() => {
152
174
  }
153
175
  return best||{x:(points[0].x+points.at(-1).x)/2,y:(points[0].y+points.at(-1).y)/2};
154
176
  }
155
- return {routeEdge,routeEdges,crowds,path,roundedPath,labelPoint,clear};
177
+ const LABEL_MARGIN = 4, LABEL_STOPS = [0.5, 0.3, 0.7, 0.15, 0.85];
178
+ function placeLabels(routes, widths, height, rectangles = []) {
179
+ const placed = [], touches = (a, b, margin) => a.x - margin < b.x + b.width && b.x - margin < a.x + a.width && a.y - margin < b.y + b.height && b.y - margin < a.y + a.height;
180
+ const segments = routes.map(points => {
181
+ const list = [];
182
+ if (points) for (let i = 1; i < points.length; i++) {
183
+ const a = points[i-1], b = points[i];
184
+ list.push({ x: Math.min(a.x,b.x), y: Math.min(a.y,b.y), width: Math.abs(b.x-a.x), height: Math.abs(b.y-a.y) });
185
+ }
186
+ return list;
187
+ });
188
+ return routes.map((points, index) => {
189
+ const width = widths[index];
190
+ if (!points || !width) return null;
191
+ const candidates = [], first = labelPoint(points);
192
+ const runs = [];
193
+ for (let i = 1; i < points.length; i++) {
194
+ const a = points[i-1], b = points[i], flat = a.y === b.y, length = flat ? Math.abs(b.x-a.x) : Math.abs(b.y-a.y);
195
+ if (length) runs.push({ a, b, flat, length, room: length - (flat ? width : height) - LABEL_MARGIN * 2 });
196
+ }
197
+ runs.sort((p, q) => Number(q.flat) - Number(p.flat) || q.length - p.length);
198
+ runs.forEach((run, rank) => {
199
+ for (const [order, stop] of (run.room > 0 ? LABEL_STOPS : [0.5]).entries()) {
200
+ const half = (run.flat ? width : height) / 2 + LABEL_MARGIN, low = Math.min(run.flat ? run.a.x : run.a.y, run.flat ? run.b.x : run.b.y);
201
+ const along = run.room > 0 ? Math.min(Math.max(low + run.length * stop, low + half), low + run.length - half) : low + run.length / 2;
202
+ const at = run.flat ? { x: along, y: run.a.y } : { x: run.a.x, y: along };
203
+ candidates.push({ at, cost: rank * 3 + order + (run.flat ? 0 : 4) + (run.room > 0 ? 0 : 6) });
204
+ }
205
+ });
206
+ if (!candidates.length) candidates.push({ at: first, cost: 0 });
207
+ let best;
208
+ for (const candidate of candidates) {
209
+ const box = { x: candidate.at.x - width / 2, y: candidate.at.y - height / 2, width, height };
210
+ let cost = candidate.cost;
211
+ for (const other of placed) if (touches(box, other, LABEL_MARGIN)) cost += 1000;
212
+ for (const card of rectangles) if (touches(box, card, 2)) cost += 1000;
213
+ if (!best || cost < best.cost) {
214
+ for (let other = 0; other < segments.length && cost < (best?.cost ?? Infinity); other++) if (other !== index) for (const segment of segments[other]) if (touches(box, segment, 2)) cost += 40;
215
+ if (!best || cost < best.cost) best = { cost, at: candidate.at, box };
216
+ }
217
+ if (best.cost === candidate.cost && best.at === candidate.at) break;
218
+ }
219
+ placed.push(best.box);
220
+ return best.at;
221
+ });
222
+ }
223
+ return {routeEdge,routeEdges,crowds,path,roundedPath,labelPoint,placeLabels,clear};
156
224
  })();
@@ -0,0 +1,31 @@
1
+ import { type Config } from './config.js';
2
+ /**
3
+ * Which projects list a graph, per signed-in account. A graph with no entry is listed in every project; an entry
4
+ * lists it only in the project paths it names. The engine owns this so the graph manager's tool can set it and the
5
+ * desktop, the TUI and the MCP server all read the same answer. It lives in config.json beside graphSelections and
6
+ * changes under the same cross-process config lock.
7
+ *
8
+ * graphVisibilityChosen lists, per account, the graphs whose visibility was chosen through the engine. A choice of
9
+ * every project leaves no entry in graphVisibility, so this is what tells it apart from a graph never configured:
10
+ * an older client's copy must not bring back a restriction the user lifted through the engine.
11
+ */
12
+ export type AccountGraphVisibility = Record<string, string[]>;
13
+ /** Called after this process changes visibility, so a host can tell its clients to reload. */
14
+ export declare function onGraphVisibilityChange(listener: () => void): () => void;
15
+ export declare function graphVisibilityFor(config: Pick<Config, 'graphVisibility'>, subject: string | undefined): AccountGraphVisibility;
16
+ /**
17
+ * Sets the projects that list `graphId` for `subject`, or lists it everywhere when `paths` is undefined.
18
+ * Returns the account's whole visibility after the change.
19
+ */
20
+ export declare function setGraphVisibility(directory: string, subject: string, graphId: string, paths: readonly string[] | undefined): Promise<AccountGraphVisibility>;
21
+ /**
22
+ * Brings in visibility a client kept before the engine owned it. Only graphs whose visibility was never chosen
23
+ * through the engine are taken, so a choice made there, "every project" included, is never overwritten by an older copy.
24
+ */
25
+ export declare function importGraphVisibility(directory: string, subject: string, entries: AccountGraphVisibility): Promise<AccountGraphVisibility>;
26
+ /**
27
+ * Moves grants from one project path to another for every account. A rename moves the grant; a merge narrows what is
28
+ * visible instead, because a graph shared only with the merged-away project is not the survivor's to inherit.
29
+ */
30
+ export declare function relinkGraphVisibility(config: Config, from: string, to: string, merged: boolean): Config;
31
+ export declare function announceGraphVisibilityChange(): void;
@@ -0,0 +1,102 @@
1
+ import { changeConfigFile, MAX_GRAPH_VISIBILITY_PROJECTS } from './config.js';
2
+ const listeners = new Set();
3
+ /** Called after this process changes visibility, so a host can tell its clients to reload. */
4
+ export function onGraphVisibilityChange(listener) {
5
+ listeners.add(listener);
6
+ return () => { listeners.delete(listener); };
7
+ }
8
+ function announce() {
9
+ for (const listener of listeners) {
10
+ try {
11
+ listener();
12
+ }
13
+ catch { /* a listener's failure is its own */ }
14
+ }
15
+ }
16
+ export function graphVisibilityFor(config, subject) {
17
+ if (!subject)
18
+ return {};
19
+ const account = config.graphVisibility?.[subject];
20
+ return account ? Object.fromEntries(Object.entries(account).map(([graph, paths]) => [graph, [...paths]])) : {};
21
+ }
22
+ function uniquePaths(paths) {
23
+ const unique = [...new Set(paths)];
24
+ if (unique.length > MAX_GRAPH_VISIBILITY_PROJECTS)
25
+ throw new Error(`A graph can be limited to at most ${MAX_GRAPH_VISIBILITY_PROJECTS} projects.`);
26
+ return unique;
27
+ }
28
+ function withAccount(config, subject, account) {
29
+ const all = { ...config.graphVisibility };
30
+ if (Object.keys(account).length === 0)
31
+ delete all[subject];
32
+ else
33
+ all[subject] = account;
34
+ const { graphVisibility: _previous, ...rest } = config;
35
+ return Object.keys(all).length === 0 ? rest : { ...rest, graphVisibility: all };
36
+ }
37
+ /**
38
+ * Sets the projects that list `graphId` for `subject`, or lists it everywhere when `paths` is undefined.
39
+ * Returns the account's whole visibility after the change.
40
+ */
41
+ export async function setGraphVisibility(directory, subject, graphId, paths) {
42
+ if (graphId === 'default')
43
+ throw new Error('The bundled Default graph is always listed in every project.');
44
+ const wanted = paths === undefined ? undefined : uniquePaths(paths);
45
+ let changed = false;
46
+ const saved = await changeConfigFile(directory, current => {
47
+ const account = graphVisibilityFor(current, subject);
48
+ const before = JSON.stringify(account[graphId] ?? null);
49
+ if (wanted === undefined)
50
+ delete account[graphId];
51
+ else
52
+ account[graphId] = wanted;
53
+ changed = JSON.stringify(account[graphId] ?? null) !== before;
54
+ const chosen = current.graphVisibilityChosen?.[subject] ?? [];
55
+ if (!changed && chosen.includes(graphId))
56
+ return current;
57
+ const next = changed ? withAccount(current, subject, account) : current;
58
+ return chosen.includes(graphId) ? next : { ...next, graphVisibilityChosen: { ...current.graphVisibilityChosen, [subject]: [...chosen, graphId] } };
59
+ });
60
+ if (changed)
61
+ announce();
62
+ return graphVisibilityFor(saved, subject);
63
+ }
64
+ /**
65
+ * Brings in visibility a client kept before the engine owned it. Only graphs whose visibility was never chosen
66
+ * through the engine are taken, so a choice made there, "every project" included, is never overwritten by an older copy.
67
+ */
68
+ export async function importGraphVisibility(directory, subject, entries) {
69
+ let changed = false;
70
+ const saved = await changeConfigFile(directory, current => {
71
+ const account = graphVisibilityFor(current, subject);
72
+ const chosen = new Set(current.graphVisibilityChosen?.[subject] ?? []);
73
+ for (const [graph, paths] of Object.entries(entries)) {
74
+ if (graph === 'default' || Object.hasOwn(account, graph) || chosen.has(graph))
75
+ continue;
76
+ account[graph] = uniquePaths(paths);
77
+ changed = true;
78
+ }
79
+ return changed ? withAccount(current, subject, account) : current;
80
+ });
81
+ if (changed)
82
+ announce();
83
+ return graphVisibilityFor(saved, subject);
84
+ }
85
+ /**
86
+ * Moves grants from one project path to another for every account. A rename moves the grant; a merge narrows what is
87
+ * visible instead, because a graph shared only with the merged-away project is not the survivor's to inherit.
88
+ */
89
+ export function relinkGraphVisibility(config, from, to, merged) {
90
+ if (!config.graphVisibility)
91
+ return config;
92
+ let changed = false;
93
+ const accounts = Object.fromEntries(Object.entries(config.graphVisibility).map(([subject, graphs]) => [subject,
94
+ Object.fromEntries(Object.entries(graphs).map(([graph, paths]) => {
95
+ if (!paths.includes(from))
96
+ return [graph, paths];
97
+ changed = true;
98
+ return [graph, merged ? paths.filter(path => path !== from) : [...new Set(paths.map(path => (path === from ? to : path)))]];
99
+ }))]));
100
+ return changed ? { ...config, graphVisibility: accounts } : config;
101
+ }
102
+ export function announceGraphVisibilityChange() { announce(); }
@@ -0,0 +1,24 @@
1
+ import type { Graph } from './graphs.js';
2
+ /** A model chosen while a run is working: the pair the run moves to, and which of its nodes follow. */
3
+ export interface LiveModelSelection {
4
+ provider: string;
5
+ model: string;
6
+ /** Every node and delegation follows the pair, including nodes that name their own model. */
7
+ overrideAllNodes: boolean;
8
+ /** Only the nodes in `nodeOverrides` were changed: a node that follows the run's model stays as it is. */
9
+ nodeOnly?: boolean;
10
+ nodeOverrides?: Record<string, {
11
+ provider: string;
12
+ model: string;
13
+ }>;
14
+ }
15
+ /**
16
+ * The provider and model a live selection gives one agent of the run, or undefined when the selection
17
+ * leaves that agent alone. `nodeId` is the engine's live id: `<node>`, `<node>/<role>` for a subagent,
18
+ * either part ending in `#fallback` on a retry's fallback attempt. A missing `model` means the
19
+ * provider's configured one.
20
+ */
21
+ export declare function liveModelTarget(current: LiveModelSelection, nodes: Graph['nodes'] | undefined, nodeId: string | undefined): {
22
+ provider: string;
23
+ model?: string;
24
+ } | undefined;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The provider and model a live selection gives one agent of the run, or undefined when the selection
3
+ * leaves that agent alone. `nodeId` is the engine's live id: `<node>`, `<node>/<role>` for a subagent,
4
+ * either part ending in `#fallback` on a retry's fallback attempt. A missing `model` means the
5
+ * provider's configured one.
6
+ */
7
+ export function liveModelTarget(current, nodes, nodeId) {
8
+ const [rootId, roleId] = (nodeId ?? '').split('/');
9
+ const fallback = roleId?.endsWith('#fallback') || rootId.endsWith('#fallback');
10
+ const own = nodes?.[rootId.replace(/#fallback$/, '')];
11
+ const nodeOverride = current.nodeOverrides?.[rootId.replace(/#fallback$/, '')];
12
+ if (current.nodeOnly === true && nodeOverride === undefined && own?.provider === undefined)
13
+ return undefined;
14
+ const policy = own?.subagents;
15
+ const role = policy?.roles?.find(item => item.id === roleId?.replace(/#fallback$/, ''));
16
+ const parentProvider = nodeOverride?.provider ?? own?.provider ?? current.provider;
17
+ const parentModel = nodeOverride?.model ?? own?.model ?? (own?.provider === undefined ? current.model : undefined);
18
+ let targetProvider = parentProvider, targetModel = parentModel;
19
+ if (fallback && own?.retry?.fallback) {
20
+ targetProvider = own.retry.fallback.provider;
21
+ targetModel = own.retry.fallback.model;
22
+ }
23
+ const inheritedProvider = targetProvider, inheritedModel = targetModel;
24
+ if (roleId && policy?.modelPolicy === 'specific') {
25
+ targetProvider = policy.provider ?? inheritedProvider;
26
+ targetModel = policy.model;
27
+ }
28
+ else if (roleId && policy?.modelPolicy === 'per-role') {
29
+ targetProvider = role?.provider ?? inheritedProvider;
30
+ targetModel = role?.model ?? (targetProvider === inheritedProvider ? inheritedModel : undefined);
31
+ }
32
+ if (current.overrideAllNodes && nodeOverride === undefined) {
33
+ targetProvider = current.provider;
34
+ targetModel = current.model;
35
+ }
36
+ return { provider: targetProvider, ...(targetModel === undefined ? {} : { model: targetModel }) };
37
+ }
@@ -2,6 +2,7 @@ import { CliSignIn, type ManagedSignInState } from './cli-sign-in.js';
2
2
  import { type OpenCodeServerLike, type OpenCodeSignInOption } from './opencode-cli-provider.js';
3
3
  export declare function claudeSignIn(): CliSignIn;
4
4
  export declare function grokSignIn(): CliSignIn;
5
+ export declare function googleSignIn(): CliSignIn;
5
6
  export interface OpenCodeSignInState extends ManagedSignInState {
6
7
  connected?: {
7
8
  id: string;
@@ -2,6 +2,7 @@ import { resolveCliExecutable } from './cli-executable.js';
2
2
  import { CliSignIn } from './cli-sign-in.js';
3
3
  import { claudeEnvironment, readClaudeSignIn } from './claude-provider.js';
4
4
  import { resolveClaudeExecutable } from './claude-executable.js';
5
+ import { GOOGLE_EXECUTABLE, googleEnvironment, readGoogleCatalog } from './google-provider.js';
5
6
  import { GROK_EXECUTABLE, grokEnvironment, readGrokCatalog } from './grok-provider.js';
6
7
  import { authorizeOpenCode, completeOpenCode, listOpenCodeSignIns, readOpenCodeCatalog, sharedOpenCodeServer, signOutOpenCode, } from './opencode-cli-provider.js';
7
8
  export function claudeSignIn() {
@@ -28,6 +29,18 @@ export function grokSignIn() {
28
29
  deviceCode: true,
29
30
  });
30
31
  }
32
+ export function googleSignIn() {
33
+ return new CliSignIn({
34
+ product: 'Google',
35
+ resolveExecutable: () => resolveCliExecutable(GOOGLE_EXECUTABLE),
36
+ env: () => googleEnvironment(),
37
+ loginArgs: ['acp', '--login'],
38
+ signOutHint: 'The Antigravity CLI signs out only from inside it: run agy in a terminal, type /logout, then refresh here.',
39
+ status: signal => readGoogleCatalog(signal),
40
+ pageHosts: ['accounts.google.com'],
41
+ acceptsCode: true,
42
+ });
43
+ }
31
44
  export class OpenCodeSignIn {
32
45
  server;
33
46
  attempt;
@@ -5,6 +5,8 @@ export interface MembershipVerdict {
5
5
  subject?: string;
6
6
  }
7
7
  export declare class PaidMembershipRequiredError extends Error {
8
+ /** The membership could not be checked (timeout, 5xx, 429, network). Says nothing about the account's plan. */
9
+ unavailable: boolean;
8
10
  constructor(message?: string);
9
11
  static for(access: MembershipVerdict): PaidMembershipRequiredError;
10
12
  }
@@ -5,11 +5,15 @@ const REASONS = {
5
5
  network: 'the account service could not be reached',
6
6
  };
7
7
  export class PaidMembershipRequiredError extends Error {
8
+ /** The membership could not be checked (timeout, 5xx, 429, network). Says nothing about the account's plan. */
9
+ unavailable = false;
8
10
  constructor(message = `Paid membership is required for ${FEATURES}. Use /login to sign in. If already signed in, check your membership or connection.`) { super(message); }
9
11
  static for(access) {
10
12
  if (access.unavailable) {
11
13
  const reason = access.failureReason ? `: ${REASONS[access.failureReason]}` : ' right now';
12
- return new PaidMembershipRequiredError(`Your Andorra membership could not be checked${reason}. This does not mean you were signed out; check your connection and retry.`);
14
+ const error = new PaidMembershipRequiredError(`Your Andorra membership could not be checked${reason}. This does not mean you were signed out; check your connection and retry.`);
15
+ error.unavailable = true;
16
+ return error;
13
17
  }
14
18
  if (!access.subject)
15
19
  return new PaidMembershipRequiredError(`You are signed out of your Andorra account; ${FEATURES} need a signed-in account. Use /login to sign in again.`);
@@ -11,6 +11,7 @@ export interface Membership {
11
11
  paid: boolean;
12
12
  unavailable?: boolean;
13
13
  failureReason?: MembershipFailureReason;
14
+ failureDetail?: string;
14
15
  subject?: string;
15
16
  email?: string;
16
17
  tier?: MembershipTier;
@@ -33,6 +34,8 @@ export interface Membership {
33
34
  billingUrl?: string;
34
35
  }
35
36
  export declare function membershipPlanLabel(tier: MembershipTier | undefined, paid: boolean): string;
37
+ /** Which step of the lookup failed and the first concrete error code under it, e.g. "sign-in token: ECONNRESET". */
38
+ export declare function transportFailureDetail(error: unknown, step: 'sign-in token' | 'account check'): string;
36
39
  export declare function safeAccountEmail(value: unknown): string | undefined;
37
40
  export { PaidMembershipRequiredError } from './membership-errors.js';
38
41
  export interface PlanConfirmation {
@@ -74,6 +74,21 @@ function transportFailureReason(error) {
74
74
  }
75
75
  return network ? 'network' : undefined;
76
76
  }
77
+ /** Which step of the lookup failed and the first concrete error code under it, e.g. "sign-in token: ECONNRESET". */
78
+ export function transportFailureDetail(error, step) {
79
+ let current = error;
80
+ for (let depth = 0; depth < 8 && current && typeof current === 'object'; depth++) {
81
+ const failure = current;
82
+ if (typeof failure.code === 'string' && /^[A-Z][A-Z0-9_]{1,63}$/.test(failure.code))
83
+ return `${step}: ${failure.code}`;
84
+ if (failure.name === 'TimeoutError')
85
+ return `${step}: timeout`;
86
+ if (current instanceof AuthError && failure.code !== 'network')
87
+ return `${step}: ${current.code}`;
88
+ current = failure.cause;
89
+ }
90
+ return step;
91
+ }
77
92
  export function safeAccountEmail(value) {
78
93
  return typeof value === 'string' && value.length <= 254
79
94
  && /^[^\s@\p{Cc}\p{Cf}\p{Cs}]+@[^\s@\p{Cc}\p{Cf}\p{Cs}]+$/u.test(value) ? value : undefined;
@@ -104,7 +119,7 @@ export function createMembershipClient(deps) {
104
119
  }).catch(error => { throw Object.assign(new Error('Membership connection unavailable'), { cause: error, membershipNetworkFailure: true }); });
105
120
  if (!response.ok) {
106
121
  await response.body?.cancel();
107
- return { paid: false, ...(response.status >= 500 || response.status === 429 ? { unavailable: true } : {}) };
122
+ return { paid: false, ...(response.status >= 500 || response.status === 429 ? { unavailable: true, failureDetail: `account check: HTTP ${response.status}` } : {}) };
108
123
  }
109
124
  const reader = response.body?.getReader();
110
125
  if (!reader)
@@ -161,8 +176,10 @@ export function createMembershipClient(deps) {
161
176
  const failureReason = transportFailureReason(error);
162
177
  const refused = error instanceof AuthError && (error.code === 'login_required' || error.code === 'invalid_token');
163
178
  const unavailable = !refused && (bounded === undefined || bounded.aborted || failureReason !== undefined);
179
+ const failureDetail = unavailable ? transportFailureDetail(error, bounded ? 'account check' : 'sign-in token') : undefined;
164
180
  return { paid: false, ...(unavailable ? { unavailable: true } : {}),
165
- ...(unavailable && !bounded?.aborted && failureReason ? { failureReason } : {}) };
181
+ ...(unavailable && !bounded?.aborted && failureReason ? { failureReason } : {}),
182
+ ...(failureDetail ? { failureDetail } : {}) };
166
183
  }
167
184
  };
168
185
  }
@@ -4,7 +4,7 @@ import { join } from 'node:path';
4
4
  export const MODEL_HEALTH_TTL_MS = 10 * 60_000;
5
5
  const REFRESH_INTERVAL_MS = 60_000;
6
6
  const FILE = 'model-health.json';
7
- const DESCRIPTIVE_FIELDS = new Set(['model', 'models', 'modelContextWindows', 'modelNames', 'contextWindow', 'reasoningEffort']);
7
+ const DESCRIPTIVE_FIELDS = new Set(['model', 'models', 'modelContextWindows', 'modelNames', 'modelParameters', 'freeModels', 'contextWindow', 'reasoningEffort']);
8
8
  export function modelHealthKey(provider, model) {
9
9
  const reach = Object.fromEntries(Object.entries(provider)
10
10
  .filter(([name]) => !DESCRIPTIVE_FIELDS.has(name))
@@ -6,6 +6,7 @@ import { readCodexCatalog } from './codex-provider.js';
6
6
  import { codexConnectFor } from './codex-rpc.js';
7
7
  import { readClaudeCatalog } from './claude-provider.js';
8
8
  import { knownClaudeContextWindow } from './model-context-windows.js';
9
+ import { readGoogleCatalog } from './google-provider.js';
9
10
  import { readGrokCatalog } from './grok-provider.js';
10
11
  import { readOpenCodeCatalog } from './opencode-cli-provider.js';
11
12
  import { ANDORRA_SIGN_IN_MESSAGE, ANDORRA_UNAVAILABLE_MESSAGE } from './andorra/endpoint.js';
@@ -45,7 +46,7 @@ export async function refreshModelContext(provider, signal) {
45
46
  return snapshot;
46
47
  }
47
48
  // Andorra entries carry the router's windows already (saved from GET /v1/hosted).
48
- if (snapshot.type === 'codex' || snapshot.type === 'grok' || snapshot.type === 'andorra')
49
+ if (snapshot.type === 'codex' || snapshot.type === 'grok' || snapshot.type === 'google' || snapshot.type === 'andorra')
49
50
  return snapshot;
50
51
  try {
51
52
  // The raw listing: a catalog default must not displace a window the user saved.
@@ -113,6 +114,12 @@ async function listModelMetadata(provider, signal) {
113
114
  throw new Error('Sign in to Grok on this machine before listing its models.');
114
115
  return catalog.models.map(id => ({ id }));
115
116
  }
117
+ if (provider.type === 'google') {
118
+ const catalog = await readGoogleCatalog(signal);
119
+ if (!catalog.signedIn)
120
+ throw new Error('Sign in with Google in the Antigravity CLI on this machine before listing its models.');
121
+ return catalog.models.map(id => ({ id }));
122
+ }
116
123
  if (provider.type === 'opencode')
117
124
  return (await readOpenCodeCatalog(signal)).models.map(model => ({ id: model.id, ...(model.contextWindow ? { contextWindow: model.contextWindow } : {}) }));
118
125
  if (provider.type === 'opencode-go')
@@ -26,6 +26,8 @@ export declare class PagedTranscript<T extends Body, R> {
26
26
  omitted: boolean;
27
27
  };
28
28
  append(value: T): void;
29
+ /** Puts `value` where the newest entry is, for a line that reports progress by rewriting itself. */
30
+ replaceLast(value: T): void;
29
31
  private size;
30
32
  private remember;
31
33
  private materialize;
@@ -68,6 +68,22 @@ export class PagedTranscript {
68
68
  this.omitted = true;
69
69
  }
70
70
  }
71
+ /** Puts `value` where the newest entry is, for a line that reports progress by rewriting itself. */
72
+ replaceLast(value) {
73
+ if (this.closed)
74
+ return;
75
+ const last = this.entries.pop();
76
+ if (last) {
77
+ const cached = this.cache.get(last);
78
+ if (cached) {
79
+ this.cachedChars -= this.size(cached);
80
+ this.cache.delete(last);
81
+ }
82
+ if (!last.fallback)
83
+ this.offset = last.offset;
84
+ }
85
+ this.append(value);
86
+ }
71
87
  size(body) { return body.text.length + (body.detail?.length ?? 0); }
72
88
  remember(entry, body) {
73
89
  const old = this.cache.get(entry);