paseo-office 0.2.2 → 0.2.4

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.
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  CHECKLIST_STEP_MAX,
3
3
  CHECKLIST_TEXT_MAX,
4
+ STEP_LABEL_MAX,
4
5
  type ChecklistStep,
5
6
  type ChecklistCounts,
6
7
  type ChecklistProgress,
7
8
  type Checklists,
9
+ type SubagentCall,
10
+ type SubagentCalls,
8
11
  } from "../shared/contracts.js";
9
12
  import type { ActivityKind, ActivityStep, TestResult } from "../shared/names.js";
10
13
  import { errorMessage } from "./errors.js";
@@ -178,11 +181,40 @@ function resultOf(item: ActivityItem): TestResult | null {
178
181
  return item.status === "completed" ? "passed" : null;
179
182
  }
180
183
 
181
- function stepOf(item: ActivityItem): ActivityStep {
184
+ function cut(text: string): string {
185
+ const line = text.split(/[\r\n]/, 1)[0].trim();
186
+ return line.length > STEP_LABEL_MAX ? `${line.slice(0, STEP_LABEL_MAX - 1)}…` : line;
187
+ }
188
+
189
+ /** What a call is at, for a host whose streamer mode is off: a file's name, a command, a site. */
190
+ function labelOf(item: ActivityItem): string {
191
+ const { detail } = item;
192
+ const command = field(detail, "command");
193
+ if (typeof command === "string") return cut(command);
194
+ const filePath = field(detail, "filePath");
195
+ if (typeof filePath === "string") return cut(filePath.split(/[\\/]/).at(-1) ?? "");
196
+ const query = field(detail, "query");
197
+ if (typeof query === "string") return cut(query);
198
+ const url = field(detail, "url");
199
+ if (typeof url !== "string") return "";
200
+ try {
201
+ return cut(new URL(url).hostname);
202
+ } catch {
203
+ return "";
204
+ }
205
+ }
206
+
207
+ function stepOf(item: ActivityItem, named: boolean): ActivityStep {
182
208
  const kind = toolKind(item);
183
209
  const key = typeof item.callId === "string" && item.callId !== "" ? item.callId : kind;
184
210
  const result = ENDS.has(kind) ? resultOf(item) : null;
185
- return result === null ? { kind, key } : { kind, key, result };
211
+ const label = named ? labelOf(item) : "";
212
+ return {
213
+ kind,
214
+ key,
215
+ ...(result === null ? {} : { result }),
216
+ ...(label === "" ? {} : { label }),
217
+ };
186
218
  }
187
219
 
188
220
  /** The ids of the tool calls in a tail: what a read has seen, for the read after it. */
@@ -209,14 +241,15 @@ export function callsIn(items: readonly ActivityItem[]): Set<string> {
209
241
  export function describeStep(
210
242
  items: readonly ActivityItem[],
211
243
  seen?: ReadonlySet<string>,
244
+ named = false,
212
245
  ): ActivityStep | null {
213
246
  let movedOn = false;
214
247
  for (const item of items.toReversed()) {
215
248
  if (item.type === "tool_call") {
216
- if (!movedOn) return stepOf(item);
249
+ if (!movedOn) return stepOf(item, named);
217
250
  const id = item.callId;
218
251
  const fresh = seen !== undefined && typeof id === "string" && id !== "" && !seen.has(id);
219
- return fresh ? stepOf(item) : null;
252
+ return fresh ? stepOf(item, named) : null;
220
253
  }
221
254
  if (item.type === "user_message") return null;
222
255
  if (item.type === "assistant_message" || item.type === "reasoning") movedOn = true;
@@ -234,8 +267,9 @@ export function nextStep(
234
267
  before: ActivityStep | undefined,
235
268
  items: readonly ActivityItem[],
236
269
  seen?: ReadonlySet<string>,
270
+ named = false,
237
271
  ): ActivityStep | null {
238
- const step = describeStep(items, seen);
272
+ const step = describeStep(items, seen, named);
239
273
  if (
240
274
  before === undefined ||
241
275
  !ENDS.has(before.kind) ||
@@ -286,6 +320,30 @@ export function readChecklist(items: readonly ActivityItem[]): {
286
320
  return { steps, progress };
287
321
  }
288
322
 
323
+ /** The most sub-agents told of one agent: a tail holds no more calls than it has items. */
324
+ const SUBAGENTS_MAX = 12;
325
+
326
+ /**
327
+ * The sub-agents an agent has at work: its `Task` or `Agent` calls in the tail that still run, the
328
+ * oldest first. Each is told by its call's id and the kind of sub-agent the provider names, never
329
+ * by its task, which is the prompt it was given. A call older than the tail is not seen.
330
+ */
331
+ export function runningSubagents(items: readonly ActivityItem[]): SubagentCall[] {
332
+ const calls: SubagentCall[] = [];
333
+ const seen = new Set<string>();
334
+ for (const item of items) {
335
+ if (item.type !== "tool_call" || item.status !== "running") continue;
336
+ const id = item.callId;
337
+ if (typeof id !== "string" || id === "" || seen.has(id)) continue;
338
+ if (toolKind(item) !== "subagent") continue;
339
+ seen.add(id);
340
+ const named = field(item.detail, "subAgentType");
341
+ const type = typeof named === "string" ? named.trim().slice(0, 40) : "";
342
+ calls.push({ id, type: type === "" ? "agent" : type });
343
+ }
344
+ return calls.slice(-SUBAGENTS_MAX);
345
+ }
346
+
289
347
  /** What the poller knows of each running agent: its line, and its step when it is at one. */
290
348
  export type ActivityLines = Readonly<Record<string, string>>;
291
349
  export type ActivitySteps = Readonly<Record<string, ActivityStep>>;
@@ -296,6 +354,8 @@ export interface ActivityPorts {
296
354
  tail(agentId: string): Promise<readonly ActivityItem[]>;
297
355
  timers: Timers;
298
356
  log(message: string): void;
357
+ /** Whether a step says what it is at (the host's streamer mode is off); absent, it never does. */
358
+ named?(): boolean;
299
359
  /**
300
360
  * `checklists` holds each agent read this round whose tail has a todo item, `[]` when all its
301
361
  * steps are finished; an agent whose read failed, or whose tail has none, is absent. An agent
@@ -306,6 +366,8 @@ export interface ActivityPorts {
306
366
  doing: ActivitySteps,
307
367
  checklists: Readonly<Checklists>,
308
368
  progress: Readonly<ChecklistCounts>,
369
+ /** The sub-agents each agent read this round has at work; an agent with none is absent. */
370
+ subagents: Readonly<SubagentCalls>,
309
371
  ): void;
310
372
  }
311
373
 
@@ -337,6 +399,7 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
337
399
  let previous: ActivityLines = {};
338
400
  let previousSteps: ActivitySteps = {};
339
401
  let previousChecklists = "[{},{}]";
402
+ let previousSubagents = "{}";
340
403
  let wasRunning: readonly string[] = [];
341
404
  // The calls each agent's last read saw, kept while the poller runs: an agent's next turn is
342
405
  // read against them too. A prompt ends the look back, so an old turn's call is never told.
@@ -348,13 +411,16 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
348
411
  steps: Record<string, ActivityStep>,
349
412
  checklists: Checklists,
350
413
  progress: ChecklistCounts,
414
+ subagents: SubagentCalls,
351
415
  ): Promise<void> {
352
416
  try {
353
417
  const items = await ports.tail(agentId);
418
+ const working = runningSubagents(items);
419
+ if (working.length > 0) subagents[agentId] = working;
354
420
  const line = describeActivity(items);
355
421
  if (line !== null) next[agentId] = line;
356
422
  const seen = seenCalls.get(agentId);
357
- const step = nextStep(previousSteps[agentId], items, seen);
423
+ const step = nextStep(previousSteps[agentId], items, seen, ports.named?.() ?? false);
358
424
  if (step !== null) steps[agentId] = step;
359
425
  const checklist = readChecklist(items);
360
426
  if (checklist !== null) {
@@ -398,10 +464,12 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
398
464
  const steps: Record<string, ActivityStep> = {};
399
465
  const checklists: Checklists = {};
400
466
  const progress: ChecklistCounts = {};
467
+ // An agent whose read failed has none here, so its sub-agents leave until a read succeeds.
468
+ const subagents: SubagentCalls = {};
401
469
  const running = [...ports.running()];
402
470
  for (const agentId of running) {
403
471
  if (stopped) return;
404
- await readOne(agentId, next, steps, checklists, progress);
472
+ await readOne(agentId, next, steps, checklists, progress, subagents);
405
473
  }
406
474
  for (const agentId of wasRunning) {
407
475
  if (stopped) return;
@@ -409,15 +477,18 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
409
477
  }
410
478
  wasRunning = running;
411
479
  const checklistsText = JSON.stringify([checklists, progress]);
480
+ const subagentsText = JSON.stringify(subagents);
412
481
  const unchanged =
413
482
  sameLines(previous, next) &&
414
483
  sameSteps(previousSteps, steps) &&
415
- checklistsText === previousChecklists;
484
+ checklistsText === previousChecklists &&
485
+ subagentsText === previousSubagents;
416
486
  if (stopped || unchanged) return;
417
487
  previous = next;
418
488
  previousSteps = steps;
419
489
  previousChecklists = checklistsText;
420
- ports.onChange(next, steps, checklists, progress);
490
+ previousSubagents = subagentsText;
491
+ ports.onChange(next, steps, checklists, progress, subagents);
421
492
  }
422
493
 
423
494
  function runLogged(): void {
@@ -13,6 +13,7 @@ import {
13
13
  type WorkspaceTicket,
14
14
  } from "../shared/contracts.js";
15
15
  import { APPEARANCE_KEY, AppearanceSchema } from "../shared/appearance.js";
16
+ import { storedTeamName } from "../shared/team-name.js";
16
17
  import { NEXT_KEY, NUMBER_KEY, storedNumber } from "./subagent-names.js";
17
18
 
18
19
  // PARENT_AGENT_ID_LABEL in packages/protocol/src/agent-labels.ts. Server code may import the
@@ -352,9 +353,12 @@ export function projectWorkspace(workspace: DirectoryWorkspaceInput): OfficeWork
352
353
  const pullRequest = pullRequestOf(workspace);
353
354
  const { additions = 0, deletions = 0 } = workspace.diffStat ?? {};
354
355
  const scripts = (workspace.scripts ?? []).map(scriptOf);
356
+ const teamName = storedTeamName(workspace.metadata);
355
357
  return {
356
358
  id: workspace.id,
357
- name: workspace.name,
359
+ // The team's name is the workspace's everywhere in the office once the owner has given one.
360
+ name: teamName ?? workspace.name,
361
+ ...(teamName === null ? {} : { workspaceName: workspace.name }),
358
362
  projectName: workspace.projectDisplayName,
359
363
  ...(branch ? { branch } : {}),
360
364
  ...(ticket ? { ticket } : {}),
package/server/hub.ts CHANGED
@@ -12,6 +12,7 @@ import type {
12
12
  OfficeSnapshot,
13
13
  OfficeWorkspace,
14
14
  Post,
15
+ SubagentCalls,
15
16
  WakeState,
16
17
  WorkspaceScript,
17
18
  } from "../shared/contracts.js";
@@ -54,6 +55,7 @@ export interface HubPorts {
54
55
  doing: ActivitySteps,
55
56
  checklists: Readonly<Checklists>,
56
57
  progress?: Readonly<ChecklistCounts>,
58
+ subagents?: Readonly<SubagentCalls>,
57
59
  ) => void,
58
60
  ): () => void;
59
61
  timers: Timers;
@@ -138,6 +140,8 @@ export function createHub(ports: HubPorts): Hub {
138
140
  // Kept after an agent stops, as the poller reads only running agents; dropped when it leaves.
139
141
  let checklists: Checklists = {};
140
142
  let checklistProgress: ChecklistCounts = {};
143
+ /** The provider's own sub-agents each running agent has at work, as the last round read them. */
144
+ let subagents: Readonly<SubagentCalls> = {};
141
145
  let boards: Record<string, readonly Post[]> = {};
142
146
  let wake: WakeState = { paused: false, queued: {} };
143
147
  let notes: NotesState | null = null;
@@ -168,6 +172,7 @@ export function createHub(ports: HubPorts): Hub {
168
172
  workspaces: [...view.workspaces],
169
173
  activity: { ...activity },
170
174
  doing: { ...doing },
175
+ ...(Object.keys(subagents).length ? { subagents: { ...subagents } } : {}),
171
176
  checklists: { ...checklists },
172
177
  ...(Object.keys(checklistProgress).length
173
178
  ? { checklistProgress: { ...checklistProgress } }
@@ -285,6 +290,7 @@ export function createHub(ports: HubPorts): Hub {
285
290
  type: "activity",
286
291
  activity: { ...activity },
287
292
  doing: { ...doing },
293
+ ...(Object.keys(subagents).length ? { subagents: { ...subagents } } : {}),
288
294
  checklists: { ...checklists },
289
295
  ...(Object.keys(checklistProgress).length
290
296
  ? { checklistProgress: { ...checklistProgress } }
@@ -335,9 +341,11 @@ export function createHub(ports: HubPorts): Hub {
335
341
  steps: ActivitySteps,
336
342
  report: Readonly<Checklists>,
337
343
  progress: Readonly<ChecklistCounts> = {},
344
+ working: Readonly<SubagentCalls> = {},
338
345
  ): void {
339
346
  activity = next;
340
347
  doing = steps;
348
+ subagents = working;
341
349
  const listed = new Set(view.agents.map((agent) => agent.id));
342
350
  const fresh = Object.entries(report).filter(([agentId]) => listed.has(agentId));
343
351
  const merged = Object.entries({ ...checklists, ...Object.fromEntries(fresh) });
@@ -444,6 +452,7 @@ export function createHub(ports: HubPorts): Hub {
444
452
  doing = {};
445
453
  checklists = {};
446
454
  checklistProgress = {};
455
+ subagents = {};
447
456
  const stop = stopDirectory;
448
457
  stopDirectory = null;
449
458
  view = EMPTY_VIEW;
@@ -17,6 +17,8 @@ export function createLifeFeed(deps: {
17
17
  const pending = new Map<string, Promise<void>>();
18
18
  const folderTeams = new Map<string, Set<string>>();
19
19
  let connected = false;
20
+ /** The name each workspace went by at the last view, to tell a rename. */
21
+ const shown = new Map<string, string>();
20
22
  let queuedAge = Promise.resolve();
21
23
  function snapshot(): Snapshot {
22
24
  const born = new Map<string, string>();
@@ -84,6 +86,13 @@ export function createLifeFeed(deps: {
84
86
  return;
85
87
  }
86
88
  const names = new Map(view.workspaces.map((w) => [w.id, w.name]));
89
+ // A workspace that goes by another name since the last view is the same team: its tenure
90
+ // goes with it, so a rename makes nobody an intern again.
91
+ for (const [id, name] of names) {
92
+ const before = shown.get(id);
93
+ if (before !== undefined && before !== name) deps.tenure.rename(before, name);
94
+ shown.set(id, name);
95
+ }
87
96
  const at = deps.now();
88
97
  const today = new Date(at).toDateString();
89
98
  const seeds = new Map(
@@ -123,6 +132,10 @@ export function createLifeFeed(deps: {
123
132
  readFolders(view, names);
124
133
  changed();
125
134
  },
135
+ /** A team now goes by `to`: its tenure goes with it, before the directory says so. */
136
+ renamed(from: string, to: string) {
137
+ if (deps.tenure.rename(from, to)) changed();
138
+ },
126
139
  async turnEnded(id: string, lookup?: () => Promise<string | null>) {
127
140
  const name = teams.get(id) ?? (await lookup?.());
128
141
  if (name) {
@@ -7,6 +7,8 @@ import {
7
7
  type ChatServicePorts,
8
8
  } from "./chat-service.js";
9
9
  import { PARENT_AGENT_ID_LABEL } from "./directory.js";
10
+ import { writerMode, writerModeChoices } from "./writer-mode.js";
11
+ import type { WriterModes } from "../shared/contracts.js";
10
12
  import type { Hub, HubPorts } from "./hub.js";
11
13
  import type { JanitorPorts } from "./janitor.js";
12
14
  import { wakeTargetOf } from "./mention-queue.js";
@@ -25,6 +27,8 @@ export function liveHubPorts(
25
27
  holder: PaseoHolder,
26
28
  timers: Timers,
27
29
  log: (message: string) => void,
30
+ /** Whether steps name what they are at: the host's streamer mode is off. */
31
+ named: () => boolean = () => false,
28
32
  ): HubPorts {
29
33
  return {
30
34
  openDirectory: (onChange, onEnd) => openPaseoDirectory(holder.require(), onChange, log, onEnd),
@@ -40,6 +44,7 @@ export function liveHubPorts(
40
44
  },
41
45
  timers,
42
46
  log,
47
+ named,
43
48
  onChange,
44
49
  });
45
50
  return () => poller.stop();
@@ -250,28 +255,45 @@ export function liveScriptLogPorts(
250
255
 
251
256
  type AgentConfig = Parameters<Paseo["agents"]["create"]>[0]["config"];
252
257
 
253
- // Claude's "Accept File Edits", which a provider extending Claude lists too. The owner's call:
254
- // nobody watches the 8:00 writer, so it edits the notes without asking.
255
- const ACCEPT_EDITS_MODE = "acceptEdits";
256
-
257
258
  /**
258
259
  * The host's default provider, as the host can tell it. The app's new-agent form starts from the
259
260
  * provider the device chose last, which the host never sees; so this takes the first enabled,
260
261
  * ready provider in the daemon's order, with the model the form gives that provider: its default
261
- * (else its first selectable one). The mode is the provider's that accepts edits, else its
262
- * default: Codex's and OpenCode's default modes edit in the workspace without asking already.
262
+ * (else its first selectable one). The mode is `writerMode`'s: the settings' where the provider
263
+ * offers it, else the one that accepts edits, else the provider's default. Nobody watches the
264
+ * 8:00 writer, so by default it edits the notes without asking.
263
265
  */
264
- async function defaultAgentConfig(paseo: Paseo, cwd: string): Promise<AgentConfig> {
266
+ async function writerProvider(paseo: Paseo, cwd: string) {
265
267
  const { entries } = await paseo.providers.waitForReady({ cwd });
266
268
  const entry = entries.find((candidate) => candidate.enabled && candidate.status === "ready");
267
269
  if (entry === undefined) throw new Error("No agent provider is ready on this host");
270
+ return entry;
271
+ }
272
+
273
+ /** The provider the writer would start on now, its modes, and the one `wanted` comes to. */
274
+ export async function readWriterModes(
275
+ holder: PaseoHolder,
276
+ cwd: string,
277
+ wanted: string,
278
+ ): Promise<WriterModes> {
279
+ const entry = await writerProvider(holder.require(), cwd);
280
+ const { modeId, fellBack } = writerMode(entry, wanted);
281
+ return {
282
+ provider: entry.label ?? entry.provider,
283
+ modes: writerModeChoices(entry),
284
+ modeId: modeId ?? null,
285
+ fellBack,
286
+ };
287
+ }
288
+
289
+ async function defaultAgentConfig(paseo: Paseo, cwd: string, wanted: string): Promise<AgentConfig> {
290
+ const entry = await writerProvider(paseo, cwd);
268
291
  const models = (entry.models ?? []).filter((model) => model.isSelectable !== false);
269
292
  const model = models.find((candidate) => candidate.isDefault) ?? models[0];
270
293
  if (model === undefined) {
271
294
  throw new Error(`The provider ${entry.label ?? entry.provider} offers no model`);
272
295
  }
273
- const acceptsEdits = (entry.modes ?? []).some((mode) => mode.id === ACCEPT_EDITS_MODE);
274
- const modeId = acceptsEdits ? ACCEPT_EDITS_MODE : entry.defaultModeId;
296
+ const { modeId } = writerMode(entry, wanted);
275
297
  return {
276
298
  provider: `${entry.provider}/${model.id}`,
277
299
  ...(modeId ? { modeId } : {}),
@@ -290,9 +312,9 @@ export function liveNotesPorts(
290
312
  (found) => found.isDirectory(),
291
313
  () => false,
292
314
  ),
293
- async startAgent({ cwd, title, prompt }) {
315
+ async startAgent({ cwd, title, prompt, mode }) {
294
316
  const paseo = holder.require();
295
- const config = await defaultAgentConfig(paseo, cwd);
317
+ const config = await defaultAgentConfig(paseo, cwd, mode ?? "");
296
318
  const workspace = await paseo.workspaces.open(cwd);
297
319
  const agent = await workspace.agents.create({ config, title, prompt });
298
320
  return agent.id;
@@ -9,6 +9,8 @@ const NOTES: OfficeSchedule = { name: NOTES_SCHEDULE, label: "Stand-up notes", l
9
9
  export interface NotesSettings {
10
10
  notesFolder: string;
11
11
  notesTimeZone: string;
12
+ /** The mode the writer starts in, by the provider's id; empty or absent for the office's choice. */
13
+ notesMode?: string;
12
14
  }
13
15
 
14
16
  /** What the 8:00 run follows: the folder and zone, and its weekdays, 0 for Sunday. */
@@ -48,6 +48,8 @@ export interface WriterStart {
48
48
  cwd: string;
49
49
  title: string;
50
50
  prompt: string;
51
+ /** The settings' mode for the writer; absent when none is set. */
52
+ mode?: string;
51
53
  }
52
54
 
53
55
  export interface NotesPorts {
@@ -219,7 +221,13 @@ export function createNotesWriter(ports: NotesPorts): NotesWriter {
219
221
  report: standupReport(await ports.snapshot(), now),
220
222
  });
221
223
  endedWhileStarting = new Map();
222
- const writerId = await ports.startAgent({ cwd: folder, title: NOTES_WRITER_TITLE, prompt });
224
+ const mode = settings.notesMode?.trim() ?? "";
225
+ const writerId = await ports.startAgent({
226
+ cwd: folder,
227
+ title: NOTES_WRITER_TITLE,
228
+ prompt,
229
+ ...(mode === "" ? {} : { mode }),
230
+ });
223
231
  return { writerId, entry: { folder, ...day } };
224
232
  }
225
233
 
@@ -0,0 +1,51 @@
1
+ import type { PlanUsage, PlanWindow } from "../shared/plan-usage.js";
2
+
3
+ /** The fields the office reads from a provider's usage, as Paseo lists it. */
4
+ export interface ProviderUsageInput {
5
+ providerId: string;
6
+ displayName: string;
7
+ status: string;
8
+ planLabel?: string | null;
9
+ windows?: readonly {
10
+ id: string;
11
+ label: string;
12
+ usedPct?: number | null;
13
+ remainingPct?: number | null;
14
+ resetsAt?: string | null;
15
+ }[];
16
+ }
17
+
18
+ function windowOf(input: NonNullable<ProviderUsageInput["windows"]>[number]): PlanWindow | null {
19
+ const { usedPct, remainingPct } = input;
20
+ let used: number | null = null;
21
+ if (typeof usedPct === "number") used = usedPct;
22
+ else if (typeof remainingPct === "number") used = 100 - remainingPct;
23
+ if (used === null || !Number.isFinite(used)) return null;
24
+ const reset = input.resetsAt ? Date.parse(input.resetsAt) : Number.NaN;
25
+ return {
26
+ id: input.id,
27
+ label: input.label,
28
+ usedPct: Math.min(100, Math.max(0, used)),
29
+ resetsAt: Number.isFinite(reset) ? reset : null,
30
+ };
31
+ }
32
+
33
+ /**
34
+ * The providers whose plan can be read now, each with the limits that say how much is used. One
35
+ * that is unavailable, in error, or reports no percentage is left out.
36
+ */
37
+ export function projectPlanUsage(providers: readonly ProviderUsageInput[]): PlanUsage[] {
38
+ const usage: PlanUsage[] = [];
39
+ for (const provider of providers) {
40
+ if (provider.status !== "available") continue;
41
+ const windows = (provider.windows ?? []).flatMap((window) => windowOf(window) ?? []);
42
+ if (windows.length === 0) continue;
43
+ usage.push({
44
+ provider: provider.providerId,
45
+ name: provider.displayName,
46
+ plan: provider.planLabel ?? null,
47
+ windows,
48
+ });
49
+ }
50
+ return usage;
51
+ }
package/server/tenure.ts CHANGED
@@ -55,6 +55,8 @@ export interface Tenure {
55
55
  list(live: ReadonlySet<string>): TenureProject[];
56
56
  seed(teams: readonly SeedTeam[]): void;
57
57
  get(team: string): TenureEntry | null;
58
+ /** A team that goes by another name keeps its entry; false when it has none or `to` is taken. */
59
+ rename(from: string, to: string): boolean;
58
60
  /** True once seed() has run on this ledger, now or on an earlier start. */
59
61
  seeded(): boolean;
60
62
  }
@@ -94,6 +96,14 @@ export function createTenure(deps: { store: TenureStore; now?: () => number }):
94
96
  return {
95
97
  seeded: () => ledger.seeded,
96
98
  get: (team) => projects[team] ?? null,
99
+ rename(from, to) {
100
+ const entry = projects[from];
101
+ if (!entry || !to || from === to || projects[to]) return false;
102
+ projects[to] = entry;
103
+ delete projects[from];
104
+ save();
105
+ return true;
106
+ },
97
107
  seed(teams) {
98
108
  if (ledger.seeded) return;
99
109
  const at = now();