@alterset/alterspec-client 0.28.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -110,8 +110,9 @@ npx @alterset/alterspec-client init --product --dispatcher https://<dispatcher>
110
110
 
111
111
  It writes `.alterspec-client.json` with `dispatcher` and `key` only (`--key` as above; no export, no tracks), the
112
112
  `dispatcher` entry in `.mcp.json` and its approval, and nothing of the developer's: no hook, no skill, no prompt. It
113
- prints the key to send to the admin, who registers the owner as a **product person**: a person of their own, with no
114
- track. One key, one role: an owner who also develops uses another key in the code repository.
113
+ prints the key to send to the admin, who registers the owner as a **product person** (the product flag). One key,
114
+ both roles: an owner who also develops has their tracks and the product flag on one person, and the client asks the
115
+ dispatcher for the role its folder means (`product` here, `developer` in a code repository; dispatcher decision 33).
115
116
 
116
117
  In the next Claude Code session in the spec project the dispatcher's product tools appear, and only those:
117
118
  `whoami`, `questions`, `answer`, `reconcile`, `feedback` (the teams' feedback lines, read) and `bug_reports` (the
@@ -251,6 +251,18 @@ When the brief says "Start from `task/chg-012-be`", a task yours waited for was
251
251
  yet: fetch it and base your branch on it, not on main (`git fetch origin task/chg-012-be`, then branch from
252
252
  `origin/task/chg-012-be`). The teams merge a change's branches together once every track is done.
253
253
 
254
+ When another track has finished the same change, the brief says so near its top: "**BE has shipped this change**"
255
+ with its commit and branch (from the dispatcher's `task`, which names the change's other tasks). The server already
256
+ behaves as the change says, so your tests of what the change removes or narrows fail until your task is done:
257
+ updating them is part of your task, not a broken dependency. A track still at work is named as "building this change
258
+ now". The dispatcher offers a shipped change's other tasks first.
259
+
260
+ When the change keeps a **compatibility** (its proposal's "Compatibility" section: what the server keeps accepting
261
+ from the apps as they are today), the brief says that instead of "tests will fail": on the backend, which tracks
262
+ still build the change and which later task ends the compatibility; on an app, that the server keeps the old
263
+ behaviour until your task is done. The task that ends a compatibility waits for every app task of the change that
264
+ kept it; when to deploy it is the team's call, since old app versions stay in use after a task is done.
265
+
254
266
  ### A brief that doesn't move under you
255
267
 
256
268
  The spec keeps changing while you build: a rule your task names may be edited by three later changes before you are
package/dist/cli.js CHANGED
@@ -241,6 +241,35 @@ function writeConfig(root, config) {
241
241
  writeFileSync(join(root, CONFIG_FILE), JSON.stringify(config, null, 2) + "\n");
242
242
  }
243
243
 
244
+ // src/role.ts
245
+ var ROLE_HEADER = "x-alterspec-role";
246
+ var roleOfConfig = (config) => isProduct(config) ? "product" : "developer";
247
+ var PRODUCT_TOOLS = [
248
+ "whoami",
249
+ "questions",
250
+ "answer",
251
+ "reconcile",
252
+ "feedback",
253
+ "bug_reports"
254
+ ];
255
+ var PRODUCT_ONLY = /* @__PURE__ */ new Set(["answer", "reconcile", "bug_reports"]);
256
+ function roleOf(whoami) {
257
+ if (whoami.role === "product" || whoami.role === "developer") return whoami.role;
258
+ return whoami.product === true ? "product" : "developer";
259
+ }
260
+ function allows(role, tool) {
261
+ return role === "product" ? PRODUCT_TOOLS.includes(tool) : !PRODUCT_ONLY.has(tool);
262
+ }
263
+ function refusal(role, tool) {
264
+ return role === "product" ? {
265
+ code: "NOT_DEVELOPER",
266
+ message: `Your key is registered as a product person; \`${tool}\` is the developers'. A product session sees the build's questions, feedback and bugs, never its tasks.`
267
+ } : {
268
+ code: "NOT_PRODUCT",
269
+ message: `Your key is registered as a developer; \`${tool}\` is the product side's. Answers and reconciling are the spec project's, through a key registered as a product person.`
270
+ };
271
+ }
272
+
244
273
  // src/ssh.ts
245
274
  import { execFileSync as execFileSync2 } from "child_process";
246
275
  import { createHash } from "crypto";
@@ -359,11 +388,14 @@ var Session = class {
359
388
  this.fetchFn = opts.fetch ?? fetch;
360
389
  this.now = opts.now ?? Date.now;
361
390
  this.signer = opts.signer ?? sign;
391
+ this.role = opts.role;
362
392
  }
363
393
  token;
364
394
  fetchFn;
365
395
  now;
366
396
  signer;
397
+ /** The role asked for on every request, when the configuration means one (decision 33). */
398
+ role;
367
399
  /** How many times this session signed in, for tests and logs. */
368
400
  signIns = 0;
369
401
  async call(path, init) {
@@ -406,6 +438,7 @@ var Session = class {
406
438
  for (let attempt = 0; ; attempt++) {
407
439
  const headers = new Headers(init.headers);
408
440
  headers.set("authorization", `Bearer ${await this.bearer()}`);
441
+ if (this.role) headers.set(ROLE_HEADER, this.role);
409
442
  const res = await this.call(path, { ...init, headers });
410
443
  if (res.status !== 401 || attempt > 0) {
411
444
  if (res.status === 401 || res.status === 403) throw await errorOf(res, this.key);
@@ -422,7 +455,7 @@ function keyOf(loaded) {
422
455
  const configured = key && !/^(ssh-ed25519|sk-ssh-ed25519@openssh\.com) /.test(key) ? configPath(loaded.root, key) : key;
423
456
  return resolveKey({ configured });
424
457
  }
425
- var sessionOf = (loaded) => new Session(loaded.config.dispatcher, keyOf(loaded));
458
+ var sessionOf = (loaded) => new Session(loaded.config.dispatcher, keyOf(loaded), { role: roleOfConfig(loaded.config) });
426
459
 
427
460
  // src/bugs.ts
428
461
  import { z as z8 } from "zod";
@@ -694,6 +727,13 @@ function exportChange(e) {
694
727
  return "not in the export";
695
728
  }
696
729
 
730
+ // ../src/changes/compatibility.ts
731
+ var COMPATIBILITY_SECTION = "Compatibility";
732
+ function compatibilityText(sectionText2) {
733
+ const text = sectionText2?.trim();
734
+ return text && !/^none\b/i.test(text) ? text : void 0;
735
+ }
736
+
697
737
  // ../src/changes/data-change.ts
698
738
  var DATA_CHANGE_SECTION = "One-time data change";
699
739
  var DATA_CHANGE_ITEM = "data-change";
@@ -1253,35 +1293,6 @@ import { z as z7 } from "zod";
1253
1293
 
1254
1294
  // src/mcp.ts
1255
1295
  import { createInterface } from "readline";
1256
-
1257
- // src/role.ts
1258
- var PRODUCT_TOOLS = [
1259
- "whoami",
1260
- "questions",
1261
- "answer",
1262
- "reconcile",
1263
- "feedback",
1264
- "bug_reports"
1265
- ];
1266
- var PRODUCT_ONLY = /* @__PURE__ */ new Set(["answer", "reconcile", "bug_reports"]);
1267
- function roleOf(whoami) {
1268
- if (whoami.role === "product" || whoami.role === "developer") return whoami.role;
1269
- return whoami.product === true ? "product" : "developer";
1270
- }
1271
- function allows(role, tool) {
1272
- return role === "product" ? PRODUCT_TOOLS.includes(tool) : !PRODUCT_ONLY.has(tool);
1273
- }
1274
- function refusal(role, tool) {
1275
- return role === "product" ? {
1276
- code: "NOT_DEVELOPER",
1277
- message: `Your key is registered as a product person; \`${tool}\` is the developers'. A product session sees the build's questions, feedback and bugs, never its tasks.`
1278
- } : {
1279
- code: "NOT_PRODUCT",
1280
- message: `Your key is registered as a developer; \`${tool}\` is the product side's. Answers and reconciling are the spec project's, through a key registered as a product person.`
1281
- };
1282
- }
1283
-
1284
- // src/mcp.ts
1285
1296
  var isRequest = (m) => m.method !== void 0 && m.id !== void 0;
1286
1297
  async function callTool(session, name, args = {}) {
1287
1298
  const res = await session.fetch("/mcp", {
@@ -1589,6 +1600,29 @@ function answersSection(answers) {
1589
1600
  // src/context.ts
1590
1601
  var ContextError = class extends Error {
1591
1602
  };
1603
+ function parseSiblings(value) {
1604
+ if (!Array.isArray(value)) return void 0;
1605
+ const str = (v) => typeof v === "string" && v ? v : void 0;
1606
+ return value.flatMap((v) => {
1607
+ const id = str(v?.id);
1608
+ const track = str(v?.track) ?? id?.split("/")[1];
1609
+ const status = str(v?.status);
1610
+ if (!id || !track || !status) return [];
1611
+ const commit = str(v.commit);
1612
+ const branch = str(v.branch);
1613
+ const inMain = str(v.in_main_at);
1614
+ return [
1615
+ {
1616
+ id,
1617
+ track,
1618
+ status,
1619
+ ...commit ? { commit } : {},
1620
+ ...branch ? { branch } : {},
1621
+ ...inMain ? { in_main_at: inMain } : {}
1622
+ }
1623
+ ];
1624
+ });
1625
+ }
1592
1626
  function startFrom(track, after2) {
1593
1627
  if (!Array.isArray(after2)) return [];
1594
1628
  const out = [];
@@ -1899,6 +1933,26 @@ function reachOf(x, id, kind, changed) {
1899
1933
  screens: screens.map((s) => piece(s.id, s.title))
1900
1934
  };
1901
1935
  }
1936
+ function compatibilityOf(x, change, work, proposal) {
1937
+ const text = compatibilityText(sectionText(x, x.sectionShard(proposal, COMPATIBILITY_SECTION)));
1938
+ const crosses = (owner, ownerChange, a) => a.change !== ownerChange && a.track !== owner.track;
1939
+ const endedBy = x.work.changes.flatMap(
1940
+ (other) => other.tasks.filter((t) => t.after.some((a) => a.change === change.id && crosses(t, other.id, a))).map((t) => `${other.id}/${t.track}`)
1941
+ );
1942
+ const kept = text ? { text, tracks: change.tasks.filter((t) => t.track !== "BE").map((t) => t.track), endedBy } : void 0;
1943
+ const byChange = /* @__PURE__ */ new Map();
1944
+ for (const a of work.after)
1945
+ if (crosses(work, change.id, a)) byChange.set(a.change, [...byChange.get(a.change) ?? [], a.track]);
1946
+ const ends = [...byChange].map(([c, tracks]) => ({ change: c, tracks }));
1947
+ return kept || ends.length ? { compatibility: { ...kept ? { kept } : {}, ...ends.length ? { ends } : {} } } : {};
1948
+ }
1949
+ function removedByOf(x, change, key) {
1950
+ if (x.sources.has(key)) return {};
1951
+ const h = history(x, key);
1952
+ const at = h.findIndex((e) => e.change === change);
1953
+ const gone = h.slice(at + 1).reverse().find((e) => e.entry.exported.before && !e.entry.exported.after);
1954
+ return gone && gone.change !== change ? { removedBy: gone.change } : {};
1955
+ }
1902
1956
  function taskContext(current, task, exportDir2, state = {}, questions, opts = {}) {
1903
1957
  const x = pinnedReader(current, task.change);
1904
1958
  const at = (path) => opts.pins && x.isPinned(path) ? `${opts.pins}/${path}` : path;
@@ -1951,7 +2005,8 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
1951
2005
  what: itemWhat(x, item, entries.get(itemObject(item)), task.track),
1952
2006
  ...covered ? { covered } : {},
1953
2007
  ...weight === void 0 ? {} : { weight },
1954
- ...labelOf(item) ? { label: labelOf(item) } : {}
2008
+ ...labelOf(item) ? { label: labelOf(item) } : {},
2009
+ ...weight === 0 ? removedByOf(current, task.change, itemObject(item)) : {}
1955
2010
  };
1956
2011
  }),
1957
2012
  known: state.covered !== void 0,
@@ -1969,6 +2024,8 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
1969
2024
  track,
1970
2025
  after: work.after,
1971
2026
  ...state.startFrom?.length ? { startFrom: state.startFrom } : {},
2027
+ ...state.siblings?.length ? { siblings: state.siblings } : {},
2028
+ ...compatibilityOf(x, change, work, proposal),
1972
2029
  proposal: {
1973
2030
  path: proposal,
1974
2031
  why: sectionText(x, x.sectionShard(proposal, "Why")),
@@ -2261,7 +2318,7 @@ function checklistSection(c) {
2261
2318
  ...list2.note ? ["", `Covered items unknown: ${list2.note}`] : [],
2262
2319
  "",
2263
2320
  ...list2.items.map(
2264
- (i) => `- [${i.weight === 0 ? "-" : i.covered ? "x" : " "}] \`${i.item}\`${i.weight === void 0 ? "" : i.weight === 0 ? " (w 0, nothing to build on this track)" : ` (w ${i.weight})`}: ${i.label ? `**${i.label}** \u2014 ` : ""}${i.what}${i.covered ? ` (covered by ${i.covered.slice(0, 12)})` : ""}`
2321
+ (i) => `- [${i.weight === 0 ? "-" : i.covered ? "x" : " "}] \`${i.item}\`${i.weight === void 0 ? "" : i.weight === 0 ? i.removedBy ? ` (w 0, removed by ${i.removedBy})` : " (w 0, nothing to build on this track)" : ` (w ${i.weight})`}: ${i.label ? `**${i.label}** \u2014 ` : ""}${i.what}${i.covered ? ` (covered by ${i.covered.slice(0, 12)})` : ""}`
2265
2322
  )
2266
2323
  );
2267
2324
  }
@@ -2273,6 +2330,7 @@ function renderChecklist(c) {
2273
2330
  "",
2274
2331
  ...c.summary ? [c.summary, ""] : [],
2275
2332
  ...c.weight === void 0 ? [] : [`Task weight ${c.weight} of 100.`, ""],
2333
+ ...shippedLines(c),
2276
2334
  ...c.questions?.length ? questionsSection(c.questions) : [],
2277
2335
  ...c.answers?.length ? answersSection(c.answers) : [],
2278
2336
  ...checklistSection(c),
@@ -2281,6 +2339,34 @@ function renderChecklist(c) {
2281
2339
  ];
2282
2340
  return out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
2283
2341
  }
2342
+ function shippedLines(c) {
2343
+ const out = [];
2344
+ const kept = c.compatibility?.kept;
2345
+ for (const s of c.siblings ?? []) {
2346
+ if (s.status === "done") {
2347
+ const where = [s.commit?.slice(0, 12), s.in_main_at ? "in main" : s.branch ?? "main"].filter(Boolean).join(", ");
2348
+ out.push(
2349
+ `**${s.track} has shipped this change** (${where})` + (kept ? ": the server keeps the old behaviour this change\u2019s Compatibility names until the other tracks\u2019 tasks are done (below)." : ": tests that check the behaviour it removes or changes are expected to fail until this task is done; updating them is part of this task."),
2350
+ ""
2351
+ );
2352
+ } else if (s.status === "in_progress") out.push(`${s.track} is building this change now.`, "");
2353
+ }
2354
+ if (kept) {
2355
+ const ended = kept.endedBy.length ? `${kept.endedBy.join(", ")} ends it.` : "The change that ends it is not signed off yet.";
2356
+ out.push(
2357
+ c.track.kind === "backend" ? `**Compatibility**: ${kept.tracks.join(", ")} build this change too; the server keeps what the proposal\u2019s Compatibility says until their tasks are done. ${ended}` : `**Compatibility**: the server keeps the old behaviour (${c.change.id}\u2019s Compatibility) until this task is done. ${ended}`,
2358
+ "",
2359
+ kept.text,
2360
+ ""
2361
+ );
2362
+ }
2363
+ for (const e of c.compatibility?.ends ?? [])
2364
+ out.push(
2365
+ `**Ends a compatibility**: this task ends the compatibility ${e.change} kept for ${e.tracks.join(", ")}; it is available once their tasks are done. When to deploy it is the team\u2019s call: old app versions stay in use after a task is done.`,
2366
+ ""
2367
+ );
2368
+ return out;
2369
+ }
2284
2370
  function renderContext(c) {
2285
2371
  const out = [
2286
2372
  `# ${c.task}: ${c.title ?? c.change.title}`,
@@ -2306,7 +2392,7 @@ function renderContext(c) {
2306
2392
  "",
2307
2393
  `Start from ${c.startFrom.map((s) => `\`${s.branch}\` (${s.id}${s.commit ? ` done at ${s.commit.slice(0, 12)}` : ""})`).join(", then ")}, not from the main branch: the predecessor's work is pushed there and not merged yet (fetch it and base your branch on \`origin/${c.startFrom[c.startFrom.length - 1].branch}\`).`
2308
2394
  );
2309
- out.push("");
2395
+ out.push("", ...shippedLines(c));
2310
2396
  if (c.questions?.length) out.push(...questionsSection(c.questions));
2311
2397
  if (c.answers?.length) out.push(...answersSection(c.answers));
2312
2398
  out.push(...checklistSection(c));
@@ -3776,6 +3862,7 @@ async function coveredState(loaded, task) {
3776
3862
  const items = answer.items ?? [];
3777
3863
  const answers = parseAnswers(answer.answers);
3778
3864
  const from = startFrom(task.track, answer.after);
3865
+ const siblings = parseSiblings(answer.siblings);
3779
3866
  return {
3780
3867
  covered: new Map(items.flatMap((i) => i.covered_commit ? [[i.item, i.covered_commit]] : [])),
3781
3868
  // The dispatcher's list is the checklist: its first item list stands (its spec, section 9), so the brief and
@@ -3788,7 +3875,8 @@ async function coveredState(loaded, task) {
3788
3875
  }))
3789
3876
  } : {},
3790
3877
  ...answers ? { answers } : {},
3791
- ...from.length ? { startFrom: from } : {}
3878
+ ...from.length ? { startFrom: from } : {},
3879
+ ...siblings?.length ? { siblings } : {}
3792
3880
  };
3793
3881
  } catch (e) {
3794
3882
  return { unknown: e.message.split("\n")[0] };