@mrciphersmith/keryx 0.4.52 → 0.4.53

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 (2) hide show
  1. package/dist/cli.js +161 -69
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -38284,7 +38284,7 @@ var package_default;
38284
38284
  var init_package = __esm(() => {
38285
38285
  package_default = {
38286
38286
  name: "@mrciphersmith/keryx",
38287
- version: "0.4.52",
38287
+ version: "0.4.53",
38288
38288
  description: "Version-controlled project context for AI coding agents: code graph, architecture wiki, project memory, relevant tests, quality signals, and task flows.",
38289
38289
  private: false,
38290
38290
  publishConfig: {
@@ -42536,15 +42536,15 @@ class V2Read {
42536
42536
  this.model = model;
42537
42537
  this.source = source;
42538
42538
  this.openEdges = openEdges;
42539
- this.base = { schemaVersion: METAPROJECT_SCHEMA_V2, snapshotId: hash3([model.base.snapshotId, source.catalog.snapshotId, model.graph, model.graphReason, openEdges, diagnostics]) };
42539
+ this.base = { schemaVersion: METAPROJECT_SCHEMA_V2, snapshotId: hash3([model.base.snapshotId, source.catalog.snapshotId, openEdges, diagnostics]) };
42540
42540
  this.state = sourceState(source, diagnostics);
42541
42541
  this.openNodes = source.catalog.entries.map(entryNode);
42542
42542
  }
42543
- read(request) {
42543
+ async read(request, freshness) {
42544
42544
  checkSnapshot2(this.base.snapshotId, request.expectedSnapshotId);
42545
42545
  switch (request.action) {
42546
42546
  case "catalog":
42547
- return this.catalog();
42547
+ return this.catalog(await freshness());
42548
42548
  case "detail":
42549
42549
  return this.detail(request);
42550
42550
  case "neighbors":
@@ -42557,8 +42557,8 @@ class V2Read {
42557
42557
  return this.history(request.id, request.cursor);
42558
42558
  }
42559
42559
  }
42560
- catalog() {
42561
- const { graph, graphReason, hasWikiLayer, hasSymbolLayer, counts } = this.model;
42560
+ catalog({ graph, graphReason }) {
42561
+ const { hasWikiLayer, hasSymbolLayer, counts } = this.model;
42562
42562
  const groups = [
42563
42563
  this.model.nodes.filter((node) => node.kind === "wiki"),
42564
42564
  this.model.nodes.filter((node) => node.kind !== "wiki"),
@@ -42703,14 +42703,14 @@ async function metaprojectExplorerV2(projectRoot, request, load) {
42703
42703
  return { schemaVersion: METAPROJECT_SCHEMA_V2, actions: METAPROJECT_CAPABILITIES };
42704
42704
  try {
42705
42705
  const root = await realpath12(projectRoot);
42706
- const [{ graph: loaded, confirm, track }, source] = await Promise.all([
42706
+ const [{ graph: loaded, freshness, confirm, track }, source] = await Promise.all([
42707
42707
  load(root, graphRequest(request)),
42708
42708
  readOpenSpec(root)
42709
42709
  ]);
42710
42710
  const graph = { ...loaded, nodes: loaded.nodes.filter(safeGraphNode) };
42711
42711
  const { edges, diagnostics } = await buildRelationships(source, graph, root, track);
42712
42712
  await confirm();
42713
- const response = new V2Read(graph, source, edges, diagnostics).read(request);
42713
+ const response = await new V2Read(graph, source, edges, diagnostics).read(request, freshness);
42714
42714
  if (bytes(response) + 1 > METAPROJECT_RESPONSE_BYTES_V2) {
42715
42715
  throw new MetaprojectRequestError("response-limit", "Metaproject response exceeds the byte limit.");
42716
42716
  }
@@ -42901,17 +42901,6 @@ async function loadExplorerGraph(root, request, observation) {
42901
42901
  edges.push({ from: page.node.id, to: found.id, kind: "links" });
42902
42902
  }
42903
42903
  }
42904
- let freshness = null;
42905
- if (graphPresent) {
42906
- try {
42907
- const provenance = ".metaproject/data/gdgraph/.provenance.json";
42908
- if (await exists(root, provenance))
42909
- await safeRead(root, provenance, 1024 * 1024);
42910
- freshness = await checkGraphStaleness(root);
42911
- } catch {
42912
- freshness = { status: "unknown", reasons: ["Graph provenance could not be read within the project"] };
42913
- }
42914
- }
42915
42904
  const layerStats = await Promise.all(["symbols.jsonl", "calls.jsonl", "wiki-pages.jsonl"].map(async (name) => {
42916
42905
  try {
42917
42906
  const relative = `${storage}/${name}`;
@@ -42952,8 +42941,6 @@ async function loadExplorerGraph(root, request, observation) {
42952
42941
  throw new Error("Symbol layer could not be read; rebuild the graph");
42953
42942
  }
42954
42943
  }
42955
- const graph = graphError ? "unknown" : freshness ? freshness.status === "fresh" ? "ready" : freshness.status : "missing";
42956
- const graphReason = graphError ?? freshness?.reasons.join("; ");
42957
42944
  return {
42958
42945
  base,
42959
42946
  nodes,
@@ -42961,26 +42948,44 @@ async function loadExplorerGraph(root, request, observation) {
42961
42948
  pages,
42962
42949
  hasSymbolLayer,
42963
42950
  hasWikiLayer,
42964
- graph,
42965
- graphReason,
42951
+ graphPresent,
42952
+ graphError,
42966
42953
  counts: { files: files.length, wiki: pages.length, modules: modules.size }
42967
42954
  };
42968
42955
  }
42956
+ async function explorerGraphFreshness(root, model) {
42957
+ if (model.graphError)
42958
+ return { graph: "unknown", graphReason: model.graphError };
42959
+ if (!model.graphPresent)
42960
+ return { graph: "missing" };
42961
+ let freshness;
42962
+ try {
42963
+ const provenance = ".metaproject/data/gdgraph/.provenance.json";
42964
+ if (await exists(root, provenance))
42965
+ await safeRead(root, provenance, 1024 * 1024);
42966
+ freshness = await checkGraphStaleness(root);
42967
+ } catch {
42968
+ freshness = { status: "unknown", reasons: ["Graph provenance could not be read within the project"] };
42969
+ }
42970
+ const graphReason = freshness.reasons.join("; ");
42971
+ return { graph: freshness.status === "fresh" ? "ready" : freshness.status, ...graphReason && { graphReason } };
42972
+ }
42969
42973
  async function metaprojectExplorer(projectRoot, request) {
42970
42974
  if ("version" in request) {
42971
42975
  return metaprojectExplorerV2(projectRoot, request, async (root, graphRequest) => {
42972
42976
  const observation = new ExplorerReadObservation(root);
42973
42977
  const graph = await loadExplorerGraph(root, graphRequest, observation);
42974
- return { graph, confirm: () => observation.confirm(), track: (target) => observation.track(target) };
42978
+ return { graph, freshness: () => explorerGraphFreshness(root, graph), confirm: () => observation.confirm(), track: (target) => observation.track(target) };
42975
42979
  });
42976
42980
  }
42977
- const model = await loadExplorerGraph(await realpath13(projectRoot), request);
42978
- const { base, nodes, edges, pages, graph, graphReason, hasSymbolLayer, hasWikiLayer, counts } = model;
42981
+ const root = await realpath13(projectRoot);
42982
+ const model = await loadExplorerGraph(root, request);
42983
+ const { base, nodes, edges, pages, hasSymbolLayer, hasWikiLayer, counts } = model;
42979
42984
  if (request.action === "catalog") {
42980
42985
  const boundedNodes = nodes.slice(0, CATALOG_NODES);
42981
42986
  const ids = new Set(boundedNodes.map((node) => node.id));
42982
42987
  const eligible = edges.filter((edge) => ids.has(edge.from) && ids.has(edge.to));
42983
- const catalog = { ...base, nodes: boundedNodes, edges: eligible.slice(0, CATALOG_EDGES), truncated: nodes.length > CATALOG_NODES || eligible.length > CATALOG_EDGES, graph, ...graphReason ? { graphReason } : {}, hasWikiLayer, hasSymbolLayer, counts };
42988
+ const catalog = { ...base, nodes: boundedNodes, edges: eligible.slice(0, CATALOG_EDGES), truncated: nodes.length > CATALOG_NODES || eligible.length > CATALOG_EDGES, ...await explorerGraphFreshness(root, model), hasWikiLayer, hasSymbolLayer, counts };
42984
42989
  return catalog;
42985
42990
  }
42986
42991
  if (request.action === "search") {
@@ -83781,17 +83786,21 @@ var init_desk_run_legacy = __esm(() => {
83781
83786
 
83782
83787
  // src/review/board-badges.ts
83783
83788
  function localBadge(runs, revision) {
83784
- runs = runs.filter((run) => run.decision?.action !== "archive" && run.decision?.action !== "delete");
83785
- const active = runs.filter((run) => run.source !== "existing" && runActive(run));
83789
+ runs = runs.filter((run) => run.source !== "existing" && run.decision?.action !== "archive" && run.decision?.action !== "delete");
83790
+ const active = runs.filter(runActive);
83786
83791
  const current = active.find((run) => sameRange(run, revision)) ?? active[0];
83787
- const latest = current ?? runs.find((run) => run.source !== "existing" && sameRange(run, revision));
83792
+ const latest = current ?? runs.find((run) => sameRange(run, revision));
83788
83793
  const same = !!latest && sameRange(latest, revision);
83789
83794
  const awaiting = latest?.awaitingAnswer ?? (latest?.pendingQuestions ? latest.pendingQuestions.length > 0 : !!latest?.pendingQuestion);
83790
83795
  const roster = same ? latest.reviewerProgress : undefined;
83796
+ const ready = runs.some((run) => runFinished(run) && !!run.result && sameRange(run.result.reviewed, revision));
83797
+ const stale = latest || ready ? undefined : runs.find((run) => runFinished(run) && !!run.result?.reviewed);
83798
+ const outdated = stale?.result?.reviewed ? { headSha: stale.result.reviewed.headSha, state: stale.state } : undefined;
83791
83799
  return {
83792
83800
  active: !!current,
83793
- ready: runs.some((run) => run.source !== "existing" && ["completed", "partial", "budget"].includes(run.state) && !!run.result && sameRange(run.result.reviewed, revision)),
83801
+ ready,
83794
83802
  ...latest ? { runState: same ? latest.state : "other-revision" } : {},
83803
+ ...outdated && { outdated },
83795
83804
  ...same && latest.state === "running" && latest.source === "manual" && awaiting && { awaitingAnswer: true },
83796
83805
  ...same && latest.publication === "pending" && sameRange(latest.result?.reviewed ?? null, revision) && { publicationPending: true },
83797
83806
  ...same && latest.state === "running" && latest.lastActivityAt && { lastActivityAt: latest.lastActivityAt },
@@ -83803,7 +83812,7 @@ function localBadge(runs, revision) {
83803
83812
  } } : {}
83804
83813
  };
83805
83814
  }
83806
- var runActive = (run) => run.state === "running" || run.state === "queued" || run.state === "cancelling", sameRange = (a, b) => a?.baseSha === b.baseSha && a.headSha === b.headSha;
83815
+ var runActive = (run) => run.state === "running" || run.state === "queued" || run.state === "cancelling", sameRange = (a, b) => a?.baseSha === b.baseSha && a.headSha === b.headSha, runFinished = (run) => run.state === "completed" || run.state === "partial" || run.state === "budget";
83807
83816
 
83808
83817
  // src/lib/hub-machine/errors.ts
83809
83818
  function machineFailure(cause, fallback = "machine-state-unavailable") {
@@ -84862,7 +84871,30 @@ Preview truncated. Full result: ` + path195.join(this.directory(run.id), "execut
84862
84871
  attachBadges(snapshot) {
84863
84872
  const tables = this.db.query("SELECT name FROM sqlite_schema WHERE type='table' AND name IN ('review_questions','reviewer_questions')").all();
84864
84873
  const pending = tables.map(({ name }) => `EXISTS(SELECT 1 FROM ${name} q WHERE q.run_id=r.id AND q.answer IS NULL)`).join(" OR ") || "0";
84874
+ const visible = (r) => `json_extract(${r}.details,'$.source') IN ('manual','scheduled')
84875
+ AND coalesce(json_extract(${r}.details,'$.decision.action'),'') NOT IN ('archive','delete')`;
84865
84876
  const query = this.db.query(`
84877
+ WITH scoped AS MATERIALIZED (
84878
+ SELECT w.key AS card, r.rowid AS seq, json_extract(r.details,'$.createdAt') AS created,
84879
+ r.state IN ('running','cancelling','queued') AS active, r.state IN ('completed','partial','budget') AS done,
84880
+ json_extract(r.details,'$.baseSha')=w.wb AND json_extract(r.details,'$.headSha')=w.wh AS requested,
84881
+ json_extract(r.details,'$.result.reviewed.baseSha') AS base,json_extract(r.details,'$.result.reviewed.headSha') AS head,
84882
+ w.wb, w.wh
84883
+ FROM (SELECT key,json_extract(value,'$.number') AS n,json_extract(value,'$.baseSha') AS wb,json_extract(value,'$.headSha') AS wh
84884
+ FROM json_each(?1)) w CROSS JOIN runs r
84885
+ WHERE r.repo=?2 AND r.viewer=?3 AND r.pr=w.n AND ${visible("r")}
84886
+ ), flagged AS (
84887
+ SELECT seq, created, card, coalesce(active OR requested,0) AS live, done, coalesce(base=wb AND head=wh,0) AS reviewed,
84888
+ done AND base IS NOT NULL AND head IS NOT NULL AS finished
84889
+ FROM scoped
84890
+ ), picked AS (
84891
+ SELECT seq, created, live OR reviewed AS kept, finished, live OR (done AND reviewed) AS supersedes, card
84892
+ FROM flagged
84893
+ ), ranked AS (
84894
+ SELECT seq, created, kept OR (finished AND NOT max(supersedes) OVER (PARTITION BY card) AND
84895
+ row_number() OVER (PARTITION BY card,finished ORDER BY created DESC,seq DESC)=1) AS wanted
84896
+ FROM picked
84897
+ )
84866
84898
  SELECT r.id, r.pr, CASE WHEN r.state='running' THEN ${pending} ELSE 0 END AS awaitingAnswer,
84867
84899
  CASE WHEN r.state='recoverable' THEN 'failed' ELSE r.state END AS state,
84868
84900
  json_extract(r.details,'$.source') AS source,
@@ -84880,23 +84912,20 @@ Preview truncated. Full result: ` + path195.join(this.directory(run.id), "execut
84880
84912
  FROM json_each(r.details,'$.reviewerProgress.sessions') s
84881
84913
  ) WHERE retry=1 AND outcome='completed'
84882
84914
  ) END) AS completed
84883
- FROM json_each(?) wanted CROSS JOIN runs r
84884
- WHERE r.repo=? AND r.viewer=? AND r.pr=json_extract(wanted.value,'$.number')
84885
- AND source IN ('manual','scheduled')
84886
- AND coalesce(json_extract(r.details,'$.decision.action'),'') NOT IN ('archive','delete') AND
84887
- (r.state IN ('running','cancelling','queued') OR
84888
- (baseSha=json_extract(wanted.value,'$.baseSha') AND headSha=json_extract(wanted.value,'$.headSha')) OR
84889
- (base=json_extract(wanted.value,'$.baseSha') AND head=json_extract(wanted.value,'$.headSha')))
84890
- ORDER BY json_extract(r.details,'$.createdAt') DESC,r.rowid DESC`);
84915
+ FROM ranked p JOIN runs r ON r.rowid=p.seq
84916
+ WHERE p.wanted
84917
+ ORDER BY p.created DESC,p.seq DESC`);
84891
84918
  for (let i = 0;i < snapshot.cards.length; i += 200) {
84892
84919
  const cards = snapshot.cards.slice(i, i + 200);
84893
84920
  const rows = query.all(JSON.stringify(cards.map(({ number, baseSha, headSha }) => ({ number, baseSha, headSha }))), snapshot.repositoryId, snapshot.viewer);
84894
84921
  const byPr = new Map;
84922
+ const cardByPr = new Map(cards.map((card) => [card.number, card]));
84895
84923
  for (const row of rows) {
84896
84924
  const runs = byPr.get(row.pr) ?? [];
84897
84925
  if (!runs.length)
84898
84926
  byPr.set(row.pr, runs);
84899
- const publication = row.base && row.head && this.publication(row.id, row.state, row.coverage);
84927
+ const card = cardByPr.get(row.pr);
84928
+ const publication = row.base && row.head && card?.baseSha === row.base && card.headSha === row.head && this.publication(row.id, row.state, row.coverage);
84900
84929
  runs.push({
84901
84930
  ...row,
84902
84931
  awaitingAnswer: !!row.awaitingAnswer,
@@ -371845,7 +371874,8 @@ function createHttpBotApi(options) {
371845
371874
  await call("answerCallbackQuery", body);
371846
371875
  },
371847
371876
  async getMe() {
371848
- return call("getMe", {});
371877
+ const { id, username } = await call("getMe", {});
371878
+ return username === undefined ? { id } : { id, username };
371849
371879
  },
371850
371880
  async getChat(params) {
371851
371881
  return call("getChat", { chat_id: params.chatId });
@@ -373996,7 +374026,7 @@ class UpdatePoller {
373996
374026
  try {
373997
374027
  updates = await this.api.getUpdates({
373998
374028
  ...confirm === undefined ? {} : { offset: confirm },
373999
- timeoutSec: this.timeoutSec,
374029
+ timeoutSec: this.resolveFirstPoll !== undefined && this.holdAfterFirstResponse !== undefined ? 0 : this.timeoutSec,
374000
374030
  signal
374001
374031
  });
374002
374032
  firstSuccess = this.resolveFirstPoll !== undefined;
@@ -376972,6 +377002,8 @@ class Pairing {
376972
377002
  bot;
376973
377003
  state = "waiting-for-user";
376974
377004
  code;
377005
+ forumCode;
377006
+ membership = { received: 0, last: "none" };
376975
377007
  expiresAt;
376976
377008
  ttlMs;
376977
377009
  earlyGroups = new Map;
@@ -376982,6 +377014,7 @@ class Pairing {
376982
377014
  problems = [];
376983
377015
  reason;
376984
377016
  candidate;
377017
+ candidateRequiresOperatorAdmin = false;
376985
377018
  poller;
376986
377019
  now;
376987
377020
  timers;
@@ -377047,6 +377080,8 @@ class Pairing {
377047
377080
  return {
377048
377081
  state: this.state,
377049
377082
  ...this.code === undefined ? {} : { code: this.code },
377083
+ ...this.forumCode === undefined ? {} : { forumCode: this.forumCode },
377084
+ ...this.options.requireConfirmation === true ? { membership: { ...this.membership } } : {},
377050
377085
  ...this.bot.username === undefined ? {} : { botUsername: this.bot.username },
377051
377086
  expiresAt: this.expiresAt,
377052
377087
  ...this.userId === undefined ? {} : { userId: this.userId },
@@ -377074,9 +377109,11 @@ class Pairing {
377074
377109
  if (this.state !== "waiting-for-confirmation" || this.userId === undefined)
377075
377110
  return;
377076
377111
  this.state = "waiting-for-group";
377112
+ this.forumCode = newPairingCode();
377077
377113
  this.expiresAt = this.now() + this.ttlMs;
377078
377114
  this.armExpiryTimer();
377079
377115
  confirmed = true;
377116
+ await this.replayGroupEvents();
377080
377117
  });
377081
377118
  return confirmed;
377082
377119
  }
@@ -377117,6 +377154,7 @@ class Pairing {
377117
377154
  this.state = state;
377118
377155
  if (FINAL.has(state)) {
377119
377156
  this.code = undefined;
377157
+ this.forumCode = undefined;
377120
377158
  if (this.expiryTimer !== undefined) {
377121
377159
  this.timers.clearTimeout(this.expiryTimer);
377122
377160
  this.expiryTimer = undefined;
@@ -377145,12 +377183,19 @@ class Pairing {
377145
377183
  this.expireIfDue();
377146
377184
  return;
377147
377185
  }
377186
+ if (update.my_chat_member !== undefined)
377187
+ this.membership.received += 1;
377148
377188
  if (this.state === "waiting-for-user") {
377149
377189
  if (this.options.requireConfirmation !== true)
377150
377190
  this.rememberGroupEvent(update);
377191
+ else if (update.my_chat_member !== undefined)
377192
+ this.membership.last = "before-claim";
377151
377193
  await this.takeCode(update);
377194
+ } else if (this.state === "waiting-for-confirmation") {
377195
+ this.deferGroupEvent(update);
377152
377196
  } else if (this.state === "waiting-for-group") {
377153
377197
  await this.takeGroup(update);
377198
+ await this.takeForumCommand(update);
377154
377199
  await this.takeMigration(update);
377155
377200
  }
377156
377201
  }
@@ -377185,6 +377230,9 @@ class Pairing {
377185
377230
  }).catch(() => {
377186
377231
  return;
377187
377232
  });
377233
+ await this.replayGroupEvents();
377234
+ }
377235
+ async replayGroupEvents() {
377188
377236
  const early = [...this.earlyGroups.values()];
377189
377237
  const earlyMoves = this.earlyMigrations;
377190
377238
  this.earlyGroups.clear();
@@ -377202,6 +377250,15 @@ class Pairing {
377202
377250
  await this.takeMigration(event);
377203
377251
  }
377204
377252
  }
377253
+ deferGroupEvent(update) {
377254
+ if (update.my_chat_member !== undefined) {
377255
+ const result = this.membershipResult(update.my_chat_member);
377256
+ this.membership.last = result === "inspecting" ? "deferred" : result;
377257
+ if (result !== "inspecting")
377258
+ return;
377259
+ }
377260
+ this.rememberGroupEvent(update);
377261
+ }
377205
377262
  rememberGroupEvent(update) {
377206
377263
  const message = update.message;
377207
377264
  if (message !== undefined && (typeof message.migrate_to_chat_id === "number" || typeof message.migrate_from_chat_id === "number")) {
@@ -377226,23 +377283,38 @@ class Pairing {
377226
377283
  }
377227
377284
  async takeGroup(update) {
377228
377285
  const change = update.my_chat_member;
377229
- if (change === undefined || change.from.id !== this.userId) {
377230
- return;
377231
- }
377232
- const type = change.chat.type;
377233
- if (type !== "group" && type !== "supergroup") {
377286
+ if (change === undefined)
377234
377287
  return;
377235
- }
377236
- const status = change.new_chat_member.status;
377237
- if (status !== "member" && status !== "administrator") {
377288
+ const result = this.membershipResult(change);
377289
+ this.membership.last = result;
377290
+ if (result !== "inspecting")
377238
377291
  return;
377239
- }
377240
377292
  this.candidate = change.chat.id;
377241
- if (change.chat.title !== undefined) {
377242
- this.chatTitle = change.chat.title;
377243
- }
377293
+ this.candidateRequiresOperatorAdmin = false;
377294
+ this.chatTitle = change.chat.title;
377244
377295
  await this.inspectGroup(change.chat.id);
377245
377296
  }
377297
+ membershipResult(change) {
377298
+ if (change.from.id !== this.userId)
377299
+ return "different-account";
377300
+ if (change.chat.type !== "group" && change.chat.type !== "supergroup")
377301
+ return "unsupported-chat";
377302
+ const role = change.new_chat_member.status;
377303
+ return role === "member" || role === "administrator" ? "inspecting" : "unsupported-role";
377304
+ }
377305
+ async takeForumCommand(update) {
377306
+ const message = update.message;
377307
+ if (this.state !== "waiting-for-group" || this.forumCode === undefined || message?.chat.type !== "supergroup" || message.from?.id !== this.userId || message.sender_chat !== undefined || message.forward_origin !== undefined || message.forward_date !== undefined || typeof message.text !== "string")
377308
+ return;
377309
+ const [command, code, extra] = message.text.trim().split(/\s+/);
377310
+ const addressed = this.bot.username && `/keryx_pair_forum@${this.bot.username.toLowerCase()}`;
377311
+ if (command?.toLowerCase() !== "/keryx_pair_forum" && command?.toLowerCase() !== addressed || code?.toUpperCase() !== this.forumCode || extra !== undefined)
377312
+ return;
377313
+ this.candidate = message.chat.id;
377314
+ this.candidateRequiresOperatorAdmin = true;
377315
+ this.chatTitle = undefined;
377316
+ await this.inspectGroup(message.chat.id);
377317
+ }
377246
377318
  async takeMigration(update) {
377247
377319
  const message = update.message;
377248
377320
  if (message === undefined || this.candidate === undefined || FINAL.has(this.state)) {
@@ -377279,6 +377351,12 @@ class Pairing {
377279
377351
  } else if (member.status === "administrator" && member.can_manage_topics !== true) {
377280
377352
  problems.push("Give the bot the Manage Topics right in the group's administrator settings.");
377281
377353
  }
377354
+ if (this.candidateRequiresOperatorAdmin && this.userId !== undefined && problems.length === 0) {
377355
+ const operator = await this.options.api.getChatMember({ chatId, userId: this.userId });
377356
+ if (operator.status !== "administrator" && operator.status !== "creator") {
377357
+ problems.push("The confirmed Telegram account must be an administrator of this forum.");
377358
+ }
377359
+ }
377282
377360
  } catch (error) {
377283
377361
  problems.push(`could not inspect the group: ${describe5(error)}`);
377284
377362
  }
@@ -377308,6 +377386,7 @@ var init_pairing = __esm(() => {
377308
377386
  class ChannelControl {
377309
377387
  options;
377310
377388
  fence;
377389
+ lastFailure;
377311
377390
  pending;
377312
377391
  constructor(options) {
377313
377392
  this.options = options;
@@ -377316,6 +377395,13 @@ class ChannelControl {
377316
377395
  pendingOperation() {
377317
377396
  return this.pending === undefined ? undefined : { operationId: this.pending.id, revision: this.pending.revision };
377318
377397
  }
377398
+ lastActivationFailure() {
377399
+ return this.lastFailure;
377400
+ }
377401
+ failActivation(reason) {
377402
+ this.lastFailure = { reason, at: Date.now() };
377403
+ return fail9(503, "activation-failed", reason);
377404
+ }
377319
377405
  async handle(request) {
377320
377406
  const body = await readJsonBody(request);
377321
377407
  if (!body.ok)
@@ -377458,22 +377544,26 @@ class ChannelControl {
377458
377544
  if (!sameBot && (!pairing.isReady() || snapshot.userId === undefined || snapshot.chatId === undefined) || token === undefined || api === undefined)
377459
377545
  return fail9(409, "pairing-incomplete", "Complete pairing before confirming.");
377460
377546
  this.pending.activating = true;
377461
- await pairing.stop();
377462
- const existing = loadChannelRecord(this.options.dir);
377463
- if (!existing.ok) {
377464
- this.clear(doc.operationId);
377465
- return fail9(503, "unavailable", existing.reason);
377466
- }
377467
- if (sameBot && (existing.value?.state !== "connected" || existing.value.bot?.id !== pairing.identity().id)) {
377547
+ try {
377548
+ await pairing.stop();
377549
+ const existing = loadChannelRecord(this.options.dir);
377550
+ if (!existing.ok)
377551
+ return this.failActivation(existing.reason);
377552
+ if (sameBot && (existing.value?.state !== "connected" || existing.value.bot?.id !== pairing.identity().id)) {
377553
+ this.lastFailure = { reason: "Channel identity changed.", at: Date.now() };
377554
+ return fail9(409, "conflict", this.lastFailure.reason);
377555
+ }
377556
+ const config = existing.value?.state === "connected" ? sameBot ? existing.value.config : { ...existing.value.config, chatId: snapshot.chatId, allowedUserIds: [snapshot.userId] } : { schemaVersion: REMOTE_CONFIG_SCHEMA_VERSION, chatId: snapshot.chatId, allowedUserIds: [snapshot.userId], orphanMs: DEFAULT_ORPHAN_MS, runTimeoutMs: DEFAULT_RUN_TIMEOUT_MS, permissionMode: DEFAULT_REMOTE_PERMISSION_MODE, approvalTimeoutMs: DEFAULT_APPROVAL_WAIT_MS };
377557
+ const result = await this.options.activate({ token, api, bot: pairing.identity(), config, expectedRevision: revision, stillOwned: () => this.fence.check(doc.operationId, revision).ok && this.pending?.pairing === pairing, stillActive: () => this.pending?.id === doc.operationId && this.pending?.pairing === pairing });
377558
+ if (!result.ok)
377559
+ return this.failActivation(result.reason);
377560
+ this.lastFailure = undefined;
377561
+ return ok4({ operationId: doc.operationId, revision: result.revision, state: "connected" });
377562
+ } catch {
377563
+ return this.failActivation("An unexpected local service error interrupted Telegram activation.");
377564
+ } finally {
377468
377565
  this.clear(doc.operationId);
377469
- return fail9(409, "conflict", "Channel identity changed.");
377470
377566
  }
377471
- const config = existing.value?.state === "connected" ? sameBot ? existing.value.config : { ...existing.value.config, chatId: snapshot.chatId, allowedUserIds: [snapshot.userId] } : { schemaVersion: REMOTE_CONFIG_SCHEMA_VERSION, chatId: snapshot.chatId, allowedUserIds: [snapshot.userId], orphanMs: DEFAULT_ORPHAN_MS, runTimeoutMs: DEFAULT_RUN_TIMEOUT_MS, permissionMode: DEFAULT_REMOTE_PERMISSION_MODE, approvalTimeoutMs: DEFAULT_APPROVAL_WAIT_MS };
377472
- const result = await this.options.activate({ token, api, bot: pairing.identity(), config, expectedRevision: revision, stillOwned: () => this.fence.check(doc.operationId, revision).ok && this.pending?.pairing === pairing, stillActive: () => this.pending?.id === doc.operationId && this.pending?.pairing === pairing });
377473
- this.clear(doc.operationId);
377474
- if (!result.ok)
377475
- return fail9(503, "activation-failed", result.reason);
377476
- return ok4({ operationId: doc.operationId, revision: result.revision, state: "connected" });
377477
377567
  }
377478
377568
  if (this.pending.sameBot)
377479
377569
  return ok4({ operationId: doc.operationId, revision, state: "same-bot-ready" });
@@ -377609,10 +377699,12 @@ class ChannelsController {
377609
377699
  if (record !== undefined && !record.ok)
377610
377700
  return fail9(503, "channel-record-invalid", record.reason);
377611
377701
  const pendingOperation = this.control?.pendingOperation();
377702
+ const lastActivationFailure = this.control?.lastActivationFailure();
377612
377703
  return ok4({
377613
377704
  machine: this.host.machine,
377614
377705
  ...record?.ok === true ? { capabilities: { desktopTelegram: 1 }, revision: record.value?.revision ?? null } : {},
377615
377706
  ...record !== undefined && pendingOperation !== undefined ? { pendingOperation } : {},
377707
+ ...lastActivationFailure === undefined ? {} : { lastActivationFailure },
377616
377708
  telegram: {
377617
377709
  state,
377618
377710
  ...reason === undefined ? {} : { reason },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrciphersmith/keryx",
3
- "version": "0.4.52",
3
+ "version": "0.4.53",
4
4
  "description": "Version-controlled project context for AI coding agents: code graph, architecture wiki, project memory, relevant tests, quality signals, and task flows.",
5
5
  "private": false,
6
6
  "publishConfig": {