@paigy/harness 0.3.13 → 0.3.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 (3) hide show
  1. package/dist/cli.js +485 -2838
  2. package/dist/main.js +485 -2838
  3. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -15,7 +15,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
15
15
  var __esm = (fn, res) => function __init() {
16
16
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
17
  };
18
- var __commonJS = (cb, mod) => function __require3() {
18
+ var __commonJS = (cb, mod) => function __require2() {
19
19
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
20
  };
21
21
  var __export = (target, all) => {
@@ -13412,11 +13412,11 @@ var require_readable = __commonJS({
13412
13412
  });
13413
13413
  }
13414
13414
  };
13415
- function isLocked(self2) {
13416
- return self2[kBody] && self2[kBody].locked === true || self2[kConsume];
13415
+ function isLocked(self) {
13416
+ return self[kBody] && self[kBody].locked === true || self[kConsume];
13417
13417
  }
13418
- function isUnusable(self2) {
13419
- return util2.isDisturbed(self2) || isLocked(self2);
13418
+ function isUnusable(self) {
13419
+ return util2.isDisturbed(self) || isLocked(self);
13420
13420
  }
13421
13421
  async function consume(stream, type) {
13422
13422
  assert(!stream[kConsume]);
@@ -13805,42 +13805,42 @@ var require_abort_signal = __commonJS({
13805
13805
  var { RequestAbortedError } = require_errors();
13806
13806
  var kListener = /* @__PURE__ */ Symbol("kListener");
13807
13807
  var kSignal = /* @__PURE__ */ Symbol("kSignal");
13808
- function abort(self2) {
13809
- if (self2.abort) {
13810
- self2.abort(self2[kSignal]?.reason);
13808
+ function abort(self) {
13809
+ if (self.abort) {
13810
+ self.abort(self[kSignal]?.reason);
13811
13811
  } else {
13812
- self2.reason = self2[kSignal]?.reason ?? new RequestAbortedError();
13812
+ self.reason = self[kSignal]?.reason ?? new RequestAbortedError();
13813
13813
  }
13814
- removeSignal(self2);
13814
+ removeSignal(self);
13815
13815
  }
13816
- function addSignal(self2, signal) {
13817
- self2.reason = null;
13818
- self2[kSignal] = null;
13819
- self2[kListener] = null;
13816
+ function addSignal(self, signal) {
13817
+ self.reason = null;
13818
+ self[kSignal] = null;
13819
+ self[kListener] = null;
13820
13820
  if (!signal) {
13821
13821
  return;
13822
13822
  }
13823
13823
  if (signal.aborted) {
13824
- abort(self2);
13824
+ abort(self);
13825
13825
  return;
13826
13826
  }
13827
- self2[kSignal] = signal;
13828
- self2[kListener] = () => {
13829
- abort(self2);
13827
+ self[kSignal] = signal;
13828
+ self[kListener] = () => {
13829
+ abort(self);
13830
13830
  };
13831
- addAbortListener(self2[kSignal], self2[kListener]);
13831
+ addAbortListener(self[kSignal], self[kListener]);
13832
13832
  }
13833
- function removeSignal(self2) {
13834
- if (!self2[kSignal]) {
13833
+ function removeSignal(self) {
13834
+ if (!self[kSignal]) {
13835
13835
  return;
13836
13836
  }
13837
- if ("removeEventListener" in self2[kSignal]) {
13838
- self2[kSignal].removeEventListener("abort", self2[kListener]);
13837
+ if ("removeEventListener" in self[kSignal]) {
13838
+ self[kSignal].removeEventListener("abort", self[kListener]);
13839
13839
  } else {
13840
- self2[kSignal].removeListener("abort", self2[kListener]);
13840
+ self[kSignal].removeListener("abort", self[kListener]);
13841
13841
  }
13842
- self2[kSignal] = null;
13843
- self2[kListener] = null;
13842
+ self[kSignal] = null;
13843
+ self[kListener] = null;
13844
13844
  }
13845
13845
  module.exports = {
13846
13846
  addSignal,
@@ -22744,22 +22744,54 @@ var require_undici = __commonJS({
22744
22744
 
22745
22745
  // ../../packages/sdk/dist/index.js
22746
22746
  import { createRequire as __sdkCreateRequire } from "module";
22747
+ import { execFileSync } from "child_process";
22747
22748
  import { createHash, randomUUID } from "crypto";
22749
+ import { readFileSync } from "fs";
22750
+ import { homedir as homedir2 } from "os";
22751
+ import { join as join2 } from "path";
22748
22752
  import { randomUUID as randomUUID3 } from "crypto";
22749
22753
  import { setTimeout as sleep2 } from "timers/promises";
22750
22754
  import { randomUUID as randomUUID2 } from "crypto";
22751
- import { closeSync, existsSync as existsSync2, mkdirSync, openSync, readFileSync, rmSync, statSync, writeFileSync } from "fs";
22752
- import { homedir as homedir2 } from "os";
22753
- import { join as join2 } from "path";
22755
+ import { closeSync, existsSync as existsSync2, mkdirSync, openSync, readFileSync as readFileSync2, rmSync, statSync, writeFileSync } from "fs";
22756
+ import { homedir as homedir22 } from "os";
22757
+ import { join as join22 } from "path";
22758
+ import { execFileSync as execFileSync2 } from "child_process";
22754
22759
  async function proxy() {
22755
22760
  if (!PROXY_ENV.some((k) => process.env[k])) return void 0;
22756
22761
  return agent ??= new (await Promise.resolve().then(() => __toESM(require_undici(), 1))).EnvHttpProxyAgent();
22757
22762
  }
22763
+ function parentOf(pid) {
22764
+ try {
22765
+ if (process.platform === "win32") return void 0;
22766
+ const ppid = process.platform === "linux" ? readFileSync(`/proc/${pid}/stat`, "utf8").split(") ")[1]?.split(" ")[1] : execFileSync("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf8", timeout: 1e3 });
22767
+ return Number(ppid?.trim()) || void 0;
22768
+ } catch {
22769
+ return void 0;
22770
+ }
22771
+ }
22772
+ function ancestors() {
22773
+ if (lineage) return lineage;
22774
+ lineage = [];
22775
+ for (let pid = process.ppid; pid && pid > 1 && lineage.length < 5; pid = parentOf(pid)) lineage.push(pid);
22776
+ return lineage;
22777
+ }
22778
+ function claudeConversation() {
22779
+ if (!envSession("CLAUDE_CODE_SESSION_ID") || process.env.CLAUDE_CODE_CHILD_SESSION) return void 0;
22780
+ const dir = envSession("CLAUDE_CONFIG_DIR") ?? join2(homedir2(), ".claude");
22781
+ for (const pid of ancestors()) {
22782
+ try {
22783
+ const { sessionId: sessionId2 } = JSON.parse(readFileSync(join2(dir, "sessions", `${pid}.json`), "utf8"));
22784
+ return typeof sessionId2 === "string" && sessionId2.trim() ? sessionId2 : void 0;
22785
+ } catch {
22786
+ }
22787
+ }
22788
+ return void 0;
22789
+ }
22758
22790
  function sessionId() {
22759
- return SESSION_ID;
22791
+ return envSession("PAIGY_SESSION_ID") ?? claudeConversation() ?? envSession("CLAUDE_CODE_SESSION_ID") ?? envSession("CODEX_THREAD_ID") ?? envSession("CODEX_SESSION_ID") ?? WORKSPACE_ID;
22760
22792
  }
22761
22793
  async function reach(url, init) {
22762
- return send(url, init, SESSION_ID);
22794
+ return send(url, init, sessionId());
22763
22795
  }
22764
22796
  function reachAs(session) {
22765
22797
  return (url, init) => send(url, init, session);
@@ -23654,69 +23686,17 @@ function mcpInputSchema(s) {
23654
23686
  delete schema.$schema;
23655
23687
  return draft2020(schema);
23656
23688
  }
23657
- function normalizeWaiting(req) {
23658
- if (!req.waiting) return req;
23659
- const { waiting, ...rest } = req;
23660
- return {
23661
- ...rest,
23662
- urgencyHint: req.urgencyHint ?? { none: "whenever", soft: "soon", hard: "now" }[waiting],
23663
- blocking: req.blocking || waiting === "hard"
23664
- };
23665
- }
23666
- function unitsOf(text) {
23667
- const spans = [];
23668
- const re = /\n\s*\n+/g;
23669
- let cursor = 0;
23670
- const push = (from, to) => {
23671
- const slice = text.slice(from, to);
23672
- const lead = slice.length - slice.trimStart().length;
23673
- const tail = slice.length - slice.trimEnd().length;
23674
- if (from + lead < to - tail) spans.push({ start: from + lead, end: to - tail });
23675
- };
23676
- for (let m = re.exec(text); m; m = re.exec(text)) {
23677
- push(cursor, m.index);
23678
- cursor = m.index + m[0].length;
23679
- }
23680
- push(cursor, text.length);
23681
- return spans;
23682
- }
23683
- function headline(text) {
23684
- const line = text.split("\n").map((l) => l.trim()).filter((l) => l && !/^`{3,}/.test(l)).map((l) => l.replace(/^(?:#{1,6}|[-*>]|\d{1,3}\.)\s+/, "")).find(Boolean) ?? "";
23685
- return (/^[^.!?\n]+[.!?]?/.exec(line)?.[0] ?? line).trim();
23686
- }
23687
- function bodyAfterHeadline(text) {
23688
- const body = text.trim();
23689
- const title = headline(body);
23690
- const rest = body.slice(title.length).replace(/^[\s.!?—–-]+/, "").trim();
23691
- if (!rest) return { title, description: [] };
23692
- const chunks = unitsOf(rest).map((u) => rest.slice(u.start, u.end)).filter(Boolean);
23693
- return { title, description: chunks.length ? chunks : [rest] };
23694
- }
23695
- function deriveAsk(req) {
23696
- req = normalizeWaiting(req);
23697
- if (!req.ask) return req;
23698
- const text = req.ask.trim();
23699
- const hinted = req.urgencyHint === "now" ? "call" : req.urgencyHint === "soon" ? "banner" : req.urgencyHint === "whenever" ? "inbox" : req.urgency;
23700
- const urgency = req.channel === "call" ? "call" : req.channel === "message" && hinted === "call" ? "banner" : hinted;
23701
- const { ask: _ask, needs, urgencyHint: _hint, channel: _channel, ...rest } = req;
23702
- return {
23703
- ...rest,
23704
- context: bodyAfterHeadline(text),
23705
- // Options riding alongside the ask (#575: pixels can't be prose) floor to a
23706
- // single pick — the model broker may upgrade to many/rank from the wording.
23707
- select: req.options?.length ? "one" : "text",
23708
- urgency,
23709
- ...needs?.length ? { points: needs } : {}
23710
- };
23711
- }
23712
23689
  function sessionSlot(sessionId2) {
23713
23690
  const id = sessionId2 ?? sessionId();
23714
23691
  return `session:${id.slice(0, 8)}`;
23715
23692
  }
23693
+ function agentName() {
23694
+ return process.env.PAIGY_AGENT || sessionSlot();
23695
+ }
23716
23696
  function readTokenFile() {
23717
23697
  if (!existsSync2(TOKEN_PATH)) return {};
23718
23698
  try {
23719
- const parsed = JSON.parse(readFileSync(TOKEN_PATH, "utf8"));
23699
+ const parsed = JSON.parse(readFileSync2(TOKEN_PATH, "utf8"));
23720
23700
  if (typeof parsed.access_token === "string") return {};
23721
23701
  const slots = parsed;
23722
23702
  delete slots["*"];
@@ -23728,7 +23708,7 @@ function readTokenFile() {
23728
23708
  function withTokenLock(mutate) {
23729
23709
  const lock = TOKEN_PATH + ".lock";
23730
23710
  const spin = new Int32Array(new SharedArrayBuffer(4));
23731
- mkdirSync(join2(homedir2(), ".paigy"), { recursive: true });
23711
+ mkdirSync(join22(homedir22(), ".paigy"), { recursive: true });
23732
23712
  for (const deadline = Date.now() + 5e3; Date.now() < deadline; ) {
23733
23713
  try {
23734
23714
  closeSync(openSync(lock, "wx"));
@@ -23745,7 +23725,7 @@ function withTokenLock(mutate) {
23745
23725
  rmSync(lock, { force: true });
23746
23726
  }
23747
23727
  }
23748
- function saveToken(token, agent2 = AGENT_NAME) {
23728
+ function saveToken(token, agent2 = agentName()) {
23749
23729
  withTokenLock(() => {
23750
23730
  const slots = { ...readTokenFile(), [agent2]: token };
23751
23731
  writeFileSync(TOKEN_PATH, JSON.stringify(slots, null, 2) + "\n", { mode: 384 });
@@ -23765,7 +23745,7 @@ function slotIdentity(agent2) {
23765
23745
  const t = readTokenFile()[agent2];
23766
23746
  return { name: t?.name ?? null, voice: t?.voice ?? null, tokenId: t?.token_id ?? null, workspace: t?.workspace ?? null };
23767
23747
  }
23768
- function readToken(agent2 = AGENT_NAME) {
23748
+ function readToken(agent2 = agentName()) {
23769
23749
  if (process.env.PAIGY_TOKEN) return process.env.PAIGY_TOKEN;
23770
23750
  return readTokenFile()[agent2]?.access_token ?? "";
23771
23751
  }
@@ -23775,24 +23755,23 @@ function listSlots() {
23775
23755
  function slotName(agent2) {
23776
23756
  return readTokenFile()[agent2]?.name ?? null;
23777
23757
  }
23778
- async function requestCode(suggestedName = AGENT_NAME, e2ee, device) {
23758
+ async function requestCode(suggestedName = agentName(), device) {
23779
23759
  const res = await reach(`${BACKEND_URL}/api/device/code`, {
23780
23760
  method: "POST",
23781
23761
  headers: { "content-type": "application/json" },
23782
23762
  body: JSON.stringify({
23783
23763
  suggestedName,
23784
- ...device ? { device } : {},
23785
- ...e2ee ? { proto: e2ee.proto, commitment: e2ee.commitment } : {}
23764
+ ...device ? { device } : {}
23786
23765
  })
23787
23766
  });
23788
23767
  if (!res.ok) throw new Error(`/api/device/code failed: ${res.status} ${await res.text()}`);
23789
23768
  return await res.json();
23790
23769
  }
23791
- async function pollToken(deviceCode, reveal) {
23770
+ async function pollToken(deviceCode) {
23792
23771
  const res = await reach(`${BACKEND_URL}/api/device/token`, {
23793
23772
  method: "POST",
23794
23773
  headers: { "content-type": "application/json" },
23795
- body: JSON.stringify(reveal ? { device_code: deviceCode, reveal } : { device_code: deviceCode })
23774
+ body: JSON.stringify({ device_code: deviceCode })
23796
23775
  });
23797
23776
  if (res.ok) return await res.json();
23798
23777
  const body = await res.json().catch(() => ({ error: "unknown" }));
@@ -23804,21 +23783,26 @@ async function pollToken(deviceCode, reveal) {
23804
23783
  if (err === "access_denied") throw new Error("Access denied by user. Pairing cancelled.");
23805
23784
  throw new Error(`Unexpected error from /api/device/token: ${err}`);
23806
23785
  }
23807
- function readKeyFile() {
23808
- if (!existsSync2(KEY_PATH)) return null;
23809
- try {
23810
- return JSON.parse(readFileSync(KEY_PATH, "utf8"));
23811
- } catch {
23812
- return null;
23813
- }
23814
- }
23815
23786
  function ensureAuthed(res) {
23816
23787
  if (res.status === 401) throw new UnpairedError();
23817
23788
  return res;
23818
23789
  }
23790
+ function overrideToken(secret) {
23791
+ tokenOverride = secret;
23792
+ }
23819
23793
  async function fail(what, res) {
23820
23794
  throw new ApiError(what, res.status, await res.text());
23821
23795
  }
23796
+ async function createGoal(input, opts = {}) {
23797
+ const token = authToken(opts.token) ?? "";
23798
+ const res = ensureAuthed(await (opts.reach ?? reach)(`${BACKEND_URL}/api/goals`, {
23799
+ method: "POST",
23800
+ headers: { "content-type": "application/json", authorization: `Bearer ${token}`, "x-paigy-model": "goal-entry-v1" },
23801
+ body: JSON.stringify(input)
23802
+ }));
23803
+ if (!res.ok) await fail("create_goal", res);
23804
+ return await res.json();
23805
+ }
23822
23806
  async function claimGoal(goalId, opts = {}) {
23823
23807
  const token = authToken(opts.token) ?? "";
23824
23808
  const res = ensureAuthed(await (opts.reach ?? reach)(`${BACKEND_URL}/api/goals/claim`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${token}`, "x-paigy-model": "goal-entry-v1" }, body: JSON.stringify(goalId ? { goalId } : {}) }));
@@ -23841,9 +23825,6 @@ async function updateGoal(goalId, input, opts = {}) {
23841
23825
  if (!res.ok) await fail("update_goal", res);
23842
23826
  return await res.json();
23843
23827
  }
23844
- function overrideToken(secret) {
23845
- tokenOverride = secret;
23846
- }
23847
23828
  async function hatch(name, voice = null) {
23848
23829
  const res = ensureAuthed(await reach(`${BACKEND_URL}/api/hatch`, {
23849
23830
  method: "POST",
@@ -23924,31 +23905,76 @@ async function acceptTriage(proposalId, body, opts = {}) {
23924
23905
  if (!res.ok) throw new Error(`accept_triage failed: ${res.status} ${await res.text()}`);
23925
23906
  return await res.json();
23926
23907
  }
23908
+ function repoFromRemote(url) {
23909
+ const said = (url ?? "").trim();
23910
+ if (!said) return null;
23911
+ const path = said.replace(/^[a-z+]+:\/\/[^/]+\//i, "").replace(/^[^@]+@[^:]+:/, "").replace(/\.git$/i, "").replace(/\/+$/, "");
23912
+ const parts = path.split("/").filter(Boolean);
23913
+ if (parts.length < 2) return null;
23914
+ const [owner, name] = parts.slice(-2);
23915
+ if (!owner || !name) return null;
23916
+ return `${owner}/${name}`.toLowerCase();
23917
+ }
23918
+ function currentRepo(cwd = process.cwd()) {
23919
+ if (asked !== void 0) return asked;
23920
+ try {
23921
+ const url = execFileSync2("git", ["remote", "get-url", "origin"], {
23922
+ cwd,
23923
+ encoding: "utf8",
23924
+ timeout: 2e3,
23925
+ stdio: ["ignore", "pipe", "ignore"]
23926
+ });
23927
+ asked = repoFromRemote(url);
23928
+ } catch {
23929
+ asked = null;
23930
+ }
23931
+ return asked;
23932
+ }
23927
23933
  async function contact(input, opts = {}) {
23928
23934
  const parsed = ContactSchema.parse(input);
23929
23935
  opts.signal?.throwIfAborted();
23930
23936
  const send22 = opts.reach ?? reach;
23931
23937
  const headers = { "content-type": "application/json", authorization: `Bearer ${authToken(opts.token) ?? ""}`, "x-paigy-model": "goal-entry-v1" };
23932
23938
  let deliveryId;
23933
- if ("deliveryId" in parsed) deliveryId = parsed.deliveryId;
23934
- else {
23935
- if (!opts.reach && readKeyFile()?.e2ee) throw new Error("Goal contact does not support E2EE yet; refusing to send plaintext.");
23936
- const shaped = deriveAsk(NotifyRequestSchema.parse({ ask: parsed.ask, waiting: parsed.waiting, options: parsed.options }));
23937
- const res = ensureAuthed(await send22(`${BACKEND_URL}/api/goals/${parsed.goalIds[0]}/contact`, {
23939
+ let deliveries = [];
23940
+ if ("deliveryId" in parsed) {
23941
+ deliveryId = parsed.deliveryId;
23942
+ } else {
23943
+ const reqAsks = parsed.asks.map((a) => ({
23944
+ id: a.id,
23945
+ parentId: a.parentId,
23946
+ // Derived, not asked for (#2315): the agent's own remote, in one spelling, so a project's
23947
+ // work does not grow three trees for "paigy", "mauurda/paigy" and "Paigy". An explicit one
23948
+ // still wins — normalised the same way — because a caller that names one knows something
23949
+ // this cannot see.
23950
+ repo: repoFromRemote(a.repo) ?? a.repo ?? currentRepo() ?? void 0,
23951
+ ask: a.ask,
23952
+ options: a.options ?? []
23953
+ }));
23954
+ const res = ensureAuthed(await send22(`${BACKEND_URL}/api/goals/contact`, {
23938
23955
  method: "POST",
23939
23956
  headers,
23940
23957
  signal: opts.signal,
23941
- body: JSON.stringify({ operationId: opts.operationId ?? randomUUID3(), threadId: parsed.threadId ?? null, content: parsed.ask, select: shaped.select, options: shaped.options ?? [], blocking: parsed.waiting === "hard", channel: parsed.channel === "call" ? "call" : "message" })
23958
+ body: JSON.stringify({
23959
+ operationId: opts.operationId ?? randomUUID3(),
23960
+ asks: reqAsks,
23961
+ waiting: parsed.waiting,
23962
+ channel: parsed.channel === "call" ? "call" : "message"
23963
+ })
23942
23964
  }));
23943
- if (!res.ok) await fail("goal contact", res);
23965
+ if (!res.ok) await fail("batch contact", res);
23944
23966
  const receipt = await res.json();
23945
- deliveryId = receipt.deliveryId ?? receipt.callId ?? receipt.notificationId ?? "";
23946
- if (!deliveryId) throw new Error("Goal contact returned no Delivery identity");
23967
+ deliveries = receipt.deliveries ?? [];
23968
+ if (deliveries.length === 0) throw new Error("Goal contact returned no Delivery identities");
23969
+ deliveryId = deliveries[0]?.deliveryId ?? "";
23970
+ if (!deliveryId) throw new Error("Goal contact returned no valid Delivery identity");
23947
23971
  }
23972
+ const all = deliveries.filter((d) => !!d.deliveryId && !!d.goalId);
23948
23973
  const read = async (signal2) => {
23949
23974
  const res = ensureAuthed(await send22(`${BACKEND_URL}/api/deliveries/${encodeURIComponent(deliveryId)}`, { headers, signal: signal2 }));
23950
23975
  if (!res.ok) await fail("read_delivery", res);
23951
- return await res.json();
23976
+ const one = await res.json();
23977
+ return all.length > 1 ? { ...one, deliveries: all } : one;
23952
23978
  };
23953
23979
  const settled = (d) => d.kind === "notification" || d.state === "closed" || d.answers.length > 0 || d.entries.some((e) => e.kind === "contribution");
23954
23980
  if (opts.waits === false) return read(opts.signal);
@@ -24048,7 +24074,8 @@ function subscribeRealtime(args) {
24048
24074
  };
24049
24075
  }
24050
24076
  async function subscribeWake(onNudge, opts = {}) {
24051
- const cfg = await registerDelivery("self_hosted", opts);
24077
+ const { release = true, ...client } = opts;
24078
+ const cfg = await registerDelivery("self_hosted", client);
24052
24079
  const { url, anonKey } = cfg.realtime;
24053
24080
  const channel = wakeChannel(cfg.tokenId);
24054
24081
  const ch = subscribeRealtime({
@@ -24063,2277 +24090,24 @@ async function subscribeWake(onNudge, opts = {}) {
24063
24090
  channel,
24064
24091
  close: async () => {
24065
24092
  ch.close();
24066
- await registerDelivery("poll", opts).catch(() => {
24093
+ if (release) await registerDelivery("poll", client).catch(() => {
24067
24094
  });
24068
24095
  }
24069
24096
  };
24070
24097
  }
24071
- var import_undici, require2, __create2, __defProp2, __getOwnPropDesc2, __getOwnPropNames2, __getProtoOf2, __hasOwnProp2, __require2, __commonJS2, __copyProps2, __toESM2, require_nacl_fast, BACKEND_URL, NETWORK_MSG, PROXY_ENV, agent, INSTANCE_ID, WORKSPACE_ID, envSession, SESSION_ID, ignoreOverride, defaultOptions, getDefaultOptions, getRefs, getRelativePath, parseCatchDef, integerDateParser, isJsonSchema7AllOfType, emojiRegex2, zodPatterns, ALPHA_NUMERIC, primitiveMappings, asAnyOf, parseOptionalDef, parsePipelineDef, parseReadonlyDef, selectParser, get$ref, addMeta, zodToJsonSchema, OPTIONS_MIN, OPTIONS_MAX, StartContactSchema, ContactSchema, CONTACT_SCHEMA, CONTACT_DESCRIPTION, CreateGoalSchema, CreateGoalToolSchema, CREATE_GOAL_DESCRIPTION, UpdateGoalSchema, UpdateGoalToolSchema, ClaimGoalSchema, GetGoalSchema, GET_GOAL_DESCRIPTION, UPDATE_GOAL_DESCRIPTION, CLAIM_GOAL_DESCRIPTION, CHECK_REPLIES_DESCRIPTION, CheckRepliesSchema, GetThreadSchema, GET_THREAD_DESCRIPTION, SearchThreadsSchema, SEARCH_THREADS_DESCRIPTION, AGENT_TOOLS, AGENT_TOOL_NAMES, LIVE_MS, ContextSchema, ParticipantSchema, TransformSchema, OptionSchema, VisualSchema, NotifyLevelSchema, SelectShapeSchema, ReceiptEventSchema, AttentionSchema, NotifyRequestFields, NotifyRequestSchema, NotifyStatusSchema, AgentStateSchema, TurnSchema, UserAnswerSchema, IntentSchema, RideAlongSchema, AwaitItemSchema, VoiceKeySchema, AgendaTurnSchema, CLAIM_STALE_MS, InboxItemSchema, APNS_TOKEN_RE, PushTokenSchema, MissedCallSchema, BrokerTuningSchema, UserSettingsSchema, HistoryItemSchema, ACTIVITY_LINES, ACTIVITY_LINE_MAX, AgentActivitySchema, ConnectionSummarySchema, LedgerItemSchema, AgentLedgerSchema, ReassignResultSchema, MoveRingSchema, MoveSchema, QueueQuestionSchema, QueueItemSchema, NoteSourceSchema, NoteStatusSchema, NoteRepeatSchema, DecisionSchema, NoteSchema, TriageItemSchema, TriageAssignmentSchema, TriageStatusSchema, SubmitTriageSchema, TriageProposalSchema, AcceptTriageSchema, AcceptTriageResultSchema, DeliveryModeSchema, WAKE_EVENT, wakeChannel, RegisterDeliverySchema, OAuthStartSchema, DeliveryConfigSchema, EnvelopeRecipientSchema, EnvelopeHeaderSchema, EnvelopeSchema, SealedAnswerSchema, DeviceCredentialSchema, DeviceRosterSchema, WakeNudgeSchema, PairingStatusSchema, PairingRevealSchema, DeviceCodeSchema, DeviceInfoSchema, DeviceTokenSchema, SupportRequestSchema, NotificationFeedbackKindSchema, FeedbackResolutionSchema, FeedbackOutcomeSchema, import_tweetnacl, import_tweetnacl2, import_tweetnacl3, import_tweetnacl4, import_tweetnacl5, AGENT_NAME, TOKEN_PATH, KEY_PATH, sleep, UnpairedError, ApiError, AWAIT_WINDOW_MS, tokenOverride, authToken, HEARTBEAT_MS, RETRY_MS, JOIN, lines;
24098
+ var import_undici, require2, BACKEND_URL, NETWORK_MSG, PROXY_ENV, agent, INSTANCE_ID, WORKSPACE_ID, envSession, lineage, ignoreOverride, defaultOptions, getDefaultOptions, getRefs, getRelativePath, parseCatchDef, integerDateParser, isJsonSchema7AllOfType, emojiRegex2, zodPatterns, ALPHA_NUMERIC, primitiveMappings, asAnyOf, parseOptionalDef, parsePipelineDef, parseReadonlyDef, selectParser, get$ref, addMeta, zodToJsonSchema, OPTIONS_MIN, OPTIONS_MAX, OptionSchema, OptionInputSchema, NIGHT, AskInputSchema, StartContactSchema, ContactSchema, CONTACT_SCHEMA, CONTACT_DESCRIPTION, CreateGoalSchema, CreateGoalToolSchema, CREATE_GOAL_DESCRIPTION, UpdateGoalSchema, UpdateGoalToolSchema, ClaimGoalSchema, GetGoalSchema, GET_GOAL_DESCRIPTION, UPDATE_GOAL_DESCRIPTION, CLAIM_GOAL_DESCRIPTION, CHECK_REPLIES_DESCRIPTION, CheckRepliesSchema, AGENT_TOOLS, AGENT_TOOL_NAMES, LIVE_MS, ContextSchema, ParticipantSchema, TransformSchema, VisualSchema, NotifyLevelSchema, SelectShapeSchema, ReceiptEventSchema, AttentionSchema, NotifyRequestFields, NotifyRequestSchema, NotifyStatusSchema, AgentStateSchema, TurnSchema, UserAnswerSchema, IntentSchema, RideAlongSchema, AwaitItemSchema, VoiceKeySchema, AgendaTurnSchema, CLAIM_STALE_MS, InboxItemSchema, APNS_TOKEN_RE, PushTokenSchema, MissedCallSchema, clock, QUIET, BrokerTuningSchema, UserSettingsSchema, HistoryItemSchema, ACTIVITY_LINES, ACTIVITY_LINE_MAX, AgentActivitySchema, ConnectionSummarySchema, LedgerItemSchema, AgentLedgerSchema, ReassignResultSchema, MoveRingSchema, MoveSchema, QueueQuestionSchema, QueueItemSchema, COLD_AFTER_MS, NoteSourceSchema, NoteStatusSchema, NoteRepeatSchema, DecisionSchema, NoteSchema, TriageItemSchema, TriageAssignmentSchema, TriageStatusSchema, SubmitTriageSchema, TriageProposalSchema, AcceptTriageSchema, AcceptTriageResultSchema, DeliveryModeSchema, WAKE_EVENT, wakeChannel, RegisterDeliverySchema, OAuthStartSchema, DeliveryConfigSchema, WakeNudgeSchema, PairingStatusSchema, DeviceCodeSchema, DeviceInfoSchema, DeviceTokenSchema, SupportRequestSchema, NotificationFeedbackKindSchema, TOKEN_PATH, KEY_PATH, sleep, UnpairedError, ApiError, tokenOverride, authToken, AWAIT_WINDOW_MS, asked, HEARTBEAT_MS, RETRY_MS, JOIN, lines;
24072
24099
  var init_dist = __esm({
24073
24100
  "../../packages/sdk/dist/index.js"() {
24074
24101
  "use strict";
24075
24102
  init_zod();
24076
24103
  init_zod();
24104
+ init_zod();
24077
24105
  init_v3();
24078
24106
  init_v3();
24079
24107
  init_v3();
24080
24108
  init_zod();
24081
24109
  import_undici = __toESM(require_undici(), 1);
24082
24110
  require2 = __sdkCreateRequire(import.meta.url);
24083
- __create2 = Object.create;
24084
- __defProp2 = Object.defineProperty;
24085
- __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
24086
- __getOwnPropNames2 = Object.getOwnPropertyNames;
24087
- __getProtoOf2 = Object.getPrototypeOf;
24088
- __hasOwnProp2 = Object.prototype.hasOwnProperty;
24089
- __require2 = /* @__PURE__ */ ((x) => typeof require2 !== "undefined" ? require2 : typeof Proxy !== "undefined" ? new Proxy(x, {
24090
- get: (a, b) => (typeof require2 !== "undefined" ? require2 : a)[b]
24091
- }) : x)(function(x) {
24092
- if (typeof require2 !== "undefined") return require2.apply(this, arguments);
24093
- throw Error('Dynamic require of "' + x + '" is not supported');
24094
- });
24095
- __commonJS2 = (cb, mod) => function __require22() {
24096
- return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
24097
- };
24098
- __copyProps2 = (to, from, except, desc) => {
24099
- if (from && typeof from === "object" || typeof from === "function") {
24100
- for (let key of __getOwnPropNames2(from))
24101
- if (!__hasOwnProp2.call(to, key) && key !== except)
24102
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
24103
- }
24104
- return to;
24105
- };
24106
- __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
24107
- // If the importer is in node compatibility mode or this is not an ESM
24108
- // file that has been converted to a CommonJS file using a Babel-
24109
- // compatible transform (i.e. "__esModule" has not been set), then set
24110
- // "default" to the CommonJS "module.exports" for node compatibility.
24111
- isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
24112
- mod
24113
- ));
24114
- require_nacl_fast = __commonJS2({
24115
- "../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js"(exports, module) {
24116
- "use strict";
24117
- (function(nacl6) {
24118
- "use strict";
24119
- var gf = function(init) {
24120
- var i, r = new Float64Array(16);
24121
- if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
24122
- return r;
24123
- };
24124
- var randombytes = function() {
24125
- throw new Error("no PRNG");
24126
- };
24127
- var _0 = new Uint8Array(16);
24128
- var _9 = new Uint8Array(32);
24129
- _9[0] = 9;
24130
- var gf0 = gf(), gf1 = gf([1]), _121665 = gf([56129, 1]), D = gf([30883, 4953, 19914, 30187, 55467, 16705, 2637, 112, 59544, 30585, 16505, 36039, 65139, 11119, 27886, 20995]), D2 = gf([61785, 9906, 39828, 60374, 45398, 33411, 5274, 224, 53552, 61171, 33010, 6542, 64743, 22239, 55772, 9222]), X = gf([54554, 36645, 11616, 51542, 42930, 38181, 51040, 26924, 56412, 64982, 57905, 49316, 21502, 52590, 14035, 8553]), Y = gf([26200, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214]), I = gf([41136, 18958, 6951, 50414, 58488, 44335, 6150, 12099, 55207, 15867, 153, 11085, 57099, 20417, 9344, 11139]);
24131
- function ts64(x, i, h, l) {
24132
- x[i] = h >> 24 & 255;
24133
- x[i + 1] = h >> 16 & 255;
24134
- x[i + 2] = h >> 8 & 255;
24135
- x[i + 3] = h & 255;
24136
- x[i + 4] = l >> 24 & 255;
24137
- x[i + 5] = l >> 16 & 255;
24138
- x[i + 6] = l >> 8 & 255;
24139
- x[i + 7] = l & 255;
24140
- }
24141
- function vn(x, xi, y, yi, n) {
24142
- var i, d = 0;
24143
- for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
24144
- return (1 & d - 1 >>> 8) - 1;
24145
- }
24146
- function crypto_verify_16(x, xi, y, yi) {
24147
- return vn(x, xi, y, yi, 16);
24148
- }
24149
- function crypto_verify_32(x, xi, y, yi) {
24150
- return vn(x, xi, y, yi, 32);
24151
- }
24152
- function core_salsa20(o, p, k, c) {
24153
- var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
24154
- var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, x15 = j15, u;
24155
- for (var i = 0; i < 20; i += 2) {
24156
- u = x0 + x12 | 0;
24157
- x4 ^= u << 7 | u >>> 32 - 7;
24158
- u = x4 + x0 | 0;
24159
- x8 ^= u << 9 | u >>> 32 - 9;
24160
- u = x8 + x4 | 0;
24161
- x12 ^= u << 13 | u >>> 32 - 13;
24162
- u = x12 + x8 | 0;
24163
- x0 ^= u << 18 | u >>> 32 - 18;
24164
- u = x5 + x1 | 0;
24165
- x9 ^= u << 7 | u >>> 32 - 7;
24166
- u = x9 + x5 | 0;
24167
- x13 ^= u << 9 | u >>> 32 - 9;
24168
- u = x13 + x9 | 0;
24169
- x1 ^= u << 13 | u >>> 32 - 13;
24170
- u = x1 + x13 | 0;
24171
- x5 ^= u << 18 | u >>> 32 - 18;
24172
- u = x10 + x6 | 0;
24173
- x14 ^= u << 7 | u >>> 32 - 7;
24174
- u = x14 + x10 | 0;
24175
- x2 ^= u << 9 | u >>> 32 - 9;
24176
- u = x2 + x14 | 0;
24177
- x6 ^= u << 13 | u >>> 32 - 13;
24178
- u = x6 + x2 | 0;
24179
- x10 ^= u << 18 | u >>> 32 - 18;
24180
- u = x15 + x11 | 0;
24181
- x3 ^= u << 7 | u >>> 32 - 7;
24182
- u = x3 + x15 | 0;
24183
- x7 ^= u << 9 | u >>> 32 - 9;
24184
- u = x7 + x3 | 0;
24185
- x11 ^= u << 13 | u >>> 32 - 13;
24186
- u = x11 + x7 | 0;
24187
- x15 ^= u << 18 | u >>> 32 - 18;
24188
- u = x0 + x3 | 0;
24189
- x1 ^= u << 7 | u >>> 32 - 7;
24190
- u = x1 + x0 | 0;
24191
- x2 ^= u << 9 | u >>> 32 - 9;
24192
- u = x2 + x1 | 0;
24193
- x3 ^= u << 13 | u >>> 32 - 13;
24194
- u = x3 + x2 | 0;
24195
- x0 ^= u << 18 | u >>> 32 - 18;
24196
- u = x5 + x4 | 0;
24197
- x6 ^= u << 7 | u >>> 32 - 7;
24198
- u = x6 + x5 | 0;
24199
- x7 ^= u << 9 | u >>> 32 - 9;
24200
- u = x7 + x6 | 0;
24201
- x4 ^= u << 13 | u >>> 32 - 13;
24202
- u = x4 + x7 | 0;
24203
- x5 ^= u << 18 | u >>> 32 - 18;
24204
- u = x10 + x9 | 0;
24205
- x11 ^= u << 7 | u >>> 32 - 7;
24206
- u = x11 + x10 | 0;
24207
- x8 ^= u << 9 | u >>> 32 - 9;
24208
- u = x8 + x11 | 0;
24209
- x9 ^= u << 13 | u >>> 32 - 13;
24210
- u = x9 + x8 | 0;
24211
- x10 ^= u << 18 | u >>> 32 - 18;
24212
- u = x15 + x14 | 0;
24213
- x12 ^= u << 7 | u >>> 32 - 7;
24214
- u = x12 + x15 | 0;
24215
- x13 ^= u << 9 | u >>> 32 - 9;
24216
- u = x13 + x12 | 0;
24217
- x14 ^= u << 13 | u >>> 32 - 13;
24218
- u = x14 + x13 | 0;
24219
- x15 ^= u << 18 | u >>> 32 - 18;
24220
- }
24221
- x0 = x0 + j0 | 0;
24222
- x1 = x1 + j1 | 0;
24223
- x2 = x2 + j2 | 0;
24224
- x3 = x3 + j3 | 0;
24225
- x4 = x4 + j4 | 0;
24226
- x5 = x5 + j5 | 0;
24227
- x6 = x6 + j6 | 0;
24228
- x7 = x7 + j7 | 0;
24229
- x8 = x8 + j8 | 0;
24230
- x9 = x9 + j9 | 0;
24231
- x10 = x10 + j10 | 0;
24232
- x11 = x11 + j11 | 0;
24233
- x12 = x12 + j12 | 0;
24234
- x13 = x13 + j13 | 0;
24235
- x14 = x14 + j14 | 0;
24236
- x15 = x15 + j15 | 0;
24237
- o[0] = x0 >>> 0 & 255;
24238
- o[1] = x0 >>> 8 & 255;
24239
- o[2] = x0 >>> 16 & 255;
24240
- o[3] = x0 >>> 24 & 255;
24241
- o[4] = x1 >>> 0 & 255;
24242
- o[5] = x1 >>> 8 & 255;
24243
- o[6] = x1 >>> 16 & 255;
24244
- o[7] = x1 >>> 24 & 255;
24245
- o[8] = x2 >>> 0 & 255;
24246
- o[9] = x2 >>> 8 & 255;
24247
- o[10] = x2 >>> 16 & 255;
24248
- o[11] = x2 >>> 24 & 255;
24249
- o[12] = x3 >>> 0 & 255;
24250
- o[13] = x3 >>> 8 & 255;
24251
- o[14] = x3 >>> 16 & 255;
24252
- o[15] = x3 >>> 24 & 255;
24253
- o[16] = x4 >>> 0 & 255;
24254
- o[17] = x4 >>> 8 & 255;
24255
- o[18] = x4 >>> 16 & 255;
24256
- o[19] = x4 >>> 24 & 255;
24257
- o[20] = x5 >>> 0 & 255;
24258
- o[21] = x5 >>> 8 & 255;
24259
- o[22] = x5 >>> 16 & 255;
24260
- o[23] = x5 >>> 24 & 255;
24261
- o[24] = x6 >>> 0 & 255;
24262
- o[25] = x6 >>> 8 & 255;
24263
- o[26] = x6 >>> 16 & 255;
24264
- o[27] = x6 >>> 24 & 255;
24265
- o[28] = x7 >>> 0 & 255;
24266
- o[29] = x7 >>> 8 & 255;
24267
- o[30] = x7 >>> 16 & 255;
24268
- o[31] = x7 >>> 24 & 255;
24269
- o[32] = x8 >>> 0 & 255;
24270
- o[33] = x8 >>> 8 & 255;
24271
- o[34] = x8 >>> 16 & 255;
24272
- o[35] = x8 >>> 24 & 255;
24273
- o[36] = x9 >>> 0 & 255;
24274
- o[37] = x9 >>> 8 & 255;
24275
- o[38] = x9 >>> 16 & 255;
24276
- o[39] = x9 >>> 24 & 255;
24277
- o[40] = x10 >>> 0 & 255;
24278
- o[41] = x10 >>> 8 & 255;
24279
- o[42] = x10 >>> 16 & 255;
24280
- o[43] = x10 >>> 24 & 255;
24281
- o[44] = x11 >>> 0 & 255;
24282
- o[45] = x11 >>> 8 & 255;
24283
- o[46] = x11 >>> 16 & 255;
24284
- o[47] = x11 >>> 24 & 255;
24285
- o[48] = x12 >>> 0 & 255;
24286
- o[49] = x12 >>> 8 & 255;
24287
- o[50] = x12 >>> 16 & 255;
24288
- o[51] = x12 >>> 24 & 255;
24289
- o[52] = x13 >>> 0 & 255;
24290
- o[53] = x13 >>> 8 & 255;
24291
- o[54] = x13 >>> 16 & 255;
24292
- o[55] = x13 >>> 24 & 255;
24293
- o[56] = x14 >>> 0 & 255;
24294
- o[57] = x14 >>> 8 & 255;
24295
- o[58] = x14 >>> 16 & 255;
24296
- o[59] = x14 >>> 24 & 255;
24297
- o[60] = x15 >>> 0 & 255;
24298
- o[61] = x15 >>> 8 & 255;
24299
- o[62] = x15 >>> 16 & 255;
24300
- o[63] = x15 >>> 24 & 255;
24301
- }
24302
- function core_hsalsa20(o, p, k, c) {
24303
- var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
24304
- var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, x15 = j15, u;
24305
- for (var i = 0; i < 20; i += 2) {
24306
- u = x0 + x12 | 0;
24307
- x4 ^= u << 7 | u >>> 32 - 7;
24308
- u = x4 + x0 | 0;
24309
- x8 ^= u << 9 | u >>> 32 - 9;
24310
- u = x8 + x4 | 0;
24311
- x12 ^= u << 13 | u >>> 32 - 13;
24312
- u = x12 + x8 | 0;
24313
- x0 ^= u << 18 | u >>> 32 - 18;
24314
- u = x5 + x1 | 0;
24315
- x9 ^= u << 7 | u >>> 32 - 7;
24316
- u = x9 + x5 | 0;
24317
- x13 ^= u << 9 | u >>> 32 - 9;
24318
- u = x13 + x9 | 0;
24319
- x1 ^= u << 13 | u >>> 32 - 13;
24320
- u = x1 + x13 | 0;
24321
- x5 ^= u << 18 | u >>> 32 - 18;
24322
- u = x10 + x6 | 0;
24323
- x14 ^= u << 7 | u >>> 32 - 7;
24324
- u = x14 + x10 | 0;
24325
- x2 ^= u << 9 | u >>> 32 - 9;
24326
- u = x2 + x14 | 0;
24327
- x6 ^= u << 13 | u >>> 32 - 13;
24328
- u = x6 + x2 | 0;
24329
- x10 ^= u << 18 | u >>> 32 - 18;
24330
- u = x15 + x11 | 0;
24331
- x3 ^= u << 7 | u >>> 32 - 7;
24332
- u = x3 + x15 | 0;
24333
- x7 ^= u << 9 | u >>> 32 - 9;
24334
- u = x7 + x3 | 0;
24335
- x11 ^= u << 13 | u >>> 32 - 13;
24336
- u = x11 + x7 | 0;
24337
- x15 ^= u << 18 | u >>> 32 - 18;
24338
- u = x0 + x3 | 0;
24339
- x1 ^= u << 7 | u >>> 32 - 7;
24340
- u = x1 + x0 | 0;
24341
- x2 ^= u << 9 | u >>> 32 - 9;
24342
- u = x2 + x1 | 0;
24343
- x3 ^= u << 13 | u >>> 32 - 13;
24344
- u = x3 + x2 | 0;
24345
- x0 ^= u << 18 | u >>> 32 - 18;
24346
- u = x5 + x4 | 0;
24347
- x6 ^= u << 7 | u >>> 32 - 7;
24348
- u = x6 + x5 | 0;
24349
- x7 ^= u << 9 | u >>> 32 - 9;
24350
- u = x7 + x6 | 0;
24351
- x4 ^= u << 13 | u >>> 32 - 13;
24352
- u = x4 + x7 | 0;
24353
- x5 ^= u << 18 | u >>> 32 - 18;
24354
- u = x10 + x9 | 0;
24355
- x11 ^= u << 7 | u >>> 32 - 7;
24356
- u = x11 + x10 | 0;
24357
- x8 ^= u << 9 | u >>> 32 - 9;
24358
- u = x8 + x11 | 0;
24359
- x9 ^= u << 13 | u >>> 32 - 13;
24360
- u = x9 + x8 | 0;
24361
- x10 ^= u << 18 | u >>> 32 - 18;
24362
- u = x15 + x14 | 0;
24363
- x12 ^= u << 7 | u >>> 32 - 7;
24364
- u = x12 + x15 | 0;
24365
- x13 ^= u << 9 | u >>> 32 - 9;
24366
- u = x13 + x12 | 0;
24367
- x14 ^= u << 13 | u >>> 32 - 13;
24368
- u = x14 + x13 | 0;
24369
- x15 ^= u << 18 | u >>> 32 - 18;
24370
- }
24371
- o[0] = x0 >>> 0 & 255;
24372
- o[1] = x0 >>> 8 & 255;
24373
- o[2] = x0 >>> 16 & 255;
24374
- o[3] = x0 >>> 24 & 255;
24375
- o[4] = x5 >>> 0 & 255;
24376
- o[5] = x5 >>> 8 & 255;
24377
- o[6] = x5 >>> 16 & 255;
24378
- o[7] = x5 >>> 24 & 255;
24379
- o[8] = x10 >>> 0 & 255;
24380
- o[9] = x10 >>> 8 & 255;
24381
- o[10] = x10 >>> 16 & 255;
24382
- o[11] = x10 >>> 24 & 255;
24383
- o[12] = x15 >>> 0 & 255;
24384
- o[13] = x15 >>> 8 & 255;
24385
- o[14] = x15 >>> 16 & 255;
24386
- o[15] = x15 >>> 24 & 255;
24387
- o[16] = x6 >>> 0 & 255;
24388
- o[17] = x6 >>> 8 & 255;
24389
- o[18] = x6 >>> 16 & 255;
24390
- o[19] = x6 >>> 24 & 255;
24391
- o[20] = x7 >>> 0 & 255;
24392
- o[21] = x7 >>> 8 & 255;
24393
- o[22] = x7 >>> 16 & 255;
24394
- o[23] = x7 >>> 24 & 255;
24395
- o[24] = x8 >>> 0 & 255;
24396
- o[25] = x8 >>> 8 & 255;
24397
- o[26] = x8 >>> 16 & 255;
24398
- o[27] = x8 >>> 24 & 255;
24399
- o[28] = x9 >>> 0 & 255;
24400
- o[29] = x9 >>> 8 & 255;
24401
- o[30] = x9 >>> 16 & 255;
24402
- o[31] = x9 >>> 24 & 255;
24403
- }
24404
- function crypto_core_salsa20(out, inp, k, c) {
24405
- core_salsa20(out, inp, k, c);
24406
- }
24407
- function crypto_core_hsalsa20(out, inp, k, c) {
24408
- core_hsalsa20(out, inp, k, c);
24409
- }
24410
- var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
24411
- function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
24412
- var z4 = new Uint8Array(16), x = new Uint8Array(64);
24413
- var u, i;
24414
- for (i = 0; i < 16; i++) z4[i] = 0;
24415
- for (i = 0; i < 8; i++) z4[i] = n[i];
24416
- while (b >= 64) {
24417
- crypto_core_salsa20(x, z4, k, sigma);
24418
- for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i];
24419
- u = 1;
24420
- for (i = 8; i < 16; i++) {
24421
- u = u + (z4[i] & 255) | 0;
24422
- z4[i] = u & 255;
24423
- u >>>= 8;
24424
- }
24425
- b -= 64;
24426
- cpos += 64;
24427
- mpos += 64;
24428
- }
24429
- if (b > 0) {
24430
- crypto_core_salsa20(x, z4, k, sigma);
24431
- for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i];
24432
- }
24433
- return 0;
24434
- }
24435
- function crypto_stream_salsa20(c, cpos, b, n, k) {
24436
- var z4 = new Uint8Array(16), x = new Uint8Array(64);
24437
- var u, i;
24438
- for (i = 0; i < 16; i++) z4[i] = 0;
24439
- for (i = 0; i < 8; i++) z4[i] = n[i];
24440
- while (b >= 64) {
24441
- crypto_core_salsa20(x, z4, k, sigma);
24442
- for (i = 0; i < 64; i++) c[cpos + i] = x[i];
24443
- u = 1;
24444
- for (i = 8; i < 16; i++) {
24445
- u = u + (z4[i] & 255) | 0;
24446
- z4[i] = u & 255;
24447
- u >>>= 8;
24448
- }
24449
- b -= 64;
24450
- cpos += 64;
24451
- }
24452
- if (b > 0) {
24453
- crypto_core_salsa20(x, z4, k, sigma);
24454
- for (i = 0; i < b; i++) c[cpos + i] = x[i];
24455
- }
24456
- return 0;
24457
- }
24458
- function crypto_stream(c, cpos, d, n, k) {
24459
- var s = new Uint8Array(32);
24460
- crypto_core_hsalsa20(s, n, k, sigma);
24461
- var sn = new Uint8Array(8);
24462
- for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
24463
- return crypto_stream_salsa20(c, cpos, d, sn, s);
24464
- }
24465
- function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
24466
- var s = new Uint8Array(32);
24467
- crypto_core_hsalsa20(s, n, k, sigma);
24468
- var sn = new Uint8Array(8);
24469
- for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
24470
- return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
24471
- }
24472
- var poly1305 = function(key) {
24473
- this.buffer = new Uint8Array(16);
24474
- this.r = new Uint16Array(10);
24475
- this.h = new Uint16Array(10);
24476
- this.pad = new Uint16Array(8);
24477
- this.leftover = 0;
24478
- this.fin = 0;
24479
- var t0, t1, t2, t3, t4, t5, t6, t7;
24480
- t0 = key[0] & 255 | (key[1] & 255) << 8;
24481
- this.r[0] = t0 & 8191;
24482
- t1 = key[2] & 255 | (key[3] & 255) << 8;
24483
- this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
24484
- t2 = key[4] & 255 | (key[5] & 255) << 8;
24485
- this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
24486
- t3 = key[6] & 255 | (key[7] & 255) << 8;
24487
- this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
24488
- t4 = key[8] & 255 | (key[9] & 255) << 8;
24489
- this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
24490
- this.r[5] = t4 >>> 1 & 8190;
24491
- t5 = key[10] & 255 | (key[11] & 255) << 8;
24492
- this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
24493
- t6 = key[12] & 255 | (key[13] & 255) << 8;
24494
- this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
24495
- t7 = key[14] & 255 | (key[15] & 255) << 8;
24496
- this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
24497
- this.r[9] = t7 >>> 5 & 127;
24498
- this.pad[0] = key[16] & 255 | (key[17] & 255) << 8;
24499
- this.pad[1] = key[18] & 255 | (key[19] & 255) << 8;
24500
- this.pad[2] = key[20] & 255 | (key[21] & 255) << 8;
24501
- this.pad[3] = key[22] & 255 | (key[23] & 255) << 8;
24502
- this.pad[4] = key[24] & 255 | (key[25] & 255) << 8;
24503
- this.pad[5] = key[26] & 255 | (key[27] & 255) << 8;
24504
- this.pad[6] = key[28] & 255 | (key[29] & 255) << 8;
24505
- this.pad[7] = key[30] & 255 | (key[31] & 255) << 8;
24506
- };
24507
- poly1305.prototype.blocks = function(m, mpos, bytes) {
24508
- var hibit = this.fin ? 0 : 1 << 11;
24509
- var t0, t1, t2, t3, t4, t5, t6, t7, c;
24510
- var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
24511
- var h0 = this.h[0], h1 = this.h[1], h2 = this.h[2], h3 = this.h[3], h4 = this.h[4], h5 = this.h[5], h6 = this.h[6], h7 = this.h[7], h8 = this.h[8], h9 = this.h[9];
24512
- var r0 = this.r[0], r1 = this.r[1], r2 = this.r[2], r3 = this.r[3], r4 = this.r[4], r5 = this.r[5], r6 = this.r[6], r7 = this.r[7], r8 = this.r[8], r9 = this.r[9];
24513
- while (bytes >= 16) {
24514
- t0 = m[mpos + 0] & 255 | (m[mpos + 1] & 255) << 8;
24515
- h0 += t0 & 8191;
24516
- t1 = m[mpos + 2] & 255 | (m[mpos + 3] & 255) << 8;
24517
- h1 += (t0 >>> 13 | t1 << 3) & 8191;
24518
- t2 = m[mpos + 4] & 255 | (m[mpos + 5] & 255) << 8;
24519
- h2 += (t1 >>> 10 | t2 << 6) & 8191;
24520
- t3 = m[mpos + 6] & 255 | (m[mpos + 7] & 255) << 8;
24521
- h3 += (t2 >>> 7 | t3 << 9) & 8191;
24522
- t4 = m[mpos + 8] & 255 | (m[mpos + 9] & 255) << 8;
24523
- h4 += (t3 >>> 4 | t4 << 12) & 8191;
24524
- h5 += t4 >>> 1 & 8191;
24525
- t5 = m[mpos + 10] & 255 | (m[mpos + 11] & 255) << 8;
24526
- h6 += (t4 >>> 14 | t5 << 2) & 8191;
24527
- t6 = m[mpos + 12] & 255 | (m[mpos + 13] & 255) << 8;
24528
- h7 += (t5 >>> 11 | t6 << 5) & 8191;
24529
- t7 = m[mpos + 14] & 255 | (m[mpos + 15] & 255) << 8;
24530
- h8 += (t6 >>> 8 | t7 << 8) & 8191;
24531
- h9 += t7 >>> 5 | hibit;
24532
- c = 0;
24533
- d0 = c;
24534
- d0 += h0 * r0;
24535
- d0 += h1 * (5 * r9);
24536
- d0 += h2 * (5 * r8);
24537
- d0 += h3 * (5 * r7);
24538
- d0 += h4 * (5 * r6);
24539
- c = d0 >>> 13;
24540
- d0 &= 8191;
24541
- d0 += h5 * (5 * r5);
24542
- d0 += h6 * (5 * r4);
24543
- d0 += h7 * (5 * r3);
24544
- d0 += h8 * (5 * r2);
24545
- d0 += h9 * (5 * r1);
24546
- c += d0 >>> 13;
24547
- d0 &= 8191;
24548
- d1 = c;
24549
- d1 += h0 * r1;
24550
- d1 += h1 * r0;
24551
- d1 += h2 * (5 * r9);
24552
- d1 += h3 * (5 * r8);
24553
- d1 += h4 * (5 * r7);
24554
- c = d1 >>> 13;
24555
- d1 &= 8191;
24556
- d1 += h5 * (5 * r6);
24557
- d1 += h6 * (5 * r5);
24558
- d1 += h7 * (5 * r4);
24559
- d1 += h8 * (5 * r3);
24560
- d1 += h9 * (5 * r2);
24561
- c += d1 >>> 13;
24562
- d1 &= 8191;
24563
- d2 = c;
24564
- d2 += h0 * r2;
24565
- d2 += h1 * r1;
24566
- d2 += h2 * r0;
24567
- d2 += h3 * (5 * r9);
24568
- d2 += h4 * (5 * r8);
24569
- c = d2 >>> 13;
24570
- d2 &= 8191;
24571
- d2 += h5 * (5 * r7);
24572
- d2 += h6 * (5 * r6);
24573
- d2 += h7 * (5 * r5);
24574
- d2 += h8 * (5 * r4);
24575
- d2 += h9 * (5 * r3);
24576
- c += d2 >>> 13;
24577
- d2 &= 8191;
24578
- d3 = c;
24579
- d3 += h0 * r3;
24580
- d3 += h1 * r2;
24581
- d3 += h2 * r1;
24582
- d3 += h3 * r0;
24583
- d3 += h4 * (5 * r9);
24584
- c = d3 >>> 13;
24585
- d3 &= 8191;
24586
- d3 += h5 * (5 * r8);
24587
- d3 += h6 * (5 * r7);
24588
- d3 += h7 * (5 * r6);
24589
- d3 += h8 * (5 * r5);
24590
- d3 += h9 * (5 * r4);
24591
- c += d3 >>> 13;
24592
- d3 &= 8191;
24593
- d4 = c;
24594
- d4 += h0 * r4;
24595
- d4 += h1 * r3;
24596
- d4 += h2 * r2;
24597
- d4 += h3 * r1;
24598
- d4 += h4 * r0;
24599
- c = d4 >>> 13;
24600
- d4 &= 8191;
24601
- d4 += h5 * (5 * r9);
24602
- d4 += h6 * (5 * r8);
24603
- d4 += h7 * (5 * r7);
24604
- d4 += h8 * (5 * r6);
24605
- d4 += h9 * (5 * r5);
24606
- c += d4 >>> 13;
24607
- d4 &= 8191;
24608
- d5 = c;
24609
- d5 += h0 * r5;
24610
- d5 += h1 * r4;
24611
- d5 += h2 * r3;
24612
- d5 += h3 * r2;
24613
- d5 += h4 * r1;
24614
- c = d5 >>> 13;
24615
- d5 &= 8191;
24616
- d5 += h5 * r0;
24617
- d5 += h6 * (5 * r9);
24618
- d5 += h7 * (5 * r8);
24619
- d5 += h8 * (5 * r7);
24620
- d5 += h9 * (5 * r6);
24621
- c += d5 >>> 13;
24622
- d5 &= 8191;
24623
- d6 = c;
24624
- d6 += h0 * r6;
24625
- d6 += h1 * r5;
24626
- d6 += h2 * r4;
24627
- d6 += h3 * r3;
24628
- d6 += h4 * r2;
24629
- c = d6 >>> 13;
24630
- d6 &= 8191;
24631
- d6 += h5 * r1;
24632
- d6 += h6 * r0;
24633
- d6 += h7 * (5 * r9);
24634
- d6 += h8 * (5 * r8);
24635
- d6 += h9 * (5 * r7);
24636
- c += d6 >>> 13;
24637
- d6 &= 8191;
24638
- d7 = c;
24639
- d7 += h0 * r7;
24640
- d7 += h1 * r6;
24641
- d7 += h2 * r5;
24642
- d7 += h3 * r4;
24643
- d7 += h4 * r3;
24644
- c = d7 >>> 13;
24645
- d7 &= 8191;
24646
- d7 += h5 * r2;
24647
- d7 += h6 * r1;
24648
- d7 += h7 * r0;
24649
- d7 += h8 * (5 * r9);
24650
- d7 += h9 * (5 * r8);
24651
- c += d7 >>> 13;
24652
- d7 &= 8191;
24653
- d8 = c;
24654
- d8 += h0 * r8;
24655
- d8 += h1 * r7;
24656
- d8 += h2 * r6;
24657
- d8 += h3 * r5;
24658
- d8 += h4 * r4;
24659
- c = d8 >>> 13;
24660
- d8 &= 8191;
24661
- d8 += h5 * r3;
24662
- d8 += h6 * r2;
24663
- d8 += h7 * r1;
24664
- d8 += h8 * r0;
24665
- d8 += h9 * (5 * r9);
24666
- c += d8 >>> 13;
24667
- d8 &= 8191;
24668
- d9 = c;
24669
- d9 += h0 * r9;
24670
- d9 += h1 * r8;
24671
- d9 += h2 * r7;
24672
- d9 += h3 * r6;
24673
- d9 += h4 * r5;
24674
- c = d9 >>> 13;
24675
- d9 &= 8191;
24676
- d9 += h5 * r4;
24677
- d9 += h6 * r3;
24678
- d9 += h7 * r2;
24679
- d9 += h8 * r1;
24680
- d9 += h9 * r0;
24681
- c += d9 >>> 13;
24682
- d9 &= 8191;
24683
- c = (c << 2) + c | 0;
24684
- c = c + d0 | 0;
24685
- d0 = c & 8191;
24686
- c = c >>> 13;
24687
- d1 += c;
24688
- h0 = d0;
24689
- h1 = d1;
24690
- h2 = d2;
24691
- h3 = d3;
24692
- h4 = d4;
24693
- h5 = d5;
24694
- h6 = d6;
24695
- h7 = d7;
24696
- h8 = d8;
24697
- h9 = d9;
24698
- mpos += 16;
24699
- bytes -= 16;
24700
- }
24701
- this.h[0] = h0;
24702
- this.h[1] = h1;
24703
- this.h[2] = h2;
24704
- this.h[3] = h3;
24705
- this.h[4] = h4;
24706
- this.h[5] = h5;
24707
- this.h[6] = h6;
24708
- this.h[7] = h7;
24709
- this.h[8] = h8;
24710
- this.h[9] = h9;
24711
- };
24712
- poly1305.prototype.finish = function(mac, macpos) {
24713
- var g = new Uint16Array(10);
24714
- var c, mask, f, i;
24715
- if (this.leftover) {
24716
- i = this.leftover;
24717
- this.buffer[i++] = 1;
24718
- for (; i < 16; i++) this.buffer[i] = 0;
24719
- this.fin = 1;
24720
- this.blocks(this.buffer, 0, 16);
24721
- }
24722
- c = this.h[1] >>> 13;
24723
- this.h[1] &= 8191;
24724
- for (i = 2; i < 10; i++) {
24725
- this.h[i] += c;
24726
- c = this.h[i] >>> 13;
24727
- this.h[i] &= 8191;
24728
- }
24729
- this.h[0] += c * 5;
24730
- c = this.h[0] >>> 13;
24731
- this.h[0] &= 8191;
24732
- this.h[1] += c;
24733
- c = this.h[1] >>> 13;
24734
- this.h[1] &= 8191;
24735
- this.h[2] += c;
24736
- g[0] = this.h[0] + 5;
24737
- c = g[0] >>> 13;
24738
- g[0] &= 8191;
24739
- for (i = 1; i < 10; i++) {
24740
- g[i] = this.h[i] + c;
24741
- c = g[i] >>> 13;
24742
- g[i] &= 8191;
24743
- }
24744
- g[9] -= 1 << 13;
24745
- mask = (c ^ 1) - 1;
24746
- for (i = 0; i < 10; i++) g[i] &= mask;
24747
- mask = ~mask;
24748
- for (i = 0; i < 10; i++) this.h[i] = this.h[i] & mask | g[i];
24749
- this.h[0] = (this.h[0] | this.h[1] << 13) & 65535;
24750
- this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535;
24751
- this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535;
24752
- this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535;
24753
- this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535;
24754
- this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535;
24755
- this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535;
24756
- this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535;
24757
- f = this.h[0] + this.pad[0];
24758
- this.h[0] = f & 65535;
24759
- for (i = 1; i < 8; i++) {
24760
- f = (this.h[i] + this.pad[i] | 0) + (f >>> 16) | 0;
24761
- this.h[i] = f & 65535;
24762
- }
24763
- mac[macpos + 0] = this.h[0] >>> 0 & 255;
24764
- mac[macpos + 1] = this.h[0] >>> 8 & 255;
24765
- mac[macpos + 2] = this.h[1] >>> 0 & 255;
24766
- mac[macpos + 3] = this.h[1] >>> 8 & 255;
24767
- mac[macpos + 4] = this.h[2] >>> 0 & 255;
24768
- mac[macpos + 5] = this.h[2] >>> 8 & 255;
24769
- mac[macpos + 6] = this.h[3] >>> 0 & 255;
24770
- mac[macpos + 7] = this.h[3] >>> 8 & 255;
24771
- mac[macpos + 8] = this.h[4] >>> 0 & 255;
24772
- mac[macpos + 9] = this.h[4] >>> 8 & 255;
24773
- mac[macpos + 10] = this.h[5] >>> 0 & 255;
24774
- mac[macpos + 11] = this.h[5] >>> 8 & 255;
24775
- mac[macpos + 12] = this.h[6] >>> 0 & 255;
24776
- mac[macpos + 13] = this.h[6] >>> 8 & 255;
24777
- mac[macpos + 14] = this.h[7] >>> 0 & 255;
24778
- mac[macpos + 15] = this.h[7] >>> 8 & 255;
24779
- };
24780
- poly1305.prototype.update = function(m, mpos, bytes) {
24781
- var i, want;
24782
- if (this.leftover) {
24783
- want = 16 - this.leftover;
24784
- if (want > bytes)
24785
- want = bytes;
24786
- for (i = 0; i < want; i++)
24787
- this.buffer[this.leftover + i] = m[mpos + i];
24788
- bytes -= want;
24789
- mpos += want;
24790
- this.leftover += want;
24791
- if (this.leftover < 16)
24792
- return;
24793
- this.blocks(this.buffer, 0, 16);
24794
- this.leftover = 0;
24795
- }
24796
- if (bytes >= 16) {
24797
- want = bytes - bytes % 16;
24798
- this.blocks(m, mpos, want);
24799
- mpos += want;
24800
- bytes -= want;
24801
- }
24802
- if (bytes) {
24803
- for (i = 0; i < bytes; i++)
24804
- this.buffer[this.leftover + i] = m[mpos + i];
24805
- this.leftover += bytes;
24806
- }
24807
- };
24808
- function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
24809
- var s = new poly1305(k);
24810
- s.update(m, mpos, n);
24811
- s.finish(out, outpos);
24812
- return 0;
24813
- }
24814
- function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
24815
- var x = new Uint8Array(16);
24816
- crypto_onetimeauth(x, 0, m, mpos, n, k);
24817
- return crypto_verify_16(h, hpos, x, 0);
24818
- }
24819
- function crypto_secretbox(c, m, d, n, k) {
24820
- var i;
24821
- if (d < 32) return -1;
24822
- crypto_stream_xor(c, 0, m, 0, d, n, k);
24823
- crypto_onetimeauth(c, 16, c, 32, d - 32, c);
24824
- for (i = 0; i < 16; i++) c[i] = 0;
24825
- return 0;
24826
- }
24827
- function crypto_secretbox_open(m, c, d, n, k) {
24828
- var i;
24829
- var x = new Uint8Array(32);
24830
- if (d < 32) return -1;
24831
- crypto_stream(x, 0, 32, n, k);
24832
- if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
24833
- crypto_stream_xor(m, 0, c, 0, d, n, k);
24834
- for (i = 0; i < 32; i++) m[i] = 0;
24835
- return 0;
24836
- }
24837
- function set25519(r, a) {
24838
- var i;
24839
- for (i = 0; i < 16; i++) r[i] = a[i] | 0;
24840
- }
24841
- function car25519(o) {
24842
- var i, v, c = 1;
24843
- for (i = 0; i < 16; i++) {
24844
- v = o[i] + c + 65535;
24845
- c = Math.floor(v / 65536);
24846
- o[i] = v - c * 65536;
24847
- }
24848
- o[0] += c - 1 + 37 * (c - 1);
24849
- }
24850
- function sel25519(p, q, b) {
24851
- var t, c = ~(b - 1);
24852
- for (var i = 0; i < 16; i++) {
24853
- t = c & (p[i] ^ q[i]);
24854
- p[i] ^= t;
24855
- q[i] ^= t;
24856
- }
24857
- }
24858
- function pack25519(o, n) {
24859
- var i, j, b;
24860
- var m = gf(), t = gf();
24861
- for (i = 0; i < 16; i++) t[i] = n[i];
24862
- car25519(t);
24863
- car25519(t);
24864
- car25519(t);
24865
- for (j = 0; j < 2; j++) {
24866
- m[0] = t[0] - 65517;
24867
- for (i = 1; i < 15; i++) {
24868
- m[i] = t[i] - 65535 - (m[i - 1] >> 16 & 1);
24869
- m[i - 1] &= 65535;
24870
- }
24871
- m[15] = t[15] - 32767 - (m[14] >> 16 & 1);
24872
- b = m[15] >> 16 & 1;
24873
- m[14] &= 65535;
24874
- sel25519(t, m, 1 - b);
24875
- }
24876
- for (i = 0; i < 16; i++) {
24877
- o[2 * i] = t[i] & 255;
24878
- o[2 * i + 1] = t[i] >> 8;
24879
- }
24880
- }
24881
- function neq25519(a, b) {
24882
- var c = new Uint8Array(32), d = new Uint8Array(32);
24883
- pack25519(c, a);
24884
- pack25519(d, b);
24885
- return crypto_verify_32(c, 0, d, 0);
24886
- }
24887
- function par25519(a) {
24888
- var d = new Uint8Array(32);
24889
- pack25519(d, a);
24890
- return d[0] & 1;
24891
- }
24892
- function unpack25519(o, n) {
24893
- var i;
24894
- for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
24895
- o[15] &= 32767;
24896
- }
24897
- function A(o, a, b) {
24898
- for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
24899
- }
24900
- function Z(o, a, b) {
24901
- for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
24902
- }
24903
- function M(o, a, b) {
24904
- var v, c, t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
24905
- v = a[0];
24906
- t0 += v * b0;
24907
- t1 += v * b1;
24908
- t2 += v * b2;
24909
- t3 += v * b3;
24910
- t4 += v * b4;
24911
- t5 += v * b5;
24912
- t6 += v * b6;
24913
- t7 += v * b7;
24914
- t8 += v * b8;
24915
- t9 += v * b9;
24916
- t10 += v * b10;
24917
- t11 += v * b11;
24918
- t12 += v * b12;
24919
- t13 += v * b13;
24920
- t14 += v * b14;
24921
- t15 += v * b15;
24922
- v = a[1];
24923
- t1 += v * b0;
24924
- t2 += v * b1;
24925
- t3 += v * b2;
24926
- t4 += v * b3;
24927
- t5 += v * b4;
24928
- t6 += v * b5;
24929
- t7 += v * b6;
24930
- t8 += v * b7;
24931
- t9 += v * b8;
24932
- t10 += v * b9;
24933
- t11 += v * b10;
24934
- t12 += v * b11;
24935
- t13 += v * b12;
24936
- t14 += v * b13;
24937
- t15 += v * b14;
24938
- t16 += v * b15;
24939
- v = a[2];
24940
- t2 += v * b0;
24941
- t3 += v * b1;
24942
- t4 += v * b2;
24943
- t5 += v * b3;
24944
- t6 += v * b4;
24945
- t7 += v * b5;
24946
- t8 += v * b6;
24947
- t9 += v * b7;
24948
- t10 += v * b8;
24949
- t11 += v * b9;
24950
- t12 += v * b10;
24951
- t13 += v * b11;
24952
- t14 += v * b12;
24953
- t15 += v * b13;
24954
- t16 += v * b14;
24955
- t17 += v * b15;
24956
- v = a[3];
24957
- t3 += v * b0;
24958
- t4 += v * b1;
24959
- t5 += v * b2;
24960
- t6 += v * b3;
24961
- t7 += v * b4;
24962
- t8 += v * b5;
24963
- t9 += v * b6;
24964
- t10 += v * b7;
24965
- t11 += v * b8;
24966
- t12 += v * b9;
24967
- t13 += v * b10;
24968
- t14 += v * b11;
24969
- t15 += v * b12;
24970
- t16 += v * b13;
24971
- t17 += v * b14;
24972
- t18 += v * b15;
24973
- v = a[4];
24974
- t4 += v * b0;
24975
- t5 += v * b1;
24976
- t6 += v * b2;
24977
- t7 += v * b3;
24978
- t8 += v * b4;
24979
- t9 += v * b5;
24980
- t10 += v * b6;
24981
- t11 += v * b7;
24982
- t12 += v * b8;
24983
- t13 += v * b9;
24984
- t14 += v * b10;
24985
- t15 += v * b11;
24986
- t16 += v * b12;
24987
- t17 += v * b13;
24988
- t18 += v * b14;
24989
- t19 += v * b15;
24990
- v = a[5];
24991
- t5 += v * b0;
24992
- t6 += v * b1;
24993
- t7 += v * b2;
24994
- t8 += v * b3;
24995
- t9 += v * b4;
24996
- t10 += v * b5;
24997
- t11 += v * b6;
24998
- t12 += v * b7;
24999
- t13 += v * b8;
25000
- t14 += v * b9;
25001
- t15 += v * b10;
25002
- t16 += v * b11;
25003
- t17 += v * b12;
25004
- t18 += v * b13;
25005
- t19 += v * b14;
25006
- t20 += v * b15;
25007
- v = a[6];
25008
- t6 += v * b0;
25009
- t7 += v * b1;
25010
- t8 += v * b2;
25011
- t9 += v * b3;
25012
- t10 += v * b4;
25013
- t11 += v * b5;
25014
- t12 += v * b6;
25015
- t13 += v * b7;
25016
- t14 += v * b8;
25017
- t15 += v * b9;
25018
- t16 += v * b10;
25019
- t17 += v * b11;
25020
- t18 += v * b12;
25021
- t19 += v * b13;
25022
- t20 += v * b14;
25023
- t21 += v * b15;
25024
- v = a[7];
25025
- t7 += v * b0;
25026
- t8 += v * b1;
25027
- t9 += v * b2;
25028
- t10 += v * b3;
25029
- t11 += v * b4;
25030
- t12 += v * b5;
25031
- t13 += v * b6;
25032
- t14 += v * b7;
25033
- t15 += v * b8;
25034
- t16 += v * b9;
25035
- t17 += v * b10;
25036
- t18 += v * b11;
25037
- t19 += v * b12;
25038
- t20 += v * b13;
25039
- t21 += v * b14;
25040
- t22 += v * b15;
25041
- v = a[8];
25042
- t8 += v * b0;
25043
- t9 += v * b1;
25044
- t10 += v * b2;
25045
- t11 += v * b3;
25046
- t12 += v * b4;
25047
- t13 += v * b5;
25048
- t14 += v * b6;
25049
- t15 += v * b7;
25050
- t16 += v * b8;
25051
- t17 += v * b9;
25052
- t18 += v * b10;
25053
- t19 += v * b11;
25054
- t20 += v * b12;
25055
- t21 += v * b13;
25056
- t22 += v * b14;
25057
- t23 += v * b15;
25058
- v = a[9];
25059
- t9 += v * b0;
25060
- t10 += v * b1;
25061
- t11 += v * b2;
25062
- t12 += v * b3;
25063
- t13 += v * b4;
25064
- t14 += v * b5;
25065
- t15 += v * b6;
25066
- t16 += v * b7;
25067
- t17 += v * b8;
25068
- t18 += v * b9;
25069
- t19 += v * b10;
25070
- t20 += v * b11;
25071
- t21 += v * b12;
25072
- t22 += v * b13;
25073
- t23 += v * b14;
25074
- t24 += v * b15;
25075
- v = a[10];
25076
- t10 += v * b0;
25077
- t11 += v * b1;
25078
- t12 += v * b2;
25079
- t13 += v * b3;
25080
- t14 += v * b4;
25081
- t15 += v * b5;
25082
- t16 += v * b6;
25083
- t17 += v * b7;
25084
- t18 += v * b8;
25085
- t19 += v * b9;
25086
- t20 += v * b10;
25087
- t21 += v * b11;
25088
- t22 += v * b12;
25089
- t23 += v * b13;
25090
- t24 += v * b14;
25091
- t25 += v * b15;
25092
- v = a[11];
25093
- t11 += v * b0;
25094
- t12 += v * b1;
25095
- t13 += v * b2;
25096
- t14 += v * b3;
25097
- t15 += v * b4;
25098
- t16 += v * b5;
25099
- t17 += v * b6;
25100
- t18 += v * b7;
25101
- t19 += v * b8;
25102
- t20 += v * b9;
25103
- t21 += v * b10;
25104
- t22 += v * b11;
25105
- t23 += v * b12;
25106
- t24 += v * b13;
25107
- t25 += v * b14;
25108
- t26 += v * b15;
25109
- v = a[12];
25110
- t12 += v * b0;
25111
- t13 += v * b1;
25112
- t14 += v * b2;
25113
- t15 += v * b3;
25114
- t16 += v * b4;
25115
- t17 += v * b5;
25116
- t18 += v * b6;
25117
- t19 += v * b7;
25118
- t20 += v * b8;
25119
- t21 += v * b9;
25120
- t22 += v * b10;
25121
- t23 += v * b11;
25122
- t24 += v * b12;
25123
- t25 += v * b13;
25124
- t26 += v * b14;
25125
- t27 += v * b15;
25126
- v = a[13];
25127
- t13 += v * b0;
25128
- t14 += v * b1;
25129
- t15 += v * b2;
25130
- t16 += v * b3;
25131
- t17 += v * b4;
25132
- t18 += v * b5;
25133
- t19 += v * b6;
25134
- t20 += v * b7;
25135
- t21 += v * b8;
25136
- t22 += v * b9;
25137
- t23 += v * b10;
25138
- t24 += v * b11;
25139
- t25 += v * b12;
25140
- t26 += v * b13;
25141
- t27 += v * b14;
25142
- t28 += v * b15;
25143
- v = a[14];
25144
- t14 += v * b0;
25145
- t15 += v * b1;
25146
- t16 += v * b2;
25147
- t17 += v * b3;
25148
- t18 += v * b4;
25149
- t19 += v * b5;
25150
- t20 += v * b6;
25151
- t21 += v * b7;
25152
- t22 += v * b8;
25153
- t23 += v * b9;
25154
- t24 += v * b10;
25155
- t25 += v * b11;
25156
- t26 += v * b12;
25157
- t27 += v * b13;
25158
- t28 += v * b14;
25159
- t29 += v * b15;
25160
- v = a[15];
25161
- t15 += v * b0;
25162
- t16 += v * b1;
25163
- t17 += v * b2;
25164
- t18 += v * b3;
25165
- t19 += v * b4;
25166
- t20 += v * b5;
25167
- t21 += v * b6;
25168
- t22 += v * b7;
25169
- t23 += v * b8;
25170
- t24 += v * b9;
25171
- t25 += v * b10;
25172
- t26 += v * b11;
25173
- t27 += v * b12;
25174
- t28 += v * b13;
25175
- t29 += v * b14;
25176
- t30 += v * b15;
25177
- t0 += 38 * t16;
25178
- t1 += 38 * t17;
25179
- t2 += 38 * t18;
25180
- t3 += 38 * t19;
25181
- t4 += 38 * t20;
25182
- t5 += 38 * t21;
25183
- t6 += 38 * t22;
25184
- t7 += 38 * t23;
25185
- t8 += 38 * t24;
25186
- t9 += 38 * t25;
25187
- t10 += 38 * t26;
25188
- t11 += 38 * t27;
25189
- t12 += 38 * t28;
25190
- t13 += 38 * t29;
25191
- t14 += 38 * t30;
25192
- c = 1;
25193
- v = t0 + c + 65535;
25194
- c = Math.floor(v / 65536);
25195
- t0 = v - c * 65536;
25196
- v = t1 + c + 65535;
25197
- c = Math.floor(v / 65536);
25198
- t1 = v - c * 65536;
25199
- v = t2 + c + 65535;
25200
- c = Math.floor(v / 65536);
25201
- t2 = v - c * 65536;
25202
- v = t3 + c + 65535;
25203
- c = Math.floor(v / 65536);
25204
- t3 = v - c * 65536;
25205
- v = t4 + c + 65535;
25206
- c = Math.floor(v / 65536);
25207
- t4 = v - c * 65536;
25208
- v = t5 + c + 65535;
25209
- c = Math.floor(v / 65536);
25210
- t5 = v - c * 65536;
25211
- v = t6 + c + 65535;
25212
- c = Math.floor(v / 65536);
25213
- t6 = v - c * 65536;
25214
- v = t7 + c + 65535;
25215
- c = Math.floor(v / 65536);
25216
- t7 = v - c * 65536;
25217
- v = t8 + c + 65535;
25218
- c = Math.floor(v / 65536);
25219
- t8 = v - c * 65536;
25220
- v = t9 + c + 65535;
25221
- c = Math.floor(v / 65536);
25222
- t9 = v - c * 65536;
25223
- v = t10 + c + 65535;
25224
- c = Math.floor(v / 65536);
25225
- t10 = v - c * 65536;
25226
- v = t11 + c + 65535;
25227
- c = Math.floor(v / 65536);
25228
- t11 = v - c * 65536;
25229
- v = t12 + c + 65535;
25230
- c = Math.floor(v / 65536);
25231
- t12 = v - c * 65536;
25232
- v = t13 + c + 65535;
25233
- c = Math.floor(v / 65536);
25234
- t13 = v - c * 65536;
25235
- v = t14 + c + 65535;
25236
- c = Math.floor(v / 65536);
25237
- t14 = v - c * 65536;
25238
- v = t15 + c + 65535;
25239
- c = Math.floor(v / 65536);
25240
- t15 = v - c * 65536;
25241
- t0 += c - 1 + 37 * (c - 1);
25242
- c = 1;
25243
- v = t0 + c + 65535;
25244
- c = Math.floor(v / 65536);
25245
- t0 = v - c * 65536;
25246
- v = t1 + c + 65535;
25247
- c = Math.floor(v / 65536);
25248
- t1 = v - c * 65536;
25249
- v = t2 + c + 65535;
25250
- c = Math.floor(v / 65536);
25251
- t2 = v - c * 65536;
25252
- v = t3 + c + 65535;
25253
- c = Math.floor(v / 65536);
25254
- t3 = v - c * 65536;
25255
- v = t4 + c + 65535;
25256
- c = Math.floor(v / 65536);
25257
- t4 = v - c * 65536;
25258
- v = t5 + c + 65535;
25259
- c = Math.floor(v / 65536);
25260
- t5 = v - c * 65536;
25261
- v = t6 + c + 65535;
25262
- c = Math.floor(v / 65536);
25263
- t6 = v - c * 65536;
25264
- v = t7 + c + 65535;
25265
- c = Math.floor(v / 65536);
25266
- t7 = v - c * 65536;
25267
- v = t8 + c + 65535;
25268
- c = Math.floor(v / 65536);
25269
- t8 = v - c * 65536;
25270
- v = t9 + c + 65535;
25271
- c = Math.floor(v / 65536);
25272
- t9 = v - c * 65536;
25273
- v = t10 + c + 65535;
25274
- c = Math.floor(v / 65536);
25275
- t10 = v - c * 65536;
25276
- v = t11 + c + 65535;
25277
- c = Math.floor(v / 65536);
25278
- t11 = v - c * 65536;
25279
- v = t12 + c + 65535;
25280
- c = Math.floor(v / 65536);
25281
- t12 = v - c * 65536;
25282
- v = t13 + c + 65535;
25283
- c = Math.floor(v / 65536);
25284
- t13 = v - c * 65536;
25285
- v = t14 + c + 65535;
25286
- c = Math.floor(v / 65536);
25287
- t14 = v - c * 65536;
25288
- v = t15 + c + 65535;
25289
- c = Math.floor(v / 65536);
25290
- t15 = v - c * 65536;
25291
- t0 += c - 1 + 37 * (c - 1);
25292
- o[0] = t0;
25293
- o[1] = t1;
25294
- o[2] = t2;
25295
- o[3] = t3;
25296
- o[4] = t4;
25297
- o[5] = t5;
25298
- o[6] = t6;
25299
- o[7] = t7;
25300
- o[8] = t8;
25301
- o[9] = t9;
25302
- o[10] = t10;
25303
- o[11] = t11;
25304
- o[12] = t12;
25305
- o[13] = t13;
25306
- o[14] = t14;
25307
- o[15] = t15;
25308
- }
25309
- function S(o, a) {
25310
- M(o, a, a);
25311
- }
25312
- function inv25519(o, i) {
25313
- var c = gf();
25314
- var a;
25315
- for (a = 0; a < 16; a++) c[a] = i[a];
25316
- for (a = 253; a >= 0; a--) {
25317
- S(c, c);
25318
- if (a !== 2 && a !== 4) M(c, c, i);
25319
- }
25320
- for (a = 0; a < 16; a++) o[a] = c[a];
25321
- }
25322
- function pow2523(o, i) {
25323
- var c = gf();
25324
- var a;
25325
- for (a = 0; a < 16; a++) c[a] = i[a];
25326
- for (a = 250; a >= 0; a--) {
25327
- S(c, c);
25328
- if (a !== 1) M(c, c, i);
25329
- }
25330
- for (a = 0; a < 16; a++) o[a] = c[a];
25331
- }
25332
- function crypto_scalarmult(q, n, p) {
25333
- var z4 = new Uint8Array(32);
25334
- var x = new Float64Array(80), r, i;
25335
- var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
25336
- for (i = 0; i < 31; i++) z4[i] = n[i];
25337
- z4[31] = n[31] & 127 | 64;
25338
- z4[0] &= 248;
25339
- unpack25519(x, p);
25340
- for (i = 0; i < 16; i++) {
25341
- b[i] = x[i];
25342
- d[i] = a[i] = c[i] = 0;
25343
- }
25344
- a[0] = d[0] = 1;
25345
- for (i = 254; i >= 0; --i) {
25346
- r = z4[i >>> 3] >>> (i & 7) & 1;
25347
- sel25519(a, b, r);
25348
- sel25519(c, d, r);
25349
- A(e, a, c);
25350
- Z(a, a, c);
25351
- A(c, b, d);
25352
- Z(b, b, d);
25353
- S(d, e);
25354
- S(f, a);
25355
- M(a, c, a);
25356
- M(c, b, e);
25357
- A(e, a, c);
25358
- Z(a, a, c);
25359
- S(b, a);
25360
- Z(c, d, f);
25361
- M(a, c, _121665);
25362
- A(a, a, d);
25363
- M(c, c, a);
25364
- M(a, d, f);
25365
- M(d, b, x);
25366
- S(b, e);
25367
- sel25519(a, b, r);
25368
- sel25519(c, d, r);
25369
- }
25370
- for (i = 0; i < 16; i++) {
25371
- x[i + 16] = a[i];
25372
- x[i + 32] = c[i];
25373
- x[i + 48] = b[i];
25374
- x[i + 64] = d[i];
25375
- }
25376
- var x32 = x.subarray(32);
25377
- var x16 = x.subarray(16);
25378
- inv25519(x32, x32);
25379
- M(x16, x16, x32);
25380
- pack25519(q, x16);
25381
- return 0;
25382
- }
25383
- function crypto_scalarmult_base(q, n) {
25384
- return crypto_scalarmult(q, n, _9);
25385
- }
25386
- function crypto_box_keypair(y, x) {
25387
- randombytes(x, 32);
25388
- return crypto_scalarmult_base(y, x);
25389
- }
25390
- function crypto_box_beforenm(k, y, x) {
25391
- var s = new Uint8Array(32);
25392
- crypto_scalarmult(s, x, y);
25393
- return crypto_core_hsalsa20(k, _0, s, sigma);
25394
- }
25395
- var crypto_box_afternm = crypto_secretbox;
25396
- var crypto_box_open_afternm = crypto_secretbox_open;
25397
- function crypto_box(c, m, d, n, y, x) {
25398
- var k = new Uint8Array(32);
25399
- crypto_box_beforenm(k, y, x);
25400
- return crypto_box_afternm(c, m, d, n, k);
25401
- }
25402
- function crypto_box_open(m, c, d, n, y, x) {
25403
- var k = new Uint8Array(32);
25404
- crypto_box_beforenm(k, y, x);
25405
- return crypto_box_open_afternm(m, c, d, n, k);
25406
- }
25407
- var K = [
25408
- 1116352408,
25409
- 3609767458,
25410
- 1899447441,
25411
- 602891725,
25412
- 3049323471,
25413
- 3964484399,
25414
- 3921009573,
25415
- 2173295548,
25416
- 961987163,
25417
- 4081628472,
25418
- 1508970993,
25419
- 3053834265,
25420
- 2453635748,
25421
- 2937671579,
25422
- 2870763221,
25423
- 3664609560,
25424
- 3624381080,
25425
- 2734883394,
25426
- 310598401,
25427
- 1164996542,
25428
- 607225278,
25429
- 1323610764,
25430
- 1426881987,
25431
- 3590304994,
25432
- 1925078388,
25433
- 4068182383,
25434
- 2162078206,
25435
- 991336113,
25436
- 2614888103,
25437
- 633803317,
25438
- 3248222580,
25439
- 3479774868,
25440
- 3835390401,
25441
- 2666613458,
25442
- 4022224774,
25443
- 944711139,
25444
- 264347078,
25445
- 2341262773,
25446
- 604807628,
25447
- 2007800933,
25448
- 770255983,
25449
- 1495990901,
25450
- 1249150122,
25451
- 1856431235,
25452
- 1555081692,
25453
- 3175218132,
25454
- 1996064986,
25455
- 2198950837,
25456
- 2554220882,
25457
- 3999719339,
25458
- 2821834349,
25459
- 766784016,
25460
- 2952996808,
25461
- 2566594879,
25462
- 3210313671,
25463
- 3203337956,
25464
- 3336571891,
25465
- 1034457026,
25466
- 3584528711,
25467
- 2466948901,
25468
- 113926993,
25469
- 3758326383,
25470
- 338241895,
25471
- 168717936,
25472
- 666307205,
25473
- 1188179964,
25474
- 773529912,
25475
- 1546045734,
25476
- 1294757372,
25477
- 1522805485,
25478
- 1396182291,
25479
- 2643833823,
25480
- 1695183700,
25481
- 2343527390,
25482
- 1986661051,
25483
- 1014477480,
25484
- 2177026350,
25485
- 1206759142,
25486
- 2456956037,
25487
- 344077627,
25488
- 2730485921,
25489
- 1290863460,
25490
- 2820302411,
25491
- 3158454273,
25492
- 3259730800,
25493
- 3505952657,
25494
- 3345764771,
25495
- 106217008,
25496
- 3516065817,
25497
- 3606008344,
25498
- 3600352804,
25499
- 1432725776,
25500
- 4094571909,
25501
- 1467031594,
25502
- 275423344,
25503
- 851169720,
25504
- 430227734,
25505
- 3100823752,
25506
- 506948616,
25507
- 1363258195,
25508
- 659060556,
25509
- 3750685593,
25510
- 883997877,
25511
- 3785050280,
25512
- 958139571,
25513
- 3318307427,
25514
- 1322822218,
25515
- 3812723403,
25516
- 1537002063,
25517
- 2003034995,
25518
- 1747873779,
25519
- 3602036899,
25520
- 1955562222,
25521
- 1575990012,
25522
- 2024104815,
25523
- 1125592928,
25524
- 2227730452,
25525
- 2716904306,
25526
- 2361852424,
25527
- 442776044,
25528
- 2428436474,
25529
- 593698344,
25530
- 2756734187,
25531
- 3733110249,
25532
- 3204031479,
25533
- 2999351573,
25534
- 3329325298,
25535
- 3815920427,
25536
- 3391569614,
25537
- 3928383900,
25538
- 3515267271,
25539
- 566280711,
25540
- 3940187606,
25541
- 3454069534,
25542
- 4118630271,
25543
- 4000239992,
25544
- 116418474,
25545
- 1914138554,
25546
- 174292421,
25547
- 2731055270,
25548
- 289380356,
25549
- 3203993006,
25550
- 460393269,
25551
- 320620315,
25552
- 685471733,
25553
- 587496836,
25554
- 852142971,
25555
- 1086792851,
25556
- 1017036298,
25557
- 365543100,
25558
- 1126000580,
25559
- 2618297676,
25560
- 1288033470,
25561
- 3409855158,
25562
- 1501505948,
25563
- 4234509866,
25564
- 1607167915,
25565
- 987167468,
25566
- 1816402316,
25567
- 1246189591
25568
- ];
25569
- function crypto_hashblocks_hl(hh, hl, m, n) {
25570
- var wh = new Int32Array(16), wl = new Int32Array(16), bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, th, tl, i, j, h, l, a, b, c, d;
25571
- var ah0 = hh[0], ah1 = hh[1], ah2 = hh[2], ah3 = hh[3], ah4 = hh[4], ah5 = hh[5], ah6 = hh[6], ah7 = hh[7], al0 = hl[0], al1 = hl[1], al2 = hl[2], al3 = hl[3], al4 = hl[4], al5 = hl[5], al6 = hl[6], al7 = hl[7];
25572
- var pos = 0;
25573
- while (n >= 128) {
25574
- for (i = 0; i < 16; i++) {
25575
- j = 8 * i + pos;
25576
- wh[i] = m[j + 0] << 24 | m[j + 1] << 16 | m[j + 2] << 8 | m[j + 3];
25577
- wl[i] = m[j + 4] << 24 | m[j + 5] << 16 | m[j + 6] << 8 | m[j + 7];
25578
- }
25579
- for (i = 0; i < 80; i++) {
25580
- bh0 = ah0;
25581
- bh1 = ah1;
25582
- bh2 = ah2;
25583
- bh3 = ah3;
25584
- bh4 = ah4;
25585
- bh5 = ah5;
25586
- bh6 = ah6;
25587
- bh7 = ah7;
25588
- bl0 = al0;
25589
- bl1 = al1;
25590
- bl2 = al2;
25591
- bl3 = al3;
25592
- bl4 = al4;
25593
- bl5 = al5;
25594
- bl6 = al6;
25595
- bl7 = al7;
25596
- h = ah7;
25597
- l = al7;
25598
- a = l & 65535;
25599
- b = l >>> 16;
25600
- c = h & 65535;
25601
- d = h >>> 16;
25602
- h = (ah4 >>> 14 | al4 << 32 - 14) ^ (ah4 >>> 18 | al4 << 32 - 18) ^ (al4 >>> 41 - 32 | ah4 << 32 - (41 - 32));
25603
- l = (al4 >>> 14 | ah4 << 32 - 14) ^ (al4 >>> 18 | ah4 << 32 - 18) ^ (ah4 >>> 41 - 32 | al4 << 32 - (41 - 32));
25604
- a += l & 65535;
25605
- b += l >>> 16;
25606
- c += h & 65535;
25607
- d += h >>> 16;
25608
- h = ah4 & ah5 ^ ~ah4 & ah6;
25609
- l = al4 & al5 ^ ~al4 & al6;
25610
- a += l & 65535;
25611
- b += l >>> 16;
25612
- c += h & 65535;
25613
- d += h >>> 16;
25614
- h = K[i * 2];
25615
- l = K[i * 2 + 1];
25616
- a += l & 65535;
25617
- b += l >>> 16;
25618
- c += h & 65535;
25619
- d += h >>> 16;
25620
- h = wh[i % 16];
25621
- l = wl[i % 16];
25622
- a += l & 65535;
25623
- b += l >>> 16;
25624
- c += h & 65535;
25625
- d += h >>> 16;
25626
- b += a >>> 16;
25627
- c += b >>> 16;
25628
- d += c >>> 16;
25629
- th = c & 65535 | d << 16;
25630
- tl = a & 65535 | b << 16;
25631
- h = th;
25632
- l = tl;
25633
- a = l & 65535;
25634
- b = l >>> 16;
25635
- c = h & 65535;
25636
- d = h >>> 16;
25637
- h = (ah0 >>> 28 | al0 << 32 - 28) ^ (al0 >>> 34 - 32 | ah0 << 32 - (34 - 32)) ^ (al0 >>> 39 - 32 | ah0 << 32 - (39 - 32));
25638
- l = (al0 >>> 28 | ah0 << 32 - 28) ^ (ah0 >>> 34 - 32 | al0 << 32 - (34 - 32)) ^ (ah0 >>> 39 - 32 | al0 << 32 - (39 - 32));
25639
- a += l & 65535;
25640
- b += l >>> 16;
25641
- c += h & 65535;
25642
- d += h >>> 16;
25643
- h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
25644
- l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
25645
- a += l & 65535;
25646
- b += l >>> 16;
25647
- c += h & 65535;
25648
- d += h >>> 16;
25649
- b += a >>> 16;
25650
- c += b >>> 16;
25651
- d += c >>> 16;
25652
- bh7 = c & 65535 | d << 16;
25653
- bl7 = a & 65535 | b << 16;
25654
- h = bh3;
25655
- l = bl3;
25656
- a = l & 65535;
25657
- b = l >>> 16;
25658
- c = h & 65535;
25659
- d = h >>> 16;
25660
- h = th;
25661
- l = tl;
25662
- a += l & 65535;
25663
- b += l >>> 16;
25664
- c += h & 65535;
25665
- d += h >>> 16;
25666
- b += a >>> 16;
25667
- c += b >>> 16;
25668
- d += c >>> 16;
25669
- bh3 = c & 65535 | d << 16;
25670
- bl3 = a & 65535 | b << 16;
25671
- ah1 = bh0;
25672
- ah2 = bh1;
25673
- ah3 = bh2;
25674
- ah4 = bh3;
25675
- ah5 = bh4;
25676
- ah6 = bh5;
25677
- ah7 = bh6;
25678
- ah0 = bh7;
25679
- al1 = bl0;
25680
- al2 = bl1;
25681
- al3 = bl2;
25682
- al4 = bl3;
25683
- al5 = bl4;
25684
- al6 = bl5;
25685
- al7 = bl6;
25686
- al0 = bl7;
25687
- if (i % 16 === 15) {
25688
- for (j = 0; j < 16; j++) {
25689
- h = wh[j];
25690
- l = wl[j];
25691
- a = l & 65535;
25692
- b = l >>> 16;
25693
- c = h & 65535;
25694
- d = h >>> 16;
25695
- h = wh[(j + 9) % 16];
25696
- l = wl[(j + 9) % 16];
25697
- a += l & 65535;
25698
- b += l >>> 16;
25699
- c += h & 65535;
25700
- d += h >>> 16;
25701
- th = wh[(j + 1) % 16];
25702
- tl = wl[(j + 1) % 16];
25703
- h = (th >>> 1 | tl << 32 - 1) ^ (th >>> 8 | tl << 32 - 8) ^ th >>> 7;
25704
- l = (tl >>> 1 | th << 32 - 1) ^ (tl >>> 8 | th << 32 - 8) ^ (tl >>> 7 | th << 32 - 7);
25705
- a += l & 65535;
25706
- b += l >>> 16;
25707
- c += h & 65535;
25708
- d += h >>> 16;
25709
- th = wh[(j + 14) % 16];
25710
- tl = wl[(j + 14) % 16];
25711
- h = (th >>> 19 | tl << 32 - 19) ^ (tl >>> 61 - 32 | th << 32 - (61 - 32)) ^ th >>> 6;
25712
- l = (tl >>> 19 | th << 32 - 19) ^ (th >>> 61 - 32 | tl << 32 - (61 - 32)) ^ (tl >>> 6 | th << 32 - 6);
25713
- a += l & 65535;
25714
- b += l >>> 16;
25715
- c += h & 65535;
25716
- d += h >>> 16;
25717
- b += a >>> 16;
25718
- c += b >>> 16;
25719
- d += c >>> 16;
25720
- wh[j] = c & 65535 | d << 16;
25721
- wl[j] = a & 65535 | b << 16;
25722
- }
25723
- }
25724
- }
25725
- h = ah0;
25726
- l = al0;
25727
- a = l & 65535;
25728
- b = l >>> 16;
25729
- c = h & 65535;
25730
- d = h >>> 16;
25731
- h = hh[0];
25732
- l = hl[0];
25733
- a += l & 65535;
25734
- b += l >>> 16;
25735
- c += h & 65535;
25736
- d += h >>> 16;
25737
- b += a >>> 16;
25738
- c += b >>> 16;
25739
- d += c >>> 16;
25740
- hh[0] = ah0 = c & 65535 | d << 16;
25741
- hl[0] = al0 = a & 65535 | b << 16;
25742
- h = ah1;
25743
- l = al1;
25744
- a = l & 65535;
25745
- b = l >>> 16;
25746
- c = h & 65535;
25747
- d = h >>> 16;
25748
- h = hh[1];
25749
- l = hl[1];
25750
- a += l & 65535;
25751
- b += l >>> 16;
25752
- c += h & 65535;
25753
- d += h >>> 16;
25754
- b += a >>> 16;
25755
- c += b >>> 16;
25756
- d += c >>> 16;
25757
- hh[1] = ah1 = c & 65535 | d << 16;
25758
- hl[1] = al1 = a & 65535 | b << 16;
25759
- h = ah2;
25760
- l = al2;
25761
- a = l & 65535;
25762
- b = l >>> 16;
25763
- c = h & 65535;
25764
- d = h >>> 16;
25765
- h = hh[2];
25766
- l = hl[2];
25767
- a += l & 65535;
25768
- b += l >>> 16;
25769
- c += h & 65535;
25770
- d += h >>> 16;
25771
- b += a >>> 16;
25772
- c += b >>> 16;
25773
- d += c >>> 16;
25774
- hh[2] = ah2 = c & 65535 | d << 16;
25775
- hl[2] = al2 = a & 65535 | b << 16;
25776
- h = ah3;
25777
- l = al3;
25778
- a = l & 65535;
25779
- b = l >>> 16;
25780
- c = h & 65535;
25781
- d = h >>> 16;
25782
- h = hh[3];
25783
- l = hl[3];
25784
- a += l & 65535;
25785
- b += l >>> 16;
25786
- c += h & 65535;
25787
- d += h >>> 16;
25788
- b += a >>> 16;
25789
- c += b >>> 16;
25790
- d += c >>> 16;
25791
- hh[3] = ah3 = c & 65535 | d << 16;
25792
- hl[3] = al3 = a & 65535 | b << 16;
25793
- h = ah4;
25794
- l = al4;
25795
- a = l & 65535;
25796
- b = l >>> 16;
25797
- c = h & 65535;
25798
- d = h >>> 16;
25799
- h = hh[4];
25800
- l = hl[4];
25801
- a += l & 65535;
25802
- b += l >>> 16;
25803
- c += h & 65535;
25804
- d += h >>> 16;
25805
- b += a >>> 16;
25806
- c += b >>> 16;
25807
- d += c >>> 16;
25808
- hh[4] = ah4 = c & 65535 | d << 16;
25809
- hl[4] = al4 = a & 65535 | b << 16;
25810
- h = ah5;
25811
- l = al5;
25812
- a = l & 65535;
25813
- b = l >>> 16;
25814
- c = h & 65535;
25815
- d = h >>> 16;
25816
- h = hh[5];
25817
- l = hl[5];
25818
- a += l & 65535;
25819
- b += l >>> 16;
25820
- c += h & 65535;
25821
- d += h >>> 16;
25822
- b += a >>> 16;
25823
- c += b >>> 16;
25824
- d += c >>> 16;
25825
- hh[5] = ah5 = c & 65535 | d << 16;
25826
- hl[5] = al5 = a & 65535 | b << 16;
25827
- h = ah6;
25828
- l = al6;
25829
- a = l & 65535;
25830
- b = l >>> 16;
25831
- c = h & 65535;
25832
- d = h >>> 16;
25833
- h = hh[6];
25834
- l = hl[6];
25835
- a += l & 65535;
25836
- b += l >>> 16;
25837
- c += h & 65535;
25838
- d += h >>> 16;
25839
- b += a >>> 16;
25840
- c += b >>> 16;
25841
- d += c >>> 16;
25842
- hh[6] = ah6 = c & 65535 | d << 16;
25843
- hl[6] = al6 = a & 65535 | b << 16;
25844
- h = ah7;
25845
- l = al7;
25846
- a = l & 65535;
25847
- b = l >>> 16;
25848
- c = h & 65535;
25849
- d = h >>> 16;
25850
- h = hh[7];
25851
- l = hl[7];
25852
- a += l & 65535;
25853
- b += l >>> 16;
25854
- c += h & 65535;
25855
- d += h >>> 16;
25856
- b += a >>> 16;
25857
- c += b >>> 16;
25858
- d += c >>> 16;
25859
- hh[7] = ah7 = c & 65535 | d << 16;
25860
- hl[7] = al7 = a & 65535 | b << 16;
25861
- pos += 128;
25862
- n -= 128;
25863
- }
25864
- return n;
25865
- }
25866
- function crypto_hash(out, m, n) {
25867
- var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
25868
- hh[0] = 1779033703;
25869
- hh[1] = 3144134277;
25870
- hh[2] = 1013904242;
25871
- hh[3] = 2773480762;
25872
- hh[4] = 1359893119;
25873
- hh[5] = 2600822924;
25874
- hh[6] = 528734635;
25875
- hh[7] = 1541459225;
25876
- hl[0] = 4089235720;
25877
- hl[1] = 2227873595;
25878
- hl[2] = 4271175723;
25879
- hl[3] = 1595750129;
25880
- hl[4] = 2917565137;
25881
- hl[5] = 725511199;
25882
- hl[6] = 4215389547;
25883
- hl[7] = 327033209;
25884
- crypto_hashblocks_hl(hh, hl, m, n);
25885
- n %= 128;
25886
- for (i = 0; i < n; i++) x[i] = m[b - n + i];
25887
- x[n] = 128;
25888
- n = 256 - 128 * (n < 112 ? 1 : 0);
25889
- x[n - 9] = 0;
25890
- ts64(x, n - 8, b / 536870912 | 0, b << 3);
25891
- crypto_hashblocks_hl(hh, hl, x, n);
25892
- for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
25893
- return 0;
25894
- }
25895
- function add(p, q) {
25896
- var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t = gf();
25897
- Z(a, p[1], p[0]);
25898
- Z(t, q[1], q[0]);
25899
- M(a, a, t);
25900
- A(b, p[0], p[1]);
25901
- A(t, q[0], q[1]);
25902
- M(b, b, t);
25903
- M(c, p[3], q[3]);
25904
- M(c, c, D2);
25905
- M(d, p[2], q[2]);
25906
- A(d, d, d);
25907
- Z(e, b, a);
25908
- Z(f, d, c);
25909
- A(g, d, c);
25910
- A(h, b, a);
25911
- M(p[0], e, f);
25912
- M(p[1], h, g);
25913
- M(p[2], g, f);
25914
- M(p[3], e, h);
25915
- }
25916
- function cswap(p, q, b) {
25917
- var i;
25918
- for (i = 0; i < 4; i++) {
25919
- sel25519(p[i], q[i], b);
25920
- }
25921
- }
25922
- function pack(r, p) {
25923
- var tx = gf(), ty = gf(), zi = gf();
25924
- inv25519(zi, p[2]);
25925
- M(tx, p[0], zi);
25926
- M(ty, p[1], zi);
25927
- pack25519(r, ty);
25928
- r[31] ^= par25519(tx) << 7;
25929
- }
25930
- function scalarmult(p, q, s) {
25931
- var b, i;
25932
- set25519(p[0], gf0);
25933
- set25519(p[1], gf1);
25934
- set25519(p[2], gf1);
25935
- set25519(p[3], gf0);
25936
- for (i = 255; i >= 0; --i) {
25937
- b = s[i / 8 | 0] >> (i & 7) & 1;
25938
- cswap(p, q, b);
25939
- add(q, p);
25940
- add(p, p);
25941
- cswap(p, q, b);
25942
- }
25943
- }
25944
- function scalarbase(p, s) {
25945
- var q = [gf(), gf(), gf(), gf()];
25946
- set25519(q[0], X);
25947
- set25519(q[1], Y);
25948
- set25519(q[2], gf1);
25949
- M(q[3], X, Y);
25950
- scalarmult(p, q, s);
25951
- }
25952
- function crypto_sign_keypair(pk, sk, seeded) {
25953
- var d = new Uint8Array(64);
25954
- var p = [gf(), gf(), gf(), gf()];
25955
- var i;
25956
- if (!seeded) randombytes(sk, 32);
25957
- crypto_hash(d, sk, 32);
25958
- d[0] &= 248;
25959
- d[31] &= 127;
25960
- d[31] |= 64;
25961
- scalarbase(p, d);
25962
- pack(pk, p);
25963
- for (i = 0; i < 32; i++) sk[i + 32] = pk[i];
25964
- return 0;
25965
- }
25966
- var L = new Float64Array([237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16]);
25967
- function modL(r, x) {
25968
- var carry, i, j, k;
25969
- for (i = 63; i >= 32; --i) {
25970
- carry = 0;
25971
- for (j = i - 32, k = i - 12; j < k; ++j) {
25972
- x[j] += carry - 16 * x[i] * L[j - (i - 32)];
25973
- carry = Math.floor((x[j] + 128) / 256);
25974
- x[j] -= carry * 256;
25975
- }
25976
- x[j] += carry;
25977
- x[i] = 0;
25978
- }
25979
- carry = 0;
25980
- for (j = 0; j < 32; j++) {
25981
- x[j] += carry - (x[31] >> 4) * L[j];
25982
- carry = x[j] >> 8;
25983
- x[j] &= 255;
25984
- }
25985
- for (j = 0; j < 32; j++) x[j] -= carry * L[j];
25986
- for (i = 0; i < 32; i++) {
25987
- x[i + 1] += x[i] >> 8;
25988
- r[i] = x[i] & 255;
25989
- }
25990
- }
25991
- function reduce(r) {
25992
- var x = new Float64Array(64), i;
25993
- for (i = 0; i < 64; i++) x[i] = r[i];
25994
- for (i = 0; i < 64; i++) r[i] = 0;
25995
- modL(r, x);
25996
- }
25997
- function crypto_sign(sm, m, n, sk) {
25998
- var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
25999
- var i, j, x = new Float64Array(64);
26000
- var p = [gf(), gf(), gf(), gf()];
26001
- crypto_hash(d, sk, 32);
26002
- d[0] &= 248;
26003
- d[31] &= 127;
26004
- d[31] |= 64;
26005
- var smlen = n + 64;
26006
- for (i = 0; i < n; i++) sm[64 + i] = m[i];
26007
- for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
26008
- crypto_hash(r, sm.subarray(32), n + 32);
26009
- reduce(r);
26010
- scalarbase(p, r);
26011
- pack(sm, p);
26012
- for (i = 32; i < 64; i++) sm[i] = sk[i];
26013
- crypto_hash(h, sm, n + 64);
26014
- reduce(h);
26015
- for (i = 0; i < 64; i++) x[i] = 0;
26016
- for (i = 0; i < 32; i++) x[i] = r[i];
26017
- for (i = 0; i < 32; i++) {
26018
- for (j = 0; j < 32; j++) {
26019
- x[i + j] += h[i] * d[j];
26020
- }
26021
- }
26022
- modL(sm.subarray(32), x);
26023
- return smlen;
26024
- }
26025
- function unpackneg(r, p) {
26026
- var t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();
26027
- set25519(r[2], gf1);
26028
- unpack25519(r[1], p);
26029
- S(num, r[1]);
26030
- M(den, num, D);
26031
- Z(num, num, r[2]);
26032
- A(den, r[2], den);
26033
- S(den2, den);
26034
- S(den4, den2);
26035
- M(den6, den4, den2);
26036
- M(t, den6, num);
26037
- M(t, t, den);
26038
- pow2523(t, t);
26039
- M(t, t, num);
26040
- M(t, t, den);
26041
- M(t, t, den);
26042
- M(r[0], t, den);
26043
- S(chk, r[0]);
26044
- M(chk, chk, den);
26045
- if (neq25519(chk, num)) M(r[0], r[0], I);
26046
- S(chk, r[0]);
26047
- M(chk, chk, den);
26048
- if (neq25519(chk, num)) return -1;
26049
- if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0]);
26050
- M(r[3], r[0], r[1]);
26051
- return 0;
26052
- }
26053
- function crypto_sign_open(m, sm, n, pk) {
26054
- var i;
26055
- var t = new Uint8Array(32), h = new Uint8Array(64);
26056
- var p = [gf(), gf(), gf(), gf()], q = [gf(), gf(), gf(), gf()];
26057
- if (n < 64) return -1;
26058
- if (unpackneg(q, pk)) return -1;
26059
- for (i = 0; i < n; i++) m[i] = sm[i];
26060
- for (i = 0; i < 32; i++) m[i + 32] = pk[i];
26061
- crypto_hash(h, m, n);
26062
- reduce(h);
26063
- scalarmult(p, q, h);
26064
- scalarbase(q, sm.subarray(32));
26065
- add(p, q);
26066
- pack(t, p);
26067
- n -= 64;
26068
- if (crypto_verify_32(sm, 0, t, 0)) {
26069
- for (i = 0; i < n; i++) m[i] = 0;
26070
- return -1;
26071
- }
26072
- for (i = 0; i < n; i++) m[i] = sm[i + 64];
26073
- return n;
26074
- }
26075
- var crypto_secretbox_KEYBYTES = 32, crypto_secretbox_NONCEBYTES = 24, crypto_secretbox_ZEROBYTES = 32, crypto_secretbox_BOXZEROBYTES = 16, crypto_scalarmult_BYTES = 32, crypto_scalarmult_SCALARBYTES = 32, crypto_box_PUBLICKEYBYTES = 32, crypto_box_SECRETKEYBYTES = 32, crypto_box_BEFORENMBYTES = 32, crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, crypto_sign_BYTES = 64, crypto_sign_PUBLICKEYBYTES = 32, crypto_sign_SECRETKEYBYTES = 64, crypto_sign_SEEDBYTES = 32, crypto_hash_BYTES = 64;
26076
- nacl6.lowlevel = {
26077
- crypto_core_hsalsa20,
26078
- crypto_stream_xor,
26079
- crypto_stream,
26080
- crypto_stream_salsa20_xor,
26081
- crypto_stream_salsa20,
26082
- crypto_onetimeauth,
26083
- crypto_onetimeauth_verify,
26084
- crypto_verify_16,
26085
- crypto_verify_32,
26086
- crypto_secretbox,
26087
- crypto_secretbox_open,
26088
- crypto_scalarmult,
26089
- crypto_scalarmult_base,
26090
- crypto_box_beforenm,
26091
- crypto_box_afternm,
26092
- crypto_box,
26093
- crypto_box_open,
26094
- crypto_box_keypair,
26095
- crypto_hash,
26096
- crypto_sign,
26097
- crypto_sign_keypair,
26098
- crypto_sign_open,
26099
- crypto_secretbox_KEYBYTES,
26100
- crypto_secretbox_NONCEBYTES,
26101
- crypto_secretbox_ZEROBYTES,
26102
- crypto_secretbox_BOXZEROBYTES,
26103
- crypto_scalarmult_BYTES,
26104
- crypto_scalarmult_SCALARBYTES,
26105
- crypto_box_PUBLICKEYBYTES,
26106
- crypto_box_SECRETKEYBYTES,
26107
- crypto_box_BEFORENMBYTES,
26108
- crypto_box_NONCEBYTES,
26109
- crypto_box_ZEROBYTES,
26110
- crypto_box_BOXZEROBYTES,
26111
- crypto_sign_BYTES,
26112
- crypto_sign_PUBLICKEYBYTES,
26113
- crypto_sign_SECRETKEYBYTES,
26114
- crypto_sign_SEEDBYTES,
26115
- crypto_hash_BYTES,
26116
- gf,
26117
- D,
26118
- L,
26119
- pack25519,
26120
- unpack25519,
26121
- M,
26122
- A,
26123
- S,
26124
- Z,
26125
- pow2523,
26126
- add,
26127
- set25519,
26128
- modL,
26129
- scalarmult,
26130
- scalarbase
26131
- };
26132
- function checkLengths(k, n) {
26133
- if (k.length !== crypto_secretbox_KEYBYTES) throw new Error("bad key size");
26134
- if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error("bad nonce size");
26135
- }
26136
- function checkBoxLengths(pk, sk) {
26137
- if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error("bad public key size");
26138
- if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
26139
- }
26140
- function checkArrayTypes() {
26141
- for (var i = 0; i < arguments.length; i++) {
26142
- if (!(arguments[i] instanceof Uint8Array))
26143
- throw new TypeError("unexpected type, use Uint8Array");
26144
- }
26145
- }
26146
- function cleanup(arr) {
26147
- for (var i = 0; i < arr.length; i++) arr[i] = 0;
26148
- }
26149
- nacl6.randomBytes = function(n) {
26150
- var b = new Uint8Array(n);
26151
- randombytes(b, n);
26152
- return b;
26153
- };
26154
- nacl6.secretbox = function(msg, nonce, key) {
26155
- checkArrayTypes(msg, nonce, key);
26156
- checkLengths(key, nonce);
26157
- var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
26158
- var c = new Uint8Array(m.length);
26159
- for (var i = 0; i < msg.length; i++) m[i + crypto_secretbox_ZEROBYTES] = msg[i];
26160
- crypto_secretbox(c, m, m.length, nonce, key);
26161
- return c.subarray(crypto_secretbox_BOXZEROBYTES);
26162
- };
26163
- nacl6.secretbox.open = function(box, nonce, key) {
26164
- checkArrayTypes(box, nonce, key);
26165
- checkLengths(key, nonce);
26166
- var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
26167
- var m = new Uint8Array(c.length);
26168
- for (var i = 0; i < box.length; i++) c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
26169
- if (c.length < 32) return null;
26170
- if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
26171
- return m.subarray(crypto_secretbox_ZEROBYTES);
26172
- };
26173
- nacl6.secretbox.keyLength = crypto_secretbox_KEYBYTES;
26174
- nacl6.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
26175
- nacl6.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
26176
- nacl6.scalarMult = function(n, p) {
26177
- checkArrayTypes(n, p);
26178
- if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
26179
- if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
26180
- var q = new Uint8Array(crypto_scalarmult_BYTES);
26181
- crypto_scalarmult(q, n, p);
26182
- return q;
26183
- };
26184
- nacl6.scalarMult.base = function(n) {
26185
- checkArrayTypes(n);
26186
- if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
26187
- var q = new Uint8Array(crypto_scalarmult_BYTES);
26188
- crypto_scalarmult_base(q, n);
26189
- return q;
26190
- };
26191
- nacl6.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
26192
- nacl6.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
26193
- nacl6.box = function(msg, nonce, publicKey, secretKey) {
26194
- var k = nacl6.box.before(publicKey, secretKey);
26195
- return nacl6.secretbox(msg, nonce, k);
26196
- };
26197
- nacl6.box.before = function(publicKey, secretKey) {
26198
- checkArrayTypes(publicKey, secretKey);
26199
- checkBoxLengths(publicKey, secretKey);
26200
- var k = new Uint8Array(crypto_box_BEFORENMBYTES);
26201
- crypto_box_beforenm(k, publicKey, secretKey);
26202
- return k;
26203
- };
26204
- nacl6.box.after = nacl6.secretbox;
26205
- nacl6.box.open = function(msg, nonce, publicKey, secretKey) {
26206
- var k = nacl6.box.before(publicKey, secretKey);
26207
- return nacl6.secretbox.open(msg, nonce, k);
26208
- };
26209
- nacl6.box.open.after = nacl6.secretbox.open;
26210
- nacl6.box.keyPair = function() {
26211
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
26212
- var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
26213
- crypto_box_keypair(pk, sk);
26214
- return { publicKey: pk, secretKey: sk };
26215
- };
26216
- nacl6.box.keyPair.fromSecretKey = function(secretKey) {
26217
- checkArrayTypes(secretKey);
26218
- if (secretKey.length !== crypto_box_SECRETKEYBYTES)
26219
- throw new Error("bad secret key size");
26220
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
26221
- crypto_scalarmult_base(pk, secretKey);
26222
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
26223
- };
26224
- nacl6.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
26225
- nacl6.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
26226
- nacl6.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
26227
- nacl6.box.nonceLength = crypto_box_NONCEBYTES;
26228
- nacl6.box.overheadLength = nacl6.secretbox.overheadLength;
26229
- nacl6.sign = function(msg, secretKey) {
26230
- checkArrayTypes(msg, secretKey);
26231
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
26232
- throw new Error("bad secret key size");
26233
- var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
26234
- crypto_sign(signedMsg, msg, msg.length, secretKey);
26235
- return signedMsg;
26236
- };
26237
- nacl6.sign.open = function(signedMsg, publicKey) {
26238
- checkArrayTypes(signedMsg, publicKey);
26239
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
26240
- throw new Error("bad public key size");
26241
- var tmp = new Uint8Array(signedMsg.length);
26242
- var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
26243
- if (mlen < 0) return null;
26244
- var m = new Uint8Array(mlen);
26245
- for (var i = 0; i < m.length; i++) m[i] = tmp[i];
26246
- return m;
26247
- };
26248
- nacl6.sign.detached = function(msg, secretKey) {
26249
- var signedMsg = nacl6.sign(msg, secretKey);
26250
- var sig = new Uint8Array(crypto_sign_BYTES);
26251
- for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
26252
- return sig;
26253
- };
26254
- nacl6.sign.detached.verify = function(msg, sig, publicKey) {
26255
- checkArrayTypes(msg, sig, publicKey);
26256
- if (sig.length !== crypto_sign_BYTES)
26257
- throw new Error("bad signature size");
26258
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
26259
- throw new Error("bad public key size");
26260
- var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
26261
- var m = new Uint8Array(crypto_sign_BYTES + msg.length);
26262
- var i;
26263
- for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
26264
- for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
26265
- return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
26266
- };
26267
- nacl6.sign.keyPair = function() {
26268
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
26269
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
26270
- crypto_sign_keypair(pk, sk);
26271
- return { publicKey: pk, secretKey: sk };
26272
- };
26273
- nacl6.sign.keyPair.fromSecretKey = function(secretKey) {
26274
- checkArrayTypes(secretKey);
26275
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
26276
- throw new Error("bad secret key size");
26277
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
26278
- for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
26279
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
26280
- };
26281
- nacl6.sign.keyPair.fromSeed = function(seed) {
26282
- checkArrayTypes(seed);
26283
- if (seed.length !== crypto_sign_SEEDBYTES)
26284
- throw new Error("bad seed size");
26285
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
26286
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
26287
- for (var i = 0; i < 32; i++) sk[i] = seed[i];
26288
- crypto_sign_keypair(pk, sk, true);
26289
- return { publicKey: pk, secretKey: sk };
26290
- };
26291
- nacl6.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
26292
- nacl6.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
26293
- nacl6.sign.seedLength = crypto_sign_SEEDBYTES;
26294
- nacl6.sign.signatureLength = crypto_sign_BYTES;
26295
- nacl6.hash = function(msg) {
26296
- checkArrayTypes(msg);
26297
- var h = new Uint8Array(crypto_hash_BYTES);
26298
- crypto_hash(h, msg, msg.length);
26299
- return h;
26300
- };
26301
- nacl6.hash.hashLength = crypto_hash_BYTES;
26302
- nacl6.verify = function(x, y) {
26303
- checkArrayTypes(x, y);
26304
- if (x.length === 0 || y.length === 0) return false;
26305
- if (x.length !== y.length) return false;
26306
- return vn(x, 0, y, 0, x.length) === 0 ? true : false;
26307
- };
26308
- nacl6.setPRNG = function(fn) {
26309
- randombytes = fn;
26310
- };
26311
- (function() {
26312
- var crypto = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
26313
- if (crypto && crypto.getRandomValues) {
26314
- var QUOTA = 65536;
26315
- nacl6.setPRNG(function(x, n) {
26316
- var i, v = new Uint8Array(n);
26317
- for (i = 0; i < n; i += QUOTA) {
26318
- crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
26319
- }
26320
- for (i = 0; i < n; i++) x[i] = v[i];
26321
- cleanup(v);
26322
- });
26323
- } else if (typeof __require2 !== "undefined") {
26324
- crypto = __require2("crypto");
26325
- if (crypto && crypto.randomBytes) {
26326
- nacl6.setPRNG(function(x, n) {
26327
- var i, v = crypto.randomBytes(n);
26328
- for (i = 0; i < n; i++) x[i] = v[i];
26329
- cleanup(v);
26330
- });
26331
- }
26332
- }
26333
- })();
26334
- })(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
26335
- }
26336
- });
26337
24111
  BACKEND_URL = process.env.PAIGY_BACKEND_URL ?? "https://paigy.ai";
26338
24112
  NETWORK_MSG = `Can't reach ${BACKEND_URL} \u2014 the connection was blocked or dropped before an HTTP response. If this agent runs in a sandboxed environment with a network allowlist (e.g. Claude Code on the web, CI), ask the user to add the Paigy domain (paigy.ai) to the environment's allowed domains, then retry.`;
26339
24113
  PROXY_ENV = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"];
@@ -26349,7 +24123,6 @@ var init_dist = __esm({
26349
24123
  const v = process.env[key];
26350
24124
  return v && v.trim() ? v : void 0;
26351
24125
  };
26352
- SESSION_ID = envSession("PAIGY_SESSION_ID") ?? envSession("CLAUDE_CODE_SESSION_ID") ?? envSession("CODEX_THREAD_ID") ?? envSession("CODEX_SESSION_ID") ?? WORKSPACE_ID;
26353
24126
  ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
26354
24127
  defaultOptions = {
26355
24128
  name: void 0,
@@ -26713,32 +24486,40 @@ var init_dist = __esm({
26713
24486
  };
26714
24487
  OPTIONS_MIN = 2;
26715
24488
  OPTIONS_MAX = 6;
26716
- StartContactSchema = external_exports.object({
26717
- goalIds: external_exports.tuple([external_exports.string().uuid()]),
26718
- // THE ASK IS THE QUESTION, not a bulletin with a question at the end (2026-09-16).
26719
- //
26720
- // A DecisionNeed is settled only by an answer in the shape THIS ask declares. Bundle news,
26721
- // findings and a decision into one, and the person answers whichever part engaged them —
26722
- // which settles nothing, leaves the need open, and gets them asked again. On call 619c5a92
26723
- // one ask carried a briefing, a side question ("the ring should show the agent's name now —
26724
- // what did you actually see?") and a one-of-four about how far an erase reaches. The owner
26725
- // answered the side question. The need stayed open; the card asked again. Of the 45 call
26726
- // asks carrying a decision, 27 are over 600 characters.
26727
- //
26728
- // Sending them separately costs nothing, because a CALL contact joins the call already
26729
- // happening (`goal/store.ts`, JOIN BEFORE MINTING) — several contacts on one Goal arrive as
26730
- // one call, planned as its turns, and each keeps its own settleable need.
24489
+ OptionSchema = external_exports.object({
24490
+ id: external_exports.string(),
24491
+ label: external_exports.string(),
24492
+ hint: external_exports.string().max(500).describe("Optional short projection of consequence or action if this option is chosen (e.g. 'Reruns test suite', 'Merges to main').").optional(),
24493
+ // .describe() flows into the MCP contact JSON schema (zodToJsonSchema), so
24494
+ // the constraints below are what an agent reads when deciding to use these.
24495
+ html: external_exports.string().max(16384).describe(
24496
+ "Optional sandboxed HTML/CSS preview for a visual 'pick one' (shown in the option card). Untrusted-sandboxed: NO JavaScript, NO external network or images \u2014 inline CSS and data: URIs only; <=16KB. Rendered edge-to-edge in a responsive card that is 200pt tall (about 320pt wide on a phone, with the next option peeking beside it); make your HTML fit that viewport. Use for layout/CSS mockups, tables, diffs. For a hosted image use `image` instead."
24497
+ ).optional(),
24498
+ image: external_exports.string().url().describe(
24499
+ "Optional image URL rendered as the option's preview (plain image, not sandboxed). For agent-generated HTML/CSS mockups, use `html` instead."
24500
+ ).optional()
24501
+ });
24502
+ OptionInputSchema = OptionSchema.omit({ id: true }).extend({
24503
+ label: external_exports.string().trim().min(1).max(1e3)
24504
+ }).strict();
24505
+ NIGHT = { from: 23, to: 7 };
24506
+ AskInputSchema = external_exports.object({
24507
+ id: external_exports.string().optional().describe("Optional idempotency key or client-side ID for this specific ask."),
24508
+ parentId: external_exports.string().uuid().optional().describe("The Goal this question is about \u2014 usually the one you are working on. The question goes onto that Goal and its answer comes back there. Omit it and Paigy places the question in the tree itself."),
24509
+ repo: external_exports.string().optional().describe("Optional repository context."),
26731
24510
  ask: external_exports.string().trim().min(1).max(1e4).describe(
26732
24511
  "The question, and only what is needed to answer it. News, progress and findings are their own contact \u2014 a call contact JOINS a call already happening, so several arrive as one call. Do not bundle: a DecisionNeed is settled only by an answer in the shape this ask declares, so someone who answers the part that interested them settles nothing and is asked again."
26733
24512
  ),
24513
+ options: external_exports.array(OptionInputSchema).min(2).max(6).optional()
24514
+ }).strict();
24515
+ StartContactSchema = external_exports.object({
24516
+ asks: external_exports.array(AskInputSchema).min(1).describe("The questions to pose, one per object. An ask with a parentId is filed on that Goal as it is; only an ask naming no Goal is placed in the tree by Paigy."),
26734
24517
  waiting: external_exports.enum(["none", "hard"]).default("none"),
26735
- channel: external_exports.enum(["notification", "call"]).default("notification"),
26736
- options: external_exports.array(external_exports.object({ label: external_exports.string().trim().min(1).max(1e3), image: external_exports.string().url().optional(), html: external_exports.string().max(16384).optional() }).strict()).min(2).max(6).optional(),
26737
- threadId: external_exports.string().uuid().optional().describe("Continue an existing Thread: the threadId a prior Delivery returned. Omit to start a new Thread.")
24518
+ channel: external_exports.enum(["notification", "call"]).default("notification")
26738
24519
  }).strict();
26739
24520
  ContactSchema = external_exports.union([StartContactSchema, external_exports.object({ deliveryId: external_exports.string().uuid() }).strict()]);
26740
24521
  CONTACT_SCHEMA = { type: "object", ...mcpInputSchema(ContactSchema) };
26741
- CONTACT_DESCRIPTION = "Contact the user about exactly one existing Goal: pass goalIds:[goalId], ask, channel:'notification'|'call', and waiting:'none'|'hard'. Options supply choices. Notification returns immediately; collect durable answers with claim_goal/get_goal. On stdio, a Call holds one cancellable ~45s window; continue with ONLY {deliveryId}. Continuation sends nothing and rereads the same durable evidence, including previously read answers. Entries retain authorship and provenance; accepted decisions are separate from quoted speech. Call state open does not mean ringing. Unsupported: soft waiting, multiple Goals/questions, outcome admission, and re-presentation of an existing request. Create a Goal explicitly first; never resend a pending ask to continue waiting.";
24522
+ CONTACT_DESCRIPTION = "Contact the user with one or more asks/questions. Pass an array of asks (each with 'ask', optional 'options', 'id', 'parentId', 'repo'), plus channel:'notification'|'call', and waiting:'none'|'hard'. An ask that names a Goal (parentId) goes onto that Goal; one that names none is placed in the person's tree by Paigy. Notification returns immediately; collect durable answers with check_replies. On stdio, a Call holds one cancellable ~45s window; continue with ONLY {deliveryId}. Never bundle multiple questions into a single 'ask' string; pass them as separate objects in the 'asks' array.";
26742
24523
  CreateGoalSchema = external_exports.object({
26743
24524
  outcome: external_exports.string().trim().min(1).max(1e4),
26744
24525
  /** The work's NAME (#2115) — one to five words, how a person refers to it out loud ("the night
@@ -26746,11 +24527,6 @@ var init_dist = __esm({
26746
24527
  title: external_exports.string().trim().min(1).max(80).optional(),
26747
24528
  ownerParticipant: external_exports.string().trim().min(1).optional(),
26748
24529
  idempotencyKey: external_exports.string().trim().min(1).max(200),
26749
- /** A past conversation this Goal should be read against — History's "new session from this"
26750
- * (owner, on the call of 2026-09-14: "let's do the reference with the threading"). A
26751
- * reference only: the owner reads it through `get_thread`, which does its own scoping, and
26752
- * the writer refuses a thread belonging to another account. */
26753
- contextThreadId: external_exports.string().uuid().optional(),
26754
24530
  /** THE GOAL THIS ONE BELONGS UNDER (owner, 2026-09-15: "the ask I gave for the design doc
26755
24531
  * didn't get created as a child goal of the voice UI goal, which is how it should've
26756
24532
  * worked"). It could not have been: this door took no parent, so the only route was
@@ -26758,12 +24534,15 @@ var init_dist = __esm({
26758
24534
  * took the short one. The hierarchy has been modelled since Goals existed and had been used
26759
24535
  * ZERO times in 2,031 of them. Absent, the server judges it against the caller's open Goals
26760
24536
  * (`apps/api/src/goal/intake.ts`). The writer refuses a Goal belonging to another account. */
26761
- parentGoalId: external_exports.string().uuid().optional()
24537
+ parentGoalId: external_exports.string().uuid().optional(),
24538
+ /** The repository or project identifier this Goal belongs to (#2280) — e.g. "owner/repo" or
24539
+ * repo name. Delegated work inherits this from its parent Goal when omitted. */
24540
+ repo: external_exports.string().trim().min(1).max(200).optional()
26762
24541
  });
26763
24542
  CreateGoalToolSchema = CreateGoalSchema.extend({
26764
24543
  idempotencyKey: CreateGoalSchema.shape.idempotencyKey.optional().describe("Optional. One is minted per call; pass your own only so a retry lands on the same Goal.")
26765
24544
  }).strict();
26766
- CREATE_GOAL_DESCRIPTION = 'Create a durable Goal for an outcome. Without parentGoalId it is placed against your open Goals: if one already IS this work, that Goal comes back (existing: true) and nothing new is created \u2014 continue it; if the work belongs under one, it is created there (parentGoalId in the receipt); otherwise it is a root. Pass parentGoalId yourself to put it under a specific Goal. Pass title to name it in one to five words, as a person would refer to it out loud ("the night rings") \u2014 it heads every list and is spoken on a call; without one the brain writes it. Admission only: the owner must claim it before doing work, then update it as it advances. Returns an admission receipt with goalId, current state, revision, ownerParticipant, and the next step; no Goal content or execution lease.';
24545
+ CREATE_GOAL_DESCRIPTION = 'Create a durable Goal for an outcome. Without parentGoalId it is placed against your open Goals: if one already IS this work, that Goal comes back (existing: true) and nothing new is created \u2014 continue it; if the work belongs under one, it is created there (parentGoalId in the receipt); otherwise it is a root. Pass parentGoalId yourself to put it under a specific Goal. Pass repo to anchor the work to a specific repository ("owner/repo" or repo name); delegated children inherit it. Pass title to name it in one to five words, as a person would refer to it out loud ("the night rings") \u2014 it heads every list and is spoken on a call; without one the brain writes it. Admission only: the owner must claim it before doing work, then update it as it advances. Returns an admission receipt with goalId, current state, revision, ownerParticipant, and the next step; no Goal content or execution lease.';
26767
24546
  UpdateGoalSchema = external_exports.object({
26768
24547
  revision: external_exports.number().int().positive(),
26769
24548
  changes: external_exports.object({
@@ -26791,19 +24570,9 @@ var init_dist = __esm({
26791
24570
  CLAIM_GOAL_DESCRIPTION = "Claim the oldest runnable or review-pending Goal you own, or pass goalId to claim that Goal. Returns the Goal as get_goal reads it, and creates or renews the execution lease.";
26792
24571
  CHECK_REPLIES_DESCRIPTION = "Your open Deliveries: every Notification or Call currently addressed to you \u2014 a request the user started toward you, an answer relayed to something you asked, a handoff \u2014 one row each: its Goals, how many decisions are still open, and the newest words in brief. A pure read with no arguments: nothing is consumed, acknowledged or claimed by reading it, so call it on startup, after a long wait, or whenever you want to know what is outstanding. To act on one, claim its Goal (claim_goal) or reread it in full with contact({deliveryId}). Once you have acted on what arrived, update_goal with reviewed: true closes the Deliveries addressed to you on that Goal. Your runnable and review-pending Goals come from claim_goal, not from here.";
26793
24572
  CheckRepliesSchema = external_exports.object({}).strict();
26794
- GetThreadSchema = external_exports.object({
26795
- parentId: external_exports.string().describe("The Thread to read \u2014 the threadId a Delivery returned, or the parentId of a search hit.")
26796
- }).strict();
26797
- GET_THREAD_DESCRIPTION = "Read the authorized durable Entries on one conversation Thread \u2014 what you wrote there and what was delivered to you, oldest first. Use claim_goal to find the work to resume; use this to rehydrate a Thread that a search hit or a Delivery named.";
26798
- SearchThreadsSchema = external_exports.object({
26799
- q: external_exports.string().describe("What to look for \u2014 plain words or a phrase (e.g. 'the livekit timeout', 'deploy to prod').")
26800
- }).strict();
26801
- SEARCH_THREADS_DESCRIPTION = `Search your PAST conversations before asking \u2014 "have we discussed this before?". Full-text over your own threads (the asks you sent + the user's answers); returns ranked threads with highlighted snippets, NOT rows: { hits: [{ parentId, at, agentLabel, matches: [{ notificationId, role, snippet }] }] }. The loop this exists for: search first \u2192 get_thread the best hit to rehydrate it \u2192 THEN continue or contact, so you answer with receipts ("last week you said ship it") instead of re-asking. Read-only, safe to call anytime; scoped to your own account's threads.`;
26802
24573
  AGENT_TOOLS = [
26803
24574
  { name: "contact", description: CONTACT_DESCRIPTION, inputSchema: CONTACT_SCHEMA },
26804
24575
  { name: "check_replies", description: CHECK_REPLIES_DESCRIPTION, inputSchema: mcpInputSchema(CheckRepliesSchema) },
26805
- { name: "get_thread", description: GET_THREAD_DESCRIPTION, inputSchema: mcpInputSchema(GetThreadSchema) },
26806
- { name: "search_threads", description: SEARCH_THREADS_DESCRIPTION, inputSchema: mcpInputSchema(SearchThreadsSchema) },
26807
24576
  { name: "create_goal", description: CREATE_GOAL_DESCRIPTION, inputSchema: mcpInputSchema(CreateGoalToolSchema) },
26808
24577
  { name: "claim_goal", description: CLAIM_GOAL_DESCRIPTION, inputSchema: mcpInputSchema(ClaimGoalSchema) },
26809
24578
  { name: "get_goal", description: GET_GOAL_DESCRIPTION, inputSchema: mcpInputSchema(GetGoalSchema) },
@@ -26837,18 +24606,6 @@ var init_dist = __esm({
26837
24606
  "summarize"
26838
24607
  // reduce volume, keep decision value — 30-turn cap, spoken briefing
26839
24608
  ]);
26840
- OptionSchema = external_exports.object({
26841
- id: external_exports.string(),
26842
- label: external_exports.string(),
26843
- // .describe() flows into the MCP contact JSON schema (zodToJsonSchema), so
26844
- // the constraints below are what an agent reads when deciding to use these.
26845
- html: external_exports.string().max(16384).describe(
26846
- "Optional sandboxed HTML/CSS preview for a visual 'pick one' (shown in the option card). Untrusted-sandboxed: NO JavaScript, NO external network or images \u2014 inline CSS and data: URIs only; <=16KB. Use for layout/CSS mockups, tables, diffs. For a hosted image use `image` instead."
26847
- ).optional(),
26848
- image: external_exports.string().url().describe(
26849
- "Optional image URL rendered as the option's preview (plain image, not sandboxed). For agent-generated HTML/CSS mockups, use `html` instead."
26850
- ).optional()
26851
- });
26852
24609
  VisualSchema = external_exports.object({
26853
24610
  url: external_exports.string().url(),
26854
24611
  label: external_exports.string().optional()
@@ -26902,7 +24659,7 @@ var init_dist = __esm({
26902
24659
  * ABSENT on the E2EE path, where the sealed `envelope` below carries it. The
26903
24660
  * superRefine at the bottom enforces exactly one of the two. */
26904
24661
  context: ContextSchema.optional(),
26905
- options: external_exports.array(OptionSchema.omit({ id: true })).min(OPTIONS_MIN).max(OPTIONS_MAX).optional().describe(
24662
+ options: external_exports.array(OptionInputSchema).min(OPTIONS_MIN).max(OPTIONS_MAX).optional().describe(
26906
24663
  "The choices, in order \u2014 required when select is 'one'/'many'/'rank', omitted otherwise. Ids are assigned automatically by position ('1', '2', \u2026); the user's answer references them as optionId(s)."
26907
24664
  ),
26908
24665
  points: external_exports.array(external_exports.string().min(1)).optional().describe(
@@ -26934,23 +24691,6 @@ var init_dist = __esm({
26934
24691
  * when `parentId` became the conversation handle: `parentId` says WHERE, this
26935
24692
  * says HOW. */
26936
24693
  clarifies: external_exports.string().optional(),
26937
- /** E2EE (text lane): when the pairing is E2EE, the sealed replacements for the
26938
- * plaintext content fields, keyed by field name. FINALIZED wire shape (was
26939
- * provisional in the storage PR): a per-field map `{ context?, options?,
26940
- * visuals? }` of opaque Envelopes — one seal per present content field, so a
26941
- * message with no options/visuals seals only `context`. It COEXISTS with the
26942
- * plaintext fields by mutual exclusion: the superRefine below requires that
26943
- * when `envelope` is present the plaintext `context`/`options`/`visuals` are
26944
- * ABSENT (and vice-versa), so a row is either fully plaintext or fully sealed —
26945
- * never a readable half. The server persists this OPAQUELY into
26946
- * notifications.envelope and relays it blindly; it never decrypts. Absent =
26947
- * today's plaintext path (context/options/visuals carry the cleartext).
26948
- * z.lazy because EnvelopeSchema is declared further down (E2EE section). */
26949
- envelope: external_exports.object({
26950
- context: external_exports.lazy(() => EnvelopeSchema).optional(),
26951
- options: external_exports.lazy(() => EnvelopeSchema).optional(),
26952
- visuals: external_exports.lazy(() => EnvelopeSchema).optional()
26953
- }).optional(),
26954
24694
  select: SelectShapeSchema.optional().describe(
26955
24695
  "How the user answers \u2014 required on the fully-shaped form, pick the shape that fits the question: 'one' = pick one option, 'many' = pick several, 'rank' = pick & order (each needs `options`); 'confirm' = yes/no or approve/deny; 'text' = free-form reply only (status updates, open questions). 'confirm' and 'text' take no options. Omit only when sending the simplified `ask` form \u2014 the broker picks the shape."
26956
24696
  ),
@@ -27004,22 +24744,6 @@ var init_dist = __esm({
27004
24744
  });
27005
24745
  NotifyRequestSchema = NotifyRequestFields.superRefine((r, ctx) => {
27006
24746
  if (r.workId && r.goalId) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["goalId"], message: "pass goalId or workId, not both" });
27007
- const sealed = !!r.envelope;
27008
- if (sealed) {
27009
- if (!r.envelope?.context)
27010
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["envelope", "context"], message: "sealed request must include envelope.context" });
27011
- for (const f of ["context", "options", "visuals"]) {
27012
- if (r[f] !== void 0)
27013
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: [f], message: `E2EE request must not carry plaintext ${f} \u2014 it's sealed in envelope.${f}` });
27014
- }
27015
- if (r.points !== void 0)
27016
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["points"], message: "E2EE request must not carry plaintext points" });
27017
- if (r.ask !== void 0)
27018
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["ask"], message: "E2EE request must not carry a plaintext ask \u2014 derive the shape agent-side and seal it" });
27019
- if (r.needs !== void 0)
27020
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["needs"], message: "E2EE request must not carry plaintext needs" });
27021
- return;
27022
- }
27023
24747
  if (r.ask !== void 0) {
27024
24748
  for (const f of ["context", "select", "points"]) {
27025
24749
  if (r[f] !== void 0)
@@ -27094,13 +24818,6 @@ var init_dist = __esm({
27094
24818
  workId: external_exports.string().uuid().optional(),
27095
24819
  decisionId: external_exports.string().uuid().optional(),
27096
24820
  answer: UserAnswerSchema,
27097
- /** E2EE: present when the answer is sealed. The server relays the opaque answer
27098
- * envelope + the plaintext `ignored` status hint; the receiving agent OPENS it
27099
- * with its device key and re-derives the real UserAnswer, treating a mismatch
27100
- * against `ignored` as tampering. Absent = today's plaintext answer (in `answer`).
27101
- * On a sealed reply the plaintext `answer` is a placeholder (kind reflects only
27102
- * the `ignored` bit) — never the real content, which stays sealed. */
27103
- sealed: external_exports.lazy(() => SealedAnswerSchema).optional(),
27104
24821
  /** WHAT THE AGENT CANNOT KNOW FROM THE FIELDS BESIDE IT (owner, 2026-09-04, issue
27105
24822
  * #1537). One line, built from the record: the ask and the caller's reply VERBATIM,
27106
24823
  * the notification they belong to, and the `contact` call that reaches the person
@@ -27136,7 +24853,7 @@ var init_dist = __esm({
27136
24853
  /** The awaited ask was REPLACED by a newer notification on its thread (e.g. a
27137
24854
  * post-feedback revision, #633) — the user will never answer this id. Stop
27138
24855
  * awaiting it; the live ask is the thread's newest turn (await that one, or
27139
- * re-orient via get_thread / check_replies). */
24856
+ * re-orient via check_replies). */
27140
24857
  external_exports.object({
27141
24858
  type: external_exports.literal("superseded"),
27142
24859
  parentId: external_exports.string(),
@@ -27250,10 +24967,6 @@ var init_dist = __esm({
27250
24967
  options: external_exports.array(OptionSchema).optional(),
27251
24968
  /** The ask's declared coverage points (#396), when the agent sent them. */
27252
24969
  points: external_exports.array(external_exports.string()).optional(),
27253
- /** The call's AGENDA (broker/agenda-design.md): the ordered turns it is made of, built at
27254
- * ring/enqueue time. Replaces the condensed line + index-aligned phrased points, which
27255
- * between them could not express a call as a sequence. `question: null` is a real turn —
27256
- * a status update stays a statement instead of being shaped into a yes/no. */
27257
24970
  /** Does this claim want an ANSWER, or is it telling you something? Written per row from
27258
24971
  * `requestAsks` — the agent's own declaration, not a guess. `false` is what earns a card
27259
24972
  * its acknowledge affordance: without it a status update offers a text box and a dismiss,
@@ -27274,7 +24987,26 @@ var init_dist = __esm({
27274
24987
  * instant the agent picks it up (#997). Absent = pre-trigger row; fall back to
27275
24988
  * `createdAt`. */
27276
24989
  agentStateAt: external_exports.string().datetime().optional(),
27277
- agenda: external_exports.array(AgendaTurnSchema).optional(),
24990
+ /** THE QUESTIONS A CALL CARRIES — the call screen's agenda spine (walk/design.md §11, owner
24991
+ * 2026-09-22). One per DecisionNeed on the Call, in the Call's order, answered or open (a
24992
+ * superseded or cancelled need is no longer a question anyone is asked). Present only on a
24993
+ * Call's cards, and every card of that Call carries the same list: the call screen reads it
24994
+ * once, off the one read it already makes (`GET /api/inbox/:callId`).
24995
+ *
24996
+ * It counts DECISIONS, not agenda turns: turns include context-only lines and are re-planned
24997
+ * every cycle, so a spine drawn from them would change length under the caller mid-call.
24998
+ *
24999
+ * `entryId` is the request Entry — the id the bot calls a CLAIM, and the one it names on the
25000
+ * `turn` topic (`asking`, `settled`), because the bot never sees a DecisionNeed id. `title` is
25001
+ * the card's own concise heading; `answer` the accepted answer in words, null while open. It
25002
+ * REPLACED `agenda` (turns), which nothing ever filled. */
25003
+ questions: external_exports.array(external_exports.object({
25004
+ id: external_exports.string(),
25005
+ entryId: external_exports.string(),
25006
+ title: external_exports.string(),
25007
+ state: external_exports.enum(["open", "answered"]),
25008
+ answer: external_exports.string().nullable()
25009
+ })).optional(),
27278
25010
  visuals: external_exports.array(VisualSchema).optional(),
27279
25011
  /** The connected agent's name (the single pairing name — user-typed, or the
27280
25012
  * agent's suggestion, or a default silly name). */
@@ -27295,12 +25027,21 @@ var init_dist = __esm({
27295
25027
  * client may still flag a stall by age. Drives the inbox error badge + Retry. */
27296
25028
  error: external_exports.string().optional(),
27297
25029
  clarifies: external_exports.string().optional(),
27298
- /** The ring ladder ran out while this was still pending — we tried to reach you and
27299
- * STOPPED trying (`arbitration/arbitrate.ts` `nextRing` → `stop`). Distinct from an
27300
- * agent with nothing to say, which the roster drew identically until now: "nothing to
27301
- * say" and "gave up saying it" are opposite situations wearing the same face
27302
- * (navigation-design.md, gap 1). False for anything that never rang. */
27303
- gaveUp: external_exports.boolean().default(false),
25030
+ /** THE RING, ON THE ITEM (walk/design.md §12 §17, #2251): the last ring on this card was
25031
+ * declined, and what the ladder will do next — read off the cron's own row, never computed
25032
+ * on the phone. Present only while a `declined` receipt stands on the card's last Call.
25033
+ * The ladder is ACCOUNT-WIDE (#2259): `anchorAt` and `step` are the account's position;
25034
+ * `nextRingAt` is this card's armed instant (`deliveries.next_ring_at`), null once the cron
25035
+ * has disarmed it — the curve's end, `inbox`/`dismiss`, or a setting that said no more rings.
25036
+ * It replaced `gaveUp` (deleted 2026-09-22): "the ladder spent" was a boolean the projection
25037
+ * never set, and it is `nextRingAt === null` here — the party's *Missed you* (`party/dress.ts`)
25038
+ * and the roster's `unreached` read `declinedAt`, and stand while it does. */
25039
+ ring: external_exports.object({
25040
+ declinedAt: external_exports.string().datetime(),
25041
+ anchorAt: external_exports.string().datetime(),
25042
+ nextRingAt: external_exports.string().datetime().nullable(),
25043
+ step: external_exports.number().int()
25044
+ }).optional(),
27304
25045
  /** Why this arrived the way it did, read back off the delivery receipt (`notify/why.ts`).
27305
25046
  * Absent for anything never delivered through a push, and for older rows written before
27306
25047
  * the reason was recorded. Deliberately a debug affordance, shown small (owner,
@@ -27322,21 +25063,6 @@ var init_dist = __esm({
27322
25063
  blocking: external_exports.boolean().default(false),
27323
25064
  /** The user's locked-in answer; present only for replied items (GET /api/replied/:id). */
27324
25065
  answer: UserAnswerSchema.optional(),
27325
- /** E2EE (text lane): the sealed content this item carries when the pairing is E2EE, in
27326
- * place of the plaintext `context`/`options`/`visuals` (which the operator would
27327
- * otherwise read). A per-field map of opaque Envelopes — the SAME shape as
27328
- * NotifyRequest.envelope. The native app decrypts it locally via openNotification;
27329
- * web / an un-enrolled device can't and renders a locked placeholder. Absent = today's
27330
- * plaintext item (context carries the cleartext), so plaintext items are unchanged. */
27331
- envelope: external_exports.object({
27332
- context: external_exports.lazy(() => EnvelopeSchema).optional(),
27333
- options: external_exports.lazy(() => EnvelopeSchema).optional(),
27334
- visuals: external_exports.lazy(() => EnvelopeSchema).optional()
27335
- }).optional(),
27336
- /** E2EE: the agent's device X25519 public key to seal the user's answer BACK to (the
27337
- * sender the phone replies to). Sourced server-side from this item's pairing credential.
27338
- * Present only alongside `envelope`; the phone seals via sealAnswer(answer, this, id). */
27339
- agentX25519: external_exports.string().optional(),
27340
25066
  /** THE TARGET FACTS A CARD RENDERS (#1796 point 5, 2026-09-11): the Delivery it is a view of,
27341
25067
  * that Delivery's kind, the request Entry, the Goals it answers for, the exact DecisionNeed (none
27342
25068
  * for a request that asks nothing), whether its content is sealed, and that Goal's state. The
@@ -27380,6 +25106,8 @@ var init_dist = __esm({
27380
25106
  "inbox",
27381
25107
  "dismiss"
27382
25108
  ]);
25109
+ clock = (h) => h === 0 ? "midnight" : h === 12 ? "noon" : h < 12 ? `${h} am` : `${h - 12} pm`;
25110
+ QUIET = ` Nothing rings from ${clock(NIGHT.from)} to ${clock(NIGHT.to)} your time; the count waits for morning.`;
27383
25111
  BrokerTuningSchema = external_exports.object({
27384
25112
  /** 'none' = skip the spoken ack after a mapped answer (power users find it slow). */
27385
25113
  ackVerbosity: external_exports.enum(["normal", "none"]).optional(),
@@ -27414,6 +25142,12 @@ var init_dist = __esm({
27414
25142
  * must not silently reset this privacy choice. Absent = leave unchanged on
27415
25143
  * write, 'hosted' on read (see store.ts). */
27416
25144
  voiceMode: external_exports.enum(["hosted", "on_device"]).optional(),
25145
+ /** Talk — after you answer, the next step is read aloud (walk/design.md §6). ALWAYS ON until
25146
+ * turned off (owner, 2026-09-18, #2249): a setting, not a per-walk toggle. Optional, NOT
25147
+ * defaulted, for the same reason `voiceMode` is: a stale client PATCHing the full settings
25148
+ * object must not silently turn it back on. Absent = leave unchanged on write, true on
25149
+ * read (see store.ts). */
25150
+ talk: external_exports.boolean().optional(),
27417
25151
  /** Per-user ring budget (#603): calls per rolling day before further calls
27418
25152
  * degrade to banner. Absent = the global default (25). A number, never a
27419
25153
  * bypass — every account keeps a ceiling. No UI; set per user for testing. */
@@ -27434,13 +25168,6 @@ var init_dist = __esm({
27434
25168
  * setting. Absent = a spoken time can't be landed, so the reminder rides the next
27435
25169
  * call — honest about what we know. */
27436
25170
  timezone: external_exports.string().min(1).max(64).optional(),
27437
- /** Account E2EE state (text lane): 'off' (default) = today's plaintext; 'on' =
27438
- * content is sealed end-to-end between the local agent and the phone. Like
27439
- * voiceMode, OPTIONAL and NOT defaulted so a stale client PATCHing the full
27440
- * settings object without it can't silently flip the account's E2EE state.
27441
- * Absent = leave unchanged on write, 'off' on read (see store.ts). The demo
27442
- * account is plaintext by construction and refuses any non-'off' value. */
27443
- e2eeMode: external_exports.enum(["off", "on"]).optional(),
27444
25171
  /** Rung-2 broker tuning (#381). Optional and NOT defaulted, same stale-client
27445
25172
  * clobber guard as voiceMode: absent = leave unchanged on write. */
27446
25173
  broker: BrokerTuningSchema.optional()
@@ -27618,6 +25345,9 @@ var init_dist = __esm({
27618
25345
  assignee: external_exports.string().nullable().default(null),
27619
25346
  /** What the agent last said it was doing; null if it has said nothing. */
27620
25347
  progress: external_exports.string().nullable().default(null),
25348
+ /** HOME'S LINE FOR THAT NOTE (owner, 2026-09-23): a few plain words one read wrote from `progress`,
25349
+ * served only while it was written for the current note. Null means show the Goal's name. */
25350
+ progressLine: external_exports.string().nullable().optional(),
27621
25351
  reviewPending: external_exports.boolean().default(false),
27622
25352
  dueAt: external_exports.string().nullable().default(null),
27623
25353
  /** The Goal this one was opened under; null at the root. */
@@ -27630,9 +25360,16 @@ var init_dist = __esm({
27630
25360
  blocked: external_exports.boolean().default(false),
27631
25361
  /** Every decision need on it, open or settled — the page decides which to show. */
27632
25362
  questions: external_exports.array(QueueQuestionSchema).default([]),
25363
+ /** The repository or project identifier this Goal belongs to (#2280), null if untracked. */
25364
+ repo: external_exports.string().nullable().optional(),
27633
25365
  createdAt: external_exports.string(),
27634
- updatedAt: external_exports.string().nullable().default(null)
25366
+ updatedAt: external_exports.string().nullable().default(null),
25367
+ /** When its owner last SAID something about it (`goals.last_progress_at`, written by every
25368
+ * `update_goal` that changes `progress`). `updatedAt` moves for reasons nobody chose — a
25369
+ * state recomputed, a review flag — so it cannot tell work in hand from work gone quiet. */
25370
+ lastProgressAt: external_exports.string().nullable().optional()
27635
25371
  });
25372
+ COLD_AFTER_MS = 3 * 24 * 60 * 60 * 1e3;
27636
25373
  NoteSourceSchema = external_exports.enum(["app", "call"]);
27637
25374
  NoteStatusSchema = external_exports.enum(["open", "assigned", "in_progress", "done"]);
27638
25375
  NoteRepeatSchema = external_exports.enum(["once", "until_done"]);
@@ -27743,54 +25480,12 @@ var init_dist = __esm({
27743
25480
  * carries credentials; only a `poll` registration can come back with null here. */
27744
25481
  realtime: external_exports.object({ url: external_exports.string(), anonKey: external_exports.string() }).nullable()
27745
25482
  });
27746
- EnvelopeRecipientSchema = external_exports.object({
27747
- keyId: external_exports.string(),
27748
- epk: external_exports.string(),
27749
- wnonce: external_exports.string(),
27750
- wrap: external_exports.string()
27751
- });
27752
- EnvelopeHeaderSchema = external_exports.object({
27753
- field: external_exports.enum(["context", "options", "visuals", "answer"]),
27754
- kind: external_exports.string(),
27755
- senderRole: external_exports.enum(["agent", "user"]),
27756
- recipientKeyIds: external_exports.array(external_exports.string()),
27757
- seq: external_exports.number().int().nonnegative()
27758
- });
27759
- EnvelopeSchema = external_exports.object({
27760
- v: external_exports.literal(1),
27761
- alg: external_exports.literal("x25519-xsalsa20poly1305"),
27762
- msgId: external_exports.string(),
27763
- hdr: EnvelopeHeaderSchema,
27764
- recipients: external_exports.array(EnvelopeRecipientSchema).min(1),
27765
- nonce: external_exports.string(),
27766
- ct: external_exports.string()
27767
- });
27768
- SealedAnswerSchema = external_exports.object({
27769
- ignored: external_exports.boolean(),
27770
- envelope: EnvelopeSchema
27771
- });
27772
- DeviceCredentialSchema = external_exports.object({
27773
- deviceId: external_exports.string(),
27774
- kind: external_exports.enum(["phone", "web", "agent"]),
27775
- x25519Pub: external_exports.string(),
27776
- ed25519Pub: external_exports.string(),
27777
- sig: external_exports.string()
27778
- });
27779
- DeviceRosterSchema = external_exports.object({
27780
- uikPub: external_exports.string(),
27781
- devices: external_exports.array(DeviceCredentialSchema)
27782
- });
27783
25483
  WakeNudgeSchema = external_exports.object({
27784
25484
  kind: external_exports.enum(["reply", "request", "callback"]),
27785
25485
  notificationId: external_exports.string().optional(),
27786
25486
  parentId: external_exports.string()
27787
25487
  });
27788
25488
  PairingStatusSchema = external_exports.enum(["pending", "approved", "denied", "expired"]);
27789
- PairingRevealSchema = external_exports.object({
27790
- x25519: external_exports.string(),
27791
- ed25519: external_exports.string(),
27792
- nonce: external_exports.string()
27793
- });
27794
25489
  DeviceCodeSchema = external_exports.object({
27795
25490
  device_code: external_exports.string(),
27796
25491
  user_code: external_exports.string(),
@@ -27810,19 +25505,7 @@ var init_dist = __esm({
27810
25505
  * (seen live: PAIGY-5T, 2026-07-21). Remove once a newer binary is the floor. */
27811
25506
  agent: external_exports.string().optional(),
27812
25507
  device: external_exports.string().nullable(),
27813
- status: PairingStatusSchema,
27814
- proto: external_exports.string().nullable().optional(),
27815
- agent_commitment: external_exports.string().nullable().optional(),
27816
- // Ca
27817
- agent_reveal: PairingRevealSchema.nullable().optional(),
27818
- // present once the agent reveals
27819
- agent_credential: DeviceCredentialSchema.nullable().optional(),
27820
- // the phone's UIK-signed cred over the agent's keys — the agent fetches it here to finalizeE2ee
27821
- // The phone's reveal + identity key, exposed here so a GATED agent (e2ee_mode='on', token
27822
- // withheld until e2ee=true) can compute the SAS WITHOUT a token. Public keys — same safety
27823
- // class as agent_reveal above. Present only once the phone reveals; null otherwise.
27824
- phone_reveal: PairingRevealSchema.nullable().optional(),
27825
- uik_pub: external_exports.string().nullable().optional()
25508
+ status: PairingStatusSchema
27826
25509
  });
27827
25510
  DeviceTokenSchema = external_exports.object({
27828
25511
  access_token: external_exports.string(),
@@ -27841,8 +25524,6 @@ var init_dist = __esm({
27841
25524
  * landed in the FIRST granted workspace and the agent rediscovered its own repo from
27842
25525
  * the thread each time (host.ts, live catch 2026-08-06 — prompt-papered until now). */
27843
25526
  workspace: external_exports.string().nullable().optional(),
27844
- phone_reveal: PairingRevealSchema.nullable().optional(),
27845
- // present once the phone reveals
27846
25527
  uik_pub: external_exports.string().nullable().optional()
27847
25528
  });
27848
25529
  SupportRequestSchema = external_exports.object({
@@ -27864,21 +25545,8 @@ var init_dist = __esm({
27864
25545
  "other"
27865
25546
  // anything else — the note carries it.
27866
25547
  ]);
27867
- FeedbackResolutionSchema = external_exports.enum(["broker_fixed", "sent_to_agent"]);
27868
- FeedbackOutcomeSchema = external_exports.object({
27869
- resolution: FeedbackResolutionSchema,
27870
- transform: TransformSchema,
27871
- message: external_exports.string(),
27872
- childIds: external_exports.array(external_exports.string()).optional()
27873
- });
27874
- import_tweetnacl = __toESM2(require_nacl_fast(), 1);
27875
- import_tweetnacl2 = __toESM2(require_nacl_fast(), 1);
27876
- import_tweetnacl3 = __toESM2(require_nacl_fast(), 1);
27877
- import_tweetnacl4 = __toESM2(require_nacl_fast(), 1);
27878
- import_tweetnacl5 = __toESM2(require_nacl_fast(), 1);
27879
- AGENT_NAME = process.env.PAIGY_AGENT || sessionSlot();
27880
- TOKEN_PATH = join2(homedir2(), ".paigy", "token.json");
27881
- KEY_PATH = join2(homedir2(), ".paigy", "key.json");
25548
+ TOKEN_PATH = join22(homedir22(), ".paigy", "token.json");
25549
+ KEY_PATH = join22(homedir22(), ".paigy", "key.json");
27882
25550
  sleep = (ms) => new Promise((r) => setTimeout(r, ms));
27883
25551
  UnpairedError = class extends Error {
27884
25552
  constructor() {
@@ -27901,9 +25569,9 @@ var init_dist = __esm({
27901
25569
  this.body = body;
27902
25570
  }
27903
25571
  };
27904
- AWAIT_WINDOW_MS = 45e3;
27905
25572
  tokenOverride = null;
27906
25573
  authToken = (explicit) => explicit ?? tokenOverride ?? readToken();
25574
+ AWAIT_WINDOW_MS = 45e3;
27907
25575
  HEARTBEAT_MS = 25e3;
27908
25576
  RETRY_MS = [1e3, 2e3, 5e3, 1e4, 3e4];
27909
25577
  JOIN = { config: { broadcast: { self: false } } };
@@ -31383,7 +29051,7 @@ var require_sync_inflate = __commonJS({
31383
29051
  if (typeof asyncCb === "function") {
31384
29052
  return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
31385
29053
  }
31386
- let self2 = this;
29054
+ let self = this;
31387
29055
  let availInBefore = chunk && chunk.length;
31388
29056
  let availOutBefore = this._chunkSize - this._offset;
31389
29057
  let leftToInflate = this._maxLength;
@@ -31395,14 +29063,14 @@ var require_sync_inflate = __commonJS({
31395
29063
  error = err;
31396
29064
  });
31397
29065
  function handleChunk(availInAfter, availOutAfter) {
31398
- if (self2._hadError) {
29066
+ if (self._hadError) {
31399
29067
  return;
31400
29068
  }
31401
29069
  let have = availOutBefore - availOutAfter;
31402
29070
  assert(have >= 0, "have should not go down");
31403
29071
  if (have > 0) {
31404
- let out = self2._buffer.slice(self2._offset, self2._offset + have);
31405
- self2._offset += have;
29072
+ let out = self._buffer.slice(self._offset, self._offset + have);
29073
+ self._offset += have;
31406
29074
  if (out.length > leftToInflate) {
31407
29075
  out = out.slice(0, leftToInflate);
31408
29076
  }
@@ -31413,10 +29081,10 @@ var require_sync_inflate = __commonJS({
31413
29081
  return false;
31414
29082
  }
31415
29083
  }
31416
- if (availOutAfter === 0 || self2._offset >= self2._chunkSize) {
31417
- availOutBefore = self2._chunkSize;
31418
- self2._offset = 0;
31419
- self2._buffer = Buffer.allocUnsafe(self2._chunkSize);
29084
+ if (availOutAfter === 0 || self._offset >= self._chunkSize) {
29085
+ availOutBefore = self._chunkSize;
29086
+ self._offset = 0;
29087
+ self._buffer = Buffer.allocUnsafe(self._chunkSize);
31420
29088
  }
31421
29089
  if (availOutAfter === 0) {
31422
29090
  inOff += availInBefore - availInAfter;
@@ -32517,9 +30185,9 @@ async function available(deps = {}) {
32517
30185
  });
32518
30186
  return [ollama, ...harnesses];
32519
30187
  }
32520
- function refusal(options, asked) {
30188
+ function refusal(options, asked2) {
32521
30189
  const lines2 = [
32522
- asked ? `Can't judge with --via ${asked}: ${options.find((o) => o.provider === asked)?.hint ?? "it isn't available on this machine"}` : "No local judge available \u2014 triage refuses rather than sending your queue to a cloud model.",
30190
+ asked2 ? `Can't judge with --via ${asked2}: ${options.find((o) => o.provider === asked2)?.hint ?? "it isn't available on this machine"}` : "No local judge available \u2014 triage refuses rather than sending your queue to a cloud model.",
32523
30191
  "",
32524
30192
  "Triage runs the model where your queue already lives (#1106). Your options:"
32525
30193
  ];
@@ -32530,10 +30198,10 @@ function refusal(options, asked) {
32530
30198
  lines2.push("", "Then re-run: paigy-harness triage [--via ollama|claude|codex|agy]");
32531
30199
  return lines2.join("\n");
32532
30200
  }
32533
- async function judgeFor(asked, deps = {}) {
30201
+ async function judgeFor(asked2, deps = {}) {
32534
30202
  const options = await available(deps);
32535
- const chosen = asked ? options.find((o) => o.provider === asked) : options.find((o) => o.ready);
32536
- if (!chosen?.ready) return { error: refusal(options, asked) };
30203
+ const chosen = asked2 ? options.find((o) => o.provider === asked2) : options.find((o) => o.ready);
30204
+ if (!chosen?.ready) return { error: refusal(options, asked2) };
32537
30205
  if (chosen.provider === "ollama") {
32538
30206
  const model = chosen.model;
32539
30207
  return {
@@ -32554,9 +30222,9 @@ async function judgeFor(asked, deps = {}) {
32554
30222
  };
32555
30223
  }
32556
30224
  const runner = RUNNERS[chosen.provider];
32557
- if (!runner) return { error: refusal(options, asked) };
30225
+ if (!runner) return { error: refusal(options, asked2) };
32558
30226
  const bin = which(runner.cli);
32559
- if (!bin) return { error: refusal(options, asked) };
30227
+ if (!bin) return { error: refusal(options, asked2) };
32560
30228
  return {
32561
30229
  provider: chosen.provider,
32562
30230
  model: null,
@@ -33152,7 +30820,7 @@ function onEnter(input, onLine) {
33152
30820
  init_dist();
33153
30821
  var import_qrcode = __toESM(require_lib(), 1);
33154
30822
  import { hostname } from "os";
33155
- import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "fs";
30823
+ import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "fs";
33156
30824
  import { execFile as execFile2, execSync } from "child_process";
33157
30825
  import { homedir as homedir8 } from "os";
33158
30826
  import { join as join7 } from "path";
@@ -33415,7 +31083,13 @@ function startSession(opts) {
33415
31083
  ...process.env,
33416
31084
  PATH: [process.env.PATH, ...probeDirs()].filter(Boolean).join(delimiter2),
33417
31085
  ...opts.token ? { PAIGY_TOKEN: opts.token } : {},
33418
- ...opts.resume ? { PAIGY_SESSION_ID: opts.resume } : {}
31086
+ ...opts.resume ? { PAIGY_SESSION_ID: opts.resume } : {},
31087
+ // A PUMP DRIVES THIS PROCESS (2026-09-22, #2265): every run `runHarness` starts has the
31088
+ // bridge's pump typing answers in, so nothing inside it may start a second delivery path.
31089
+ // Exported on EVERY spawn — `PAIGY_SESSION_ID` above is the conversation to resume, and a
31090
+ // fresh spawn has none, which is how a fresh run read as "not harness-started" to the
31091
+ // session-start hook and the `listen` tool (they now test either mark; listening.ts).
31092
+ PAIGY_HARNESS: "1"
33419
31093
  },
33420
31094
  stdio: ["pipe", "pipe", "pipe"]
33421
31095
  });
@@ -33464,6 +31138,7 @@ function startSession(opts) {
33464
31138
  // ../../packages/schema/dist/index.js
33465
31139
  init_zod();
33466
31140
  init_zod();
31141
+ init_zod();
33467
31142
 
33468
31143
  // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
33469
31144
  var ignoreOverride2 = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
@@ -34760,6 +32435,23 @@ var zodToJsonSchema2 = (schema, options) => {
34760
32435
  init_zod();
34761
32436
  var OPTIONS_MIN2 = 2;
34762
32437
  var OPTIONS_MAX2 = 6;
32438
+ var OptionSchema2 = external_exports.object({
32439
+ id: external_exports.string(),
32440
+ label: external_exports.string(),
32441
+ hint: external_exports.string().max(500).describe("Optional short projection of consequence or action if this option is chosen (e.g. 'Reruns test suite', 'Merges to main').").optional(),
32442
+ // .describe() flows into the MCP contact JSON schema (zodToJsonSchema), so
32443
+ // the constraints below are what an agent reads when deciding to use these.
32444
+ html: external_exports.string().max(16384).describe(
32445
+ "Optional sandboxed HTML/CSS preview for a visual 'pick one' (shown in the option card). Untrusted-sandboxed: NO JavaScript, NO external network or images \u2014 inline CSS and data: URIs only; <=16KB. Rendered edge-to-edge in a responsive card that is 200pt tall (about 320pt wide on a phone, with the next option peeking beside it); make your HTML fit that viewport. Use for layout/CSS mockups, tables, diffs. For a hosted image use `image` instead."
32446
+ ).optional(),
32447
+ image: external_exports.string().url().describe(
32448
+ "Optional image URL rendered as the option's preview (plain image, not sandboxed). For agent-generated HTML/CSS mockups, use `html` instead."
32449
+ ).optional()
32450
+ });
32451
+ var OptionInputSchema2 = OptionSchema2.omit({ id: true }).extend({
32452
+ label: external_exports.string().trim().min(1).max(1e3)
32453
+ }).strict();
32454
+ var NIGHT2 = { from: 23, to: 7 };
34763
32455
  function draft20202(node) {
34764
32456
  if (Array.isArray(node)) return node.map(draft20202);
34765
32457
  if (node && typeof node === "object") {
@@ -34789,32 +32481,23 @@ function mcpInputSchema2(s) {
34789
32481
  delete schema.$schema;
34790
32482
  return draft20202(schema);
34791
32483
  }
34792
- var StartContactSchema2 = external_exports.object({
34793
- goalIds: external_exports.tuple([external_exports.string().uuid()]),
34794
- // THE ASK IS THE QUESTION, not a bulletin with a question at the end (2026-09-16).
34795
- //
34796
- // A DecisionNeed is settled only by an answer in the shape THIS ask declares. Bundle news,
34797
- // findings and a decision into one, and the person answers whichever part engaged them —
34798
- // which settles nothing, leaves the need open, and gets them asked again. On call 619c5a92
34799
- // one ask carried a briefing, a side question ("the ring should show the agent's name now —
34800
- // what did you actually see?") and a one-of-four about how far an erase reaches. The owner
34801
- // answered the side question. The need stayed open; the card asked again. Of the 45 call
34802
- // asks carrying a decision, 27 are over 600 characters.
34803
- //
34804
- // Sending them separately costs nothing, because a CALL contact joins the call already
34805
- // happening (`goal/store.ts`, JOIN BEFORE MINTING) — several contacts on one Goal arrive as
34806
- // one call, planned as its turns, and each keeps its own settleable need.
32484
+ var AskInputSchema2 = external_exports.object({
32485
+ id: external_exports.string().optional().describe("Optional idempotency key or client-side ID for this specific ask."),
32486
+ parentId: external_exports.string().uuid().optional().describe("The Goal this question is about \u2014 usually the one you are working on. The question goes onto that Goal and its answer comes back there. Omit it and Paigy places the question in the tree itself."),
32487
+ repo: external_exports.string().optional().describe("Optional repository context."),
34807
32488
  ask: external_exports.string().trim().min(1).max(1e4).describe(
34808
32489
  "The question, and only what is needed to answer it. News, progress and findings are their own contact \u2014 a call contact JOINS a call already happening, so several arrive as one call. Do not bundle: a DecisionNeed is settled only by an answer in the shape this ask declares, so someone who answers the part that interested them settles nothing and is asked again."
34809
32490
  ),
32491
+ options: external_exports.array(OptionInputSchema2).min(2).max(6).optional()
32492
+ }).strict();
32493
+ var StartContactSchema2 = external_exports.object({
32494
+ asks: external_exports.array(AskInputSchema2).min(1).describe("The questions to pose, one per object. An ask with a parentId is filed on that Goal as it is; only an ask naming no Goal is placed in the tree by Paigy."),
34810
32495
  waiting: external_exports.enum(["none", "hard"]).default("none"),
34811
- channel: external_exports.enum(["notification", "call"]).default("notification"),
34812
- options: external_exports.array(external_exports.object({ label: external_exports.string().trim().min(1).max(1e3), image: external_exports.string().url().optional(), html: external_exports.string().max(16384).optional() }).strict()).min(2).max(6).optional(),
34813
- threadId: external_exports.string().uuid().optional().describe("Continue an existing Thread: the threadId a prior Delivery returned. Omit to start a new Thread.")
32496
+ channel: external_exports.enum(["notification", "call"]).default("notification")
34814
32497
  }).strict();
34815
32498
  var ContactSchema2 = external_exports.union([StartContactSchema2, external_exports.object({ deliveryId: external_exports.string().uuid() }).strict()]);
34816
32499
  var CONTACT_SCHEMA2 = { type: "object", ...mcpInputSchema2(ContactSchema2) };
34817
- var CONTACT_DESCRIPTION2 = "Contact the user about exactly one existing Goal: pass goalIds:[goalId], ask, channel:'notification'|'call', and waiting:'none'|'hard'. Options supply choices. Notification returns immediately; collect durable answers with claim_goal/get_goal. On stdio, a Call holds one cancellable ~45s window; continue with ONLY {deliveryId}. Continuation sends nothing and rereads the same durable evidence, including previously read answers. Entries retain authorship and provenance; accepted decisions are separate from quoted speech. Call state open does not mean ringing. Unsupported: soft waiting, multiple Goals/questions, outcome admission, and re-presentation of an existing request. Create a Goal explicitly first; never resend a pending ask to continue waiting.";
32500
+ var CONTACT_DESCRIPTION2 = "Contact the user with one or more asks/questions. Pass an array of asks (each with 'ask', optional 'options', 'id', 'parentId', 'repo'), plus channel:'notification'|'call', and waiting:'none'|'hard'. An ask that names a Goal (parentId) goes onto that Goal; one that names none is placed in the person's tree by Paigy. Notification returns immediately; collect durable answers with check_replies. On stdio, a Call holds one cancellable ~45s window; continue with ONLY {deliveryId}. Never bundle multiple questions into a single 'ask' string; pass them as separate objects in the 'asks' array.";
34818
32501
  var CreateGoalSchema2 = external_exports.object({
34819
32502
  outcome: external_exports.string().trim().min(1).max(1e4),
34820
32503
  /** The work's NAME (#2115) — one to five words, how a person refers to it out loud ("the night
@@ -34822,11 +32505,6 @@ var CreateGoalSchema2 = external_exports.object({
34822
32505
  title: external_exports.string().trim().min(1).max(80).optional(),
34823
32506
  ownerParticipant: external_exports.string().trim().min(1).optional(),
34824
32507
  idempotencyKey: external_exports.string().trim().min(1).max(200),
34825
- /** A past conversation this Goal should be read against — History's "new session from this"
34826
- * (owner, on the call of 2026-09-14: "let's do the reference with the threading"). A
34827
- * reference only: the owner reads it through `get_thread`, which does its own scoping, and
34828
- * the writer refuses a thread belonging to another account. */
34829
- contextThreadId: external_exports.string().uuid().optional(),
34830
32508
  /** THE GOAL THIS ONE BELONGS UNDER (owner, 2026-09-15: "the ask I gave for the design doc
34831
32509
  * didn't get created as a child goal of the voice UI goal, which is how it should've
34832
32510
  * worked"). It could not have been: this door took no parent, so the only route was
@@ -34834,12 +32512,15 @@ var CreateGoalSchema2 = external_exports.object({
34834
32512
  * took the short one. The hierarchy has been modelled since Goals existed and had been used
34835
32513
  * ZERO times in 2,031 of them. Absent, the server judges it against the caller's open Goals
34836
32514
  * (`apps/api/src/goal/intake.ts`). The writer refuses a Goal belonging to another account. */
34837
- parentGoalId: external_exports.string().uuid().optional()
32515
+ parentGoalId: external_exports.string().uuid().optional(),
32516
+ /** The repository or project identifier this Goal belongs to (#2280) — e.g. "owner/repo" or
32517
+ * repo name. Delegated work inherits this from its parent Goal when omitted. */
32518
+ repo: external_exports.string().trim().min(1).max(200).optional()
34838
32519
  });
34839
32520
  var CreateGoalToolSchema2 = CreateGoalSchema2.extend({
34840
32521
  idempotencyKey: CreateGoalSchema2.shape.idempotencyKey.optional().describe("Optional. One is minted per call; pass your own only so a retry lands on the same Goal.")
34841
32522
  }).strict();
34842
- var CREATE_GOAL_DESCRIPTION2 = 'Create a durable Goal for an outcome. Without parentGoalId it is placed against your open Goals: if one already IS this work, that Goal comes back (existing: true) and nothing new is created \u2014 continue it; if the work belongs under one, it is created there (parentGoalId in the receipt); otherwise it is a root. Pass parentGoalId yourself to put it under a specific Goal. Pass title to name it in one to five words, as a person would refer to it out loud ("the night rings") \u2014 it heads every list and is spoken on a call; without one the brain writes it. Admission only: the owner must claim it before doing work, then update it as it advances. Returns an admission receipt with goalId, current state, revision, ownerParticipant, and the next step; no Goal content or execution lease.';
32523
+ var CREATE_GOAL_DESCRIPTION2 = 'Create a durable Goal for an outcome. Without parentGoalId it is placed against your open Goals: if one already IS this work, that Goal comes back (existing: true) and nothing new is created \u2014 continue it; if the work belongs under one, it is created there (parentGoalId in the receipt); otherwise it is a root. Pass parentGoalId yourself to put it under a specific Goal. Pass repo to anchor the work to a specific repository ("owner/repo" or repo name); delegated children inherit it. Pass title to name it in one to five words, as a person would refer to it out loud ("the night rings") \u2014 it heads every list and is spoken on a call; without one the brain writes it. Admission only: the owner must claim it before doing work, then update it as it advances. Returns an admission receipt with goalId, current state, revision, ownerParticipant, and the next step; no Goal content or execution lease.';
34843
32524
  var UpdateGoalSchema2 = external_exports.object({
34844
32525
  revision: external_exports.number().int().positive(),
34845
32526
  changes: external_exports.object({
@@ -34867,19 +32548,9 @@ var UPDATE_GOAL_DESCRIPTION2 = "Update an owned Goal at an exact revision. State
34867
32548
  var CLAIM_GOAL_DESCRIPTION2 = "Claim the oldest runnable or review-pending Goal you own, or pass goalId to claim that Goal. Returns the Goal as get_goal reads it, and creates or renews the execution lease.";
34868
32549
  var CHECK_REPLIES_DESCRIPTION2 = "Your open Deliveries: every Notification or Call currently addressed to you \u2014 a request the user started toward you, an answer relayed to something you asked, a handoff \u2014 one row each: its Goals, how many decisions are still open, and the newest words in brief. A pure read with no arguments: nothing is consumed, acknowledged or claimed by reading it, so call it on startup, after a long wait, or whenever you want to know what is outstanding. To act on one, claim its Goal (claim_goal) or reread it in full with contact({deliveryId}). Once you have acted on what arrived, update_goal with reviewed: true closes the Deliveries addressed to you on that Goal. Your runnable and review-pending Goals come from claim_goal, not from here.";
34869
32550
  var CheckRepliesSchema2 = external_exports.object({}).strict();
34870
- var GetThreadSchema2 = external_exports.object({
34871
- parentId: external_exports.string().describe("The Thread to read \u2014 the threadId a Delivery returned, or the parentId of a search hit.")
34872
- }).strict();
34873
- var GET_THREAD_DESCRIPTION2 = "Read the authorized durable Entries on one conversation Thread \u2014 what you wrote there and what was delivered to you, oldest first. Use claim_goal to find the work to resume; use this to rehydrate a Thread that a search hit or a Delivery named.";
34874
- var SearchThreadsSchema2 = external_exports.object({
34875
- q: external_exports.string().describe("What to look for \u2014 plain words or a phrase (e.g. 'the livekit timeout', 'deploy to prod').")
34876
- }).strict();
34877
- var SEARCH_THREADS_DESCRIPTION2 = `Search your PAST conversations before asking \u2014 "have we discussed this before?". Full-text over your own threads (the asks you sent + the user's answers); returns ranked threads with highlighted snippets, NOT rows: { hits: [{ parentId, at, agentLabel, matches: [{ notificationId, role, snippet }] }] }. The loop this exists for: search first \u2192 get_thread the best hit to rehydrate it \u2192 THEN continue or contact, so you answer with receipts ("last week you said ship it") instead of re-asking. Read-only, safe to call anytime; scoped to your own account's threads.`;
34878
32551
  var AGENT_TOOLS2 = [
34879
32552
  { name: "contact", description: CONTACT_DESCRIPTION2, inputSchema: CONTACT_SCHEMA2 },
34880
32553
  { name: "check_replies", description: CHECK_REPLIES_DESCRIPTION2, inputSchema: mcpInputSchema2(CheckRepliesSchema2) },
34881
- { name: "get_thread", description: GET_THREAD_DESCRIPTION2, inputSchema: mcpInputSchema2(GetThreadSchema2) },
34882
- { name: "search_threads", description: SEARCH_THREADS_DESCRIPTION2, inputSchema: mcpInputSchema2(SearchThreadsSchema2) },
34883
32554
  { name: "create_goal", description: CREATE_GOAL_DESCRIPTION2, inputSchema: mcpInputSchema2(CreateGoalToolSchema2) },
34884
32555
  { name: "claim_goal", description: CLAIM_GOAL_DESCRIPTION2, inputSchema: mcpInputSchema2(ClaimGoalSchema2) },
34885
32556
  { name: "get_goal", description: GET_GOAL_DESCRIPTION2, inputSchema: mcpInputSchema2(GetGoalSchema2) },
@@ -34928,18 +32599,6 @@ var TransformSchema2 = external_exports.enum([
34928
32599
  "summarize"
34929
32600
  // reduce volume, keep decision value — 30-turn cap, spoken briefing
34930
32601
  ]);
34931
- var OptionSchema2 = external_exports.object({
34932
- id: external_exports.string(),
34933
- label: external_exports.string(),
34934
- // .describe() flows into the MCP contact JSON schema (zodToJsonSchema), so
34935
- // the constraints below are what an agent reads when deciding to use these.
34936
- html: external_exports.string().max(16384).describe(
34937
- "Optional sandboxed HTML/CSS preview for a visual 'pick one' (shown in the option card). Untrusted-sandboxed: NO JavaScript, NO external network or images \u2014 inline CSS and data: URIs only; <=16KB. Use for layout/CSS mockups, tables, diffs. For a hosted image use `image` instead."
34938
- ).optional(),
34939
- image: external_exports.string().url().describe(
34940
- "Optional image URL rendered as the option's preview (plain image, not sandboxed). For agent-generated HTML/CSS mockups, use `html` instead."
34941
- ).optional()
34942
- });
34943
32602
  var VisualSchema2 = external_exports.object({
34944
32603
  url: external_exports.string().url(),
34945
32604
  label: external_exports.string().optional()
@@ -34993,7 +32652,7 @@ var NotifyRequestFields2 = external_exports.object({
34993
32652
  * ABSENT on the E2EE path, where the sealed `envelope` below carries it. The
34994
32653
  * superRefine at the bottom enforces exactly one of the two. */
34995
32654
  context: ContextSchema2.optional(),
34996
- options: external_exports.array(OptionSchema2.omit({ id: true })).min(OPTIONS_MIN2).max(OPTIONS_MAX2).optional().describe(
32655
+ options: external_exports.array(OptionInputSchema2).min(OPTIONS_MIN2).max(OPTIONS_MAX2).optional().describe(
34997
32656
  "The choices, in order \u2014 required when select is 'one'/'many'/'rank', omitted otherwise. Ids are assigned automatically by position ('1', '2', \u2026); the user's answer references them as optionId(s)."
34998
32657
  ),
34999
32658
  points: external_exports.array(external_exports.string().min(1)).optional().describe(
@@ -35025,23 +32684,6 @@ var NotifyRequestFields2 = external_exports.object({
35025
32684
  * when `parentId` became the conversation handle: `parentId` says WHERE, this
35026
32685
  * says HOW. */
35027
32686
  clarifies: external_exports.string().optional(),
35028
- /** E2EE (text lane): when the pairing is E2EE, the sealed replacements for the
35029
- * plaintext content fields, keyed by field name. FINALIZED wire shape (was
35030
- * provisional in the storage PR): a per-field map `{ context?, options?,
35031
- * visuals? }` of opaque Envelopes — one seal per present content field, so a
35032
- * message with no options/visuals seals only `context`. It COEXISTS with the
35033
- * plaintext fields by mutual exclusion: the superRefine below requires that
35034
- * when `envelope` is present the plaintext `context`/`options`/`visuals` are
35035
- * ABSENT (and vice-versa), so a row is either fully plaintext or fully sealed —
35036
- * never a readable half. The server persists this OPAQUELY into
35037
- * notifications.envelope and relays it blindly; it never decrypts. Absent =
35038
- * today's plaintext path (context/options/visuals carry the cleartext).
35039
- * z.lazy because EnvelopeSchema is declared further down (E2EE section). */
35040
- envelope: external_exports.object({
35041
- context: external_exports.lazy(() => EnvelopeSchema2).optional(),
35042
- options: external_exports.lazy(() => EnvelopeSchema2).optional(),
35043
- visuals: external_exports.lazy(() => EnvelopeSchema2).optional()
35044
- }).optional(),
35045
32687
  select: SelectShapeSchema2.optional().describe(
35046
32688
  "How the user answers \u2014 required on the fully-shaped form, pick the shape that fits the question: 'one' = pick one option, 'many' = pick several, 'rank' = pick & order (each needs `options`); 'confirm' = yes/no or approve/deny; 'text' = free-form reply only (status updates, open questions). 'confirm' and 'text' take no options. Omit only when sending the simplified `ask` form \u2014 the broker picks the shape."
35047
32689
  ),
@@ -35095,22 +32737,6 @@ var NotifyRequestFields2 = external_exports.object({
35095
32737
  });
35096
32738
  var NotifyRequestSchema2 = NotifyRequestFields2.superRefine((r, ctx) => {
35097
32739
  if (r.workId && r.goalId) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["goalId"], message: "pass goalId or workId, not both" });
35098
- const sealed = !!r.envelope;
35099
- if (sealed) {
35100
- if (!r.envelope?.context)
35101
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["envelope", "context"], message: "sealed request must include envelope.context" });
35102
- for (const f of ["context", "options", "visuals"]) {
35103
- if (r[f] !== void 0)
35104
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: [f], message: `E2EE request must not carry plaintext ${f} \u2014 it's sealed in envelope.${f}` });
35105
- }
35106
- if (r.points !== void 0)
35107
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["points"], message: "E2EE request must not carry plaintext points" });
35108
- if (r.ask !== void 0)
35109
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["ask"], message: "E2EE request must not carry a plaintext ask \u2014 derive the shape agent-side and seal it" });
35110
- if (r.needs !== void 0)
35111
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["needs"], message: "E2EE request must not carry plaintext needs" });
35112
- return;
35113
- }
35114
32740
  if (r.ask !== void 0) {
35115
32741
  for (const f of ["context", "select", "points"]) {
35116
32742
  if (r[f] !== void 0)
@@ -35185,13 +32811,6 @@ var AwaitItemSchema2 = external_exports.discriminatedUnion("type", [
35185
32811
  workId: external_exports.string().uuid().optional(),
35186
32812
  decisionId: external_exports.string().uuid().optional(),
35187
32813
  answer: UserAnswerSchema2,
35188
- /** E2EE: present when the answer is sealed. The server relays the opaque answer
35189
- * envelope + the plaintext `ignored` status hint; the receiving agent OPENS it
35190
- * with its device key and re-derives the real UserAnswer, treating a mismatch
35191
- * against `ignored` as tampering. Absent = today's plaintext answer (in `answer`).
35192
- * On a sealed reply the plaintext `answer` is a placeholder (kind reflects only
35193
- * the `ignored` bit) — never the real content, which stays sealed. */
35194
- sealed: external_exports.lazy(() => SealedAnswerSchema2).optional(),
35195
32814
  /** WHAT THE AGENT CANNOT KNOW FROM THE FIELDS BESIDE IT (owner, 2026-09-04, issue
35196
32815
  * #1537). One line, built from the record: the ask and the caller's reply VERBATIM,
35197
32816
  * the notification they belong to, and the `contact` call that reaches the person
@@ -35227,7 +32846,7 @@ var AwaitItemSchema2 = external_exports.discriminatedUnion("type", [
35227
32846
  /** The awaited ask was REPLACED by a newer notification on its thread (e.g. a
35228
32847
  * post-feedback revision, #633) — the user will never answer this id. Stop
35229
32848
  * awaiting it; the live ask is the thread's newest turn (await that one, or
35230
- * re-orient via get_thread / check_replies). */
32849
+ * re-orient via check_replies). */
35231
32850
  external_exports.object({
35232
32851
  type: external_exports.literal("superseded"),
35233
32852
  parentId: external_exports.string(),
@@ -35341,10 +32960,6 @@ var InboxItemSchema2 = external_exports.object({
35341
32960
  options: external_exports.array(OptionSchema2).optional(),
35342
32961
  /** The ask's declared coverage points (#396), when the agent sent them. */
35343
32962
  points: external_exports.array(external_exports.string()).optional(),
35344
- /** The call's AGENDA (broker/agenda-design.md): the ordered turns it is made of, built at
35345
- * ring/enqueue time. Replaces the condensed line + index-aligned phrased points, which
35346
- * between them could not express a call as a sequence. `question: null` is a real turn —
35347
- * a status update stays a statement instead of being shaped into a yes/no. */
35348
32963
  /** Does this claim want an ANSWER, or is it telling you something? Written per row from
35349
32964
  * `requestAsks` — the agent's own declaration, not a guess. `false` is what earns a card
35350
32965
  * its acknowledge affordance: without it a status update offers a text box and a dismiss,
@@ -35365,7 +32980,26 @@ var InboxItemSchema2 = external_exports.object({
35365
32980
  * instant the agent picks it up (#997). Absent = pre-trigger row; fall back to
35366
32981
  * `createdAt`. */
35367
32982
  agentStateAt: external_exports.string().datetime().optional(),
35368
- agenda: external_exports.array(AgendaTurnSchema2).optional(),
32983
+ /** THE QUESTIONS A CALL CARRIES — the call screen's agenda spine (walk/design.md §11, owner
32984
+ * 2026-09-22). One per DecisionNeed on the Call, in the Call's order, answered or open (a
32985
+ * superseded or cancelled need is no longer a question anyone is asked). Present only on a
32986
+ * Call's cards, and every card of that Call carries the same list: the call screen reads it
32987
+ * once, off the one read it already makes (`GET /api/inbox/:callId`).
32988
+ *
32989
+ * It counts DECISIONS, not agenda turns: turns include context-only lines and are re-planned
32990
+ * every cycle, so a spine drawn from them would change length under the caller mid-call.
32991
+ *
32992
+ * `entryId` is the request Entry — the id the bot calls a CLAIM, and the one it names on the
32993
+ * `turn` topic (`asking`, `settled`), because the bot never sees a DecisionNeed id. `title` is
32994
+ * the card's own concise heading; `answer` the accepted answer in words, null while open. It
32995
+ * REPLACED `agenda` (turns), which nothing ever filled. */
32996
+ questions: external_exports.array(external_exports.object({
32997
+ id: external_exports.string(),
32998
+ entryId: external_exports.string(),
32999
+ title: external_exports.string(),
33000
+ state: external_exports.enum(["open", "answered"]),
33001
+ answer: external_exports.string().nullable()
33002
+ })).optional(),
35369
33003
  visuals: external_exports.array(VisualSchema2).optional(),
35370
33004
  /** The connected agent's name (the single pairing name — user-typed, or the
35371
33005
  * agent's suggestion, or a default silly name). */
@@ -35386,12 +33020,21 @@ var InboxItemSchema2 = external_exports.object({
35386
33020
  * client may still flag a stall by age. Drives the inbox error badge + Retry. */
35387
33021
  error: external_exports.string().optional(),
35388
33022
  clarifies: external_exports.string().optional(),
35389
- /** The ring ladder ran out while this was still pending — we tried to reach you and
35390
- * STOPPED trying (`arbitration/arbitrate.ts` `nextRing` → `stop`). Distinct from an
35391
- * agent with nothing to say, which the roster drew identically until now: "nothing to
35392
- * say" and "gave up saying it" are opposite situations wearing the same face
35393
- * (navigation-design.md, gap 1). False for anything that never rang. */
35394
- gaveUp: external_exports.boolean().default(false),
33023
+ /** THE RING, ON THE ITEM (walk/design.md §12 §17, #2251): the last ring on this card was
33024
+ * declined, and what the ladder will do next — read off the cron's own row, never computed
33025
+ * on the phone. Present only while a `declined` receipt stands on the card's last Call.
33026
+ * The ladder is ACCOUNT-WIDE (#2259): `anchorAt` and `step` are the account's position;
33027
+ * `nextRingAt` is this card's armed instant (`deliveries.next_ring_at`), null once the cron
33028
+ * has disarmed it — the curve's end, `inbox`/`dismiss`, or a setting that said no more rings.
33029
+ * It replaced `gaveUp` (deleted 2026-09-22): "the ladder spent" was a boolean the projection
33030
+ * never set, and it is `nextRingAt === null` here — the party's *Missed you* (`party/dress.ts`)
33031
+ * and the roster's `unreached` read `declinedAt`, and stand while it does. */
33032
+ ring: external_exports.object({
33033
+ declinedAt: external_exports.string().datetime(),
33034
+ anchorAt: external_exports.string().datetime(),
33035
+ nextRingAt: external_exports.string().datetime().nullable(),
33036
+ step: external_exports.number().int()
33037
+ }).optional(),
35395
33038
  /** Why this arrived the way it did, read back off the delivery receipt (`notify/why.ts`).
35396
33039
  * Absent for anything never delivered through a push, and for older rows written before
35397
33040
  * the reason was recorded. Deliberately a debug affordance, shown small (owner,
@@ -35413,21 +33056,6 @@ var InboxItemSchema2 = external_exports.object({
35413
33056
  blocking: external_exports.boolean().default(false),
35414
33057
  /** The user's locked-in answer; present only for replied items (GET /api/replied/:id). */
35415
33058
  answer: UserAnswerSchema2.optional(),
35416
- /** E2EE (text lane): the sealed content this item carries when the pairing is E2EE, in
35417
- * place of the plaintext `context`/`options`/`visuals` (which the operator would
35418
- * otherwise read). A per-field map of opaque Envelopes — the SAME shape as
35419
- * NotifyRequest.envelope. The native app decrypts it locally via openNotification;
35420
- * web / an un-enrolled device can't and renders a locked placeholder. Absent = today's
35421
- * plaintext item (context carries the cleartext), so plaintext items are unchanged. */
35422
- envelope: external_exports.object({
35423
- context: external_exports.lazy(() => EnvelopeSchema2).optional(),
35424
- options: external_exports.lazy(() => EnvelopeSchema2).optional(),
35425
- visuals: external_exports.lazy(() => EnvelopeSchema2).optional()
35426
- }).optional(),
35427
- /** E2EE: the agent's device X25519 public key to seal the user's answer BACK to (the
35428
- * sender the phone replies to). Sourced server-side from this item's pairing credential.
35429
- * Present only alongside `envelope`; the phone seals via sealAnswer(answer, this, id). */
35430
- agentX25519: external_exports.string().optional(),
35431
33059
  /** THE TARGET FACTS A CARD RENDERS (#1796 point 5, 2026-09-11): the Delivery it is a view of,
35432
33060
  * that Delivery's kind, the request Entry, the Goals it answers for, the exact DecisionNeed (none
35433
33061
  * for a request that asks nothing), whether its content is sealed, and that Goal's state. The
@@ -35471,6 +33099,8 @@ var MissedCallSchema2 = external_exports.enum([
35471
33099
  "inbox",
35472
33100
  "dismiss"
35473
33101
  ]);
33102
+ var clock2 = (h) => h === 0 ? "midnight" : h === 12 ? "noon" : h < 12 ? `${h} am` : `${h - 12} pm`;
33103
+ var QUIET2 = ` Nothing rings from ${clock2(NIGHT2.from)} to ${clock2(NIGHT2.to)} your time; the count waits for morning.`;
35474
33104
  var BrokerTuningSchema2 = external_exports.object({
35475
33105
  /** 'none' = skip the spoken ack after a mapped answer (power users find it slow). */
35476
33106
  ackVerbosity: external_exports.enum(["normal", "none"]).optional(),
@@ -35505,6 +33135,12 @@ var UserSettingsSchema2 = external_exports.object({
35505
33135
  * must not silently reset this privacy choice. Absent = leave unchanged on
35506
33136
  * write, 'hosted' on read (see store.ts). */
35507
33137
  voiceMode: external_exports.enum(["hosted", "on_device"]).optional(),
33138
+ /** Talk — after you answer, the next step is read aloud (walk/design.md §6). ALWAYS ON until
33139
+ * turned off (owner, 2026-09-18, #2249): a setting, not a per-walk toggle. Optional, NOT
33140
+ * defaulted, for the same reason `voiceMode` is: a stale client PATCHing the full settings
33141
+ * object must not silently turn it back on. Absent = leave unchanged on write, true on
33142
+ * read (see store.ts). */
33143
+ talk: external_exports.boolean().optional(),
35508
33144
  /** Per-user ring budget (#603): calls per rolling day before further calls
35509
33145
  * degrade to banner. Absent = the global default (25). A number, never a
35510
33146
  * bypass — every account keeps a ceiling. No UI; set per user for testing. */
@@ -35525,13 +33161,6 @@ var UserSettingsSchema2 = external_exports.object({
35525
33161
  * setting. Absent = a spoken time can't be landed, so the reminder rides the next
35526
33162
  * call — honest about what we know. */
35527
33163
  timezone: external_exports.string().min(1).max(64).optional(),
35528
- /** Account E2EE state (text lane): 'off' (default) = today's plaintext; 'on' =
35529
- * content is sealed end-to-end between the local agent and the phone. Like
35530
- * voiceMode, OPTIONAL and NOT defaulted so a stale client PATCHing the full
35531
- * settings object without it can't silently flip the account's E2EE state.
35532
- * Absent = leave unchanged on write, 'off' on read (see store.ts). The demo
35533
- * account is plaintext by construction and refuses any non-'off' value. */
35534
- e2eeMode: external_exports.enum(["off", "on"]).optional(),
35535
33164
  /** Rung-2 broker tuning (#381). Optional and NOT defaulted, same stale-client
35536
33165
  * clobber guard as voiceMode: absent = leave unchanged on write. */
35537
33166
  broker: BrokerTuningSchema2.optional()
@@ -35709,6 +33338,9 @@ var QueueItemSchema2 = external_exports.object({
35709
33338
  assignee: external_exports.string().nullable().default(null),
35710
33339
  /** What the agent last said it was doing; null if it has said nothing. */
35711
33340
  progress: external_exports.string().nullable().default(null),
33341
+ /** HOME'S LINE FOR THAT NOTE (owner, 2026-09-23): a few plain words one read wrote from `progress`,
33342
+ * served only while it was written for the current note. Null means show the Goal's name. */
33343
+ progressLine: external_exports.string().nullable().optional(),
35712
33344
  reviewPending: external_exports.boolean().default(false),
35713
33345
  dueAt: external_exports.string().nullable().default(null),
35714
33346
  /** The Goal this one was opened under; null at the root. */
@@ -35721,9 +33353,16 @@ var QueueItemSchema2 = external_exports.object({
35721
33353
  blocked: external_exports.boolean().default(false),
35722
33354
  /** Every decision need on it, open or settled — the page decides which to show. */
35723
33355
  questions: external_exports.array(QueueQuestionSchema2).default([]),
33356
+ /** The repository or project identifier this Goal belongs to (#2280), null if untracked. */
33357
+ repo: external_exports.string().nullable().optional(),
35724
33358
  createdAt: external_exports.string(),
35725
- updatedAt: external_exports.string().nullable().default(null)
33359
+ updatedAt: external_exports.string().nullable().default(null),
33360
+ /** When its owner last SAID something about it (`goals.last_progress_at`, written by every
33361
+ * `update_goal` that changes `progress`). `updatedAt` moves for reasons nobody chose — a
33362
+ * state recomputed, a review flag — so it cannot tell work in hand from work gone quiet. */
33363
+ lastProgressAt: external_exports.string().nullable().optional()
35726
33364
  });
33365
+ var COLD_AFTER_MS2 = 3 * 24 * 60 * 60 * 1e3;
35727
33366
  var NoteSourceSchema2 = external_exports.enum(["app", "call"]);
35728
33367
  var NoteStatusSchema2 = external_exports.enum(["open", "assigned", "in_progress", "done"]);
35729
33368
  var NoteRepeatSchema2 = external_exports.enum(["once", "until_done"]);
@@ -35832,54 +33471,12 @@ var DeliveryConfigSchema2 = external_exports.object({
35832
33471
  * carries credentials; only a `poll` registration can come back with null here. */
35833
33472
  realtime: external_exports.object({ url: external_exports.string(), anonKey: external_exports.string() }).nullable()
35834
33473
  });
35835
- var EnvelopeRecipientSchema2 = external_exports.object({
35836
- keyId: external_exports.string(),
35837
- epk: external_exports.string(),
35838
- wnonce: external_exports.string(),
35839
- wrap: external_exports.string()
35840
- });
35841
- var EnvelopeHeaderSchema2 = external_exports.object({
35842
- field: external_exports.enum(["context", "options", "visuals", "answer"]),
35843
- kind: external_exports.string(),
35844
- senderRole: external_exports.enum(["agent", "user"]),
35845
- recipientKeyIds: external_exports.array(external_exports.string()),
35846
- seq: external_exports.number().int().nonnegative()
35847
- });
35848
- var EnvelopeSchema2 = external_exports.object({
35849
- v: external_exports.literal(1),
35850
- alg: external_exports.literal("x25519-xsalsa20poly1305"),
35851
- msgId: external_exports.string(),
35852
- hdr: EnvelopeHeaderSchema2,
35853
- recipients: external_exports.array(EnvelopeRecipientSchema2).min(1),
35854
- nonce: external_exports.string(),
35855
- ct: external_exports.string()
35856
- });
35857
- var SealedAnswerSchema2 = external_exports.object({
35858
- ignored: external_exports.boolean(),
35859
- envelope: EnvelopeSchema2
35860
- });
35861
- var DeviceCredentialSchema2 = external_exports.object({
35862
- deviceId: external_exports.string(),
35863
- kind: external_exports.enum(["phone", "web", "agent"]),
35864
- x25519Pub: external_exports.string(),
35865
- ed25519Pub: external_exports.string(),
35866
- sig: external_exports.string()
35867
- });
35868
- var DeviceRosterSchema2 = external_exports.object({
35869
- uikPub: external_exports.string(),
35870
- devices: external_exports.array(DeviceCredentialSchema2)
35871
- });
35872
33474
  var WakeNudgeSchema2 = external_exports.object({
35873
33475
  kind: external_exports.enum(["reply", "request", "callback"]),
35874
33476
  notificationId: external_exports.string().optional(),
35875
33477
  parentId: external_exports.string()
35876
33478
  });
35877
33479
  var PairingStatusSchema2 = external_exports.enum(["pending", "approved", "denied", "expired"]);
35878
- var PairingRevealSchema2 = external_exports.object({
35879
- x25519: external_exports.string(),
35880
- ed25519: external_exports.string(),
35881
- nonce: external_exports.string()
35882
- });
35883
33480
  var DeviceCodeSchema2 = external_exports.object({
35884
33481
  device_code: external_exports.string(),
35885
33482
  user_code: external_exports.string(),
@@ -35899,19 +33496,7 @@ var DeviceInfoSchema2 = external_exports.object({
35899
33496
  * (seen live: PAIGY-5T, 2026-07-21). Remove once a newer binary is the floor. */
35900
33497
  agent: external_exports.string().optional(),
35901
33498
  device: external_exports.string().nullable(),
35902
- status: PairingStatusSchema2,
35903
- proto: external_exports.string().nullable().optional(),
35904
- agent_commitment: external_exports.string().nullable().optional(),
35905
- // Ca
35906
- agent_reveal: PairingRevealSchema2.nullable().optional(),
35907
- // present once the agent reveals
35908
- agent_credential: DeviceCredentialSchema2.nullable().optional(),
35909
- // the phone's UIK-signed cred over the agent's keys — the agent fetches it here to finalizeE2ee
35910
- // The phone's reveal + identity key, exposed here so a GATED agent (e2ee_mode='on', token
35911
- // withheld until e2ee=true) can compute the SAS WITHOUT a token. Public keys — same safety
35912
- // class as agent_reveal above. Present only once the phone reveals; null otherwise.
35913
- phone_reveal: PairingRevealSchema2.nullable().optional(),
35914
- uik_pub: external_exports.string().nullable().optional()
33499
+ status: PairingStatusSchema2
35915
33500
  });
35916
33501
  var DeviceTokenSchema2 = external_exports.object({
35917
33502
  access_token: external_exports.string(),
@@ -35930,8 +33515,6 @@ var DeviceTokenSchema2 = external_exports.object({
35930
33515
  * landed in the FIRST granted workspace and the agent rediscovered its own repo from
35931
33516
  * the thread each time (host.ts, live catch 2026-08-06 — prompt-papered until now). */
35932
33517
  workspace: external_exports.string().nullable().optional(),
35933
- phone_reveal: PairingRevealSchema2.nullable().optional(),
35934
- // present once the phone reveals
35935
33518
  uik_pub: external_exports.string().nullable().optional()
35936
33519
  });
35937
33520
  var SupportRequestSchema2 = external_exports.object({
@@ -35953,13 +33536,6 @@ var NotificationFeedbackKindSchema2 = external_exports.enum([
35953
33536
  "other"
35954
33537
  // anything else — the note carries it.
35955
33538
  ]);
35956
- var FeedbackResolutionSchema2 = external_exports.enum(["broker_fixed", "sent_to_agent"]);
35957
- var FeedbackOutcomeSchema2 = external_exports.object({
35958
- resolution: FeedbackResolutionSchema2,
35959
- transform: TransformSchema2,
35960
- message: external_exports.string(),
35961
- childIds: external_exports.array(external_exports.string()).optional()
35962
- });
35963
33539
 
35964
33540
  // src/paigy/activity.ts
35965
33541
  function shortenPaths(s) {
@@ -35985,14 +33561,32 @@ function sameTail(a, b) {
35985
33561
  init_dist();
35986
33562
 
35987
33563
  // src/paigy/conversation.ts
33564
+ import { randomUUID as randomUUID4 } from "crypto";
33565
+ var HARNESS_INSTRUCTION = "You are running as an unattended background harness agent connected to your user through Paigy. The user is NOT at the terminal and cannot see text printed here. To ask questions, request approvals, or make decisions, use Paigy tools or end your turn with a clear question for the bridge to relay. When complete, provide a concise summary of what was accomplished.";
35988
33566
  function endsWithQuestion(text) {
35989
33567
  if (!text) return false;
35990
- const tail = text.trim().split("\n").filter(Boolean).slice(-3).join(" ").toLowerCase();
35991
- if (!tail) return false;
35992
- if (tail.endsWith("?")) return true;
33568
+ const trimmed = text.trim();
33569
+ if (!trimmed) return false;
33570
+ if (trimmed.endsWith("?")) return true;
33571
+ const lines2 = trimmed.split("\n").map((l) => l.trim()).filter(Boolean);
33572
+ if (lines2.length === 0) return false;
33573
+ let lastNonListIdx = lines2.length - 1;
33574
+ while (lastNonListIdx >= 0) {
33575
+ const line = lines2[lastNonListIdx];
33576
+ if (line && /^[-*•\d.)]\s+/.test(line)) {
33577
+ lastNonListIdx--;
33578
+ } else {
33579
+ break;
33580
+ }
33581
+ }
33582
+ const promptLine = lastNonListIdx >= 0 ? lines2[lastNonListIdx] : lines2[lines2.length - 1];
33583
+ if (promptLine?.endsWith("?")) return true;
33584
+ const tail = lines2.slice(-3).join(" ").toLowerCase();
35993
33585
  return [
35994
33586
  /\b(let me know|which (one|would|do you)|do you want|should i|shall i)\b/,
35995
- /\b(want me to|prefer|your call|up to you|confirm whether)\b/
33587
+ /\b(want me to|prefer|your call|up to you|confirm whether)\b/,
33588
+ /\b(how would you like|how should we|what would you like|what should we)\b/,
33589
+ /\b(please choose|choose one|select one|how do you want)\b/
35996
33590
  ].some((re) => re.test(tail));
35997
33591
  }
35998
33592
  var POLL_MS = 5e3;
@@ -36010,17 +33604,34 @@ function unheard(brief, state) {
36010
33604
  }
36011
33605
  return words2;
36012
33606
  }
36013
- async function step(session, state, rail) {
33607
+ async function step(session, state, rail, opts) {
36014
33608
  if (!state.goal) {
36015
33609
  if (!state.resting) return;
36016
- const brief2 = await rail.claim();
36017
- if (!brief2.goalId || brief2.revision === void 0) return;
33610
+ let brief2 = await rail.claim();
33611
+ if (!brief2.goalId || brief2.revision === void 0) {
33612
+ if (opts?.initialPrompt?.trim()) {
33613
+ const prompt = opts.initialPrompt.trim();
33614
+ opts.initialPrompt = void 0;
33615
+ const admitted = await rail.create({ outcome: prompt, idempotencyKey: randomUUID4() });
33616
+ brief2 = await rail.claim();
33617
+ if (!brief2.goalId || brief2.revision === void 0) {
33618
+ state.goal = { id: admitted.goalId, revision: admitted.revision };
33619
+ if (checkCallOnDone(prompt)) state.callOnDone = true;
33620
+ send2(session, state, [HARNESS_INSTRUCTION, prompt].join("\n\n"));
33621
+ return;
33622
+ }
33623
+ } else {
33624
+ return;
33625
+ }
33626
+ }
36018
33627
  unheard(brief2, state);
36019
33628
  if (ended(brief2.state)) await rail.update(brief2.goalId, { revision: brief2.revision, changes: { reviewed: true }, reason: "Typed into the session." });
36020
33629
  else state.goal = { id: brief2.goalId, revision: brief2.revision };
36021
33630
  const outcome = brief2.outcome?.trim() ?? "";
36022
33631
  const said = (brief2.entries ?? []).map((e) => entryWords(e).trim()).filter((w) => w && w.toLowerCase() !== outcome.toLowerCase());
36023
- send2(session, state, [outcome, ...said].filter(Boolean).join("\n\n"));
33632
+ const fullText = [outcome, ...said].filter(Boolean).join("\n\n");
33633
+ if (checkCallOnDone(fullText)) state.callOnDone = true;
33634
+ send2(session, state, [HARNESS_INSTRUCTION, fullText].filter(Boolean).join("\n\n"));
36024
33635
  return;
36025
33636
  }
36026
33637
  const brief = await rail.read(state.goal.id);
@@ -36039,16 +33650,21 @@ async function step(session, state, rail) {
36039
33650
  }
36040
33651
  if (state.asks?.size || !state.resting) return;
36041
33652
  const words2 = unheard(brief, state);
36042
- if (words2.length) send2(session, state, words2.join("\n\n"));
33653
+ if (words2.length) {
33654
+ const text = words2.join("\n\n");
33655
+ if (checkCallOnDone(text)) state.callOnDone = true;
33656
+ send2(session, state, text);
33657
+ }
36043
33658
  }
36044
33659
  function send2(session, state, text) {
36045
33660
  state.resting = false;
36046
33661
  session.send(text);
36047
33662
  }
36048
33663
  async function pump(session, state, rail, opts) {
33664
+ const promptRef = opts.initialPrompt ? { initialPrompt: opts.initialPrompt } : void 0;
36049
33665
  for (; ; ) {
36050
33666
  try {
36051
- await step(session, state, rail);
33667
+ await step(session, state, rail, promptRef);
36052
33668
  } catch {
36053
33669
  }
36054
33670
  if (!await opts.onIdle()) return;
@@ -36056,25 +33672,6 @@ async function pump(session, state, rail, opts) {
36056
33672
  }
36057
33673
  }
36058
33674
 
36059
- // src/paigy/level.ts
36060
- var DESTRUCTIVE = [
36061
- /\brm\s+-[a-z]*[rf]/,
36062
- // rm -rf, rm -f
36063
- /\bgit\s+push\b.*(--force|-f\b)/,
36064
- /\bgit\s+reset\s+--hard/,
36065
- /\bgit\s+clean\s+-[a-z]*f/,
36066
- /\bdrop\s+(table|database|schema)\b/i,
36067
- /\btruncate\s+table\b/i,
36068
- /\bdd\s+if=/,
36069
- /\bmkfs\b/,
36070
- /\b(shutdown|reboot)\b/,
36071
- /:\s*>\s*\/dev\/sd/
36072
- // writing over a raw device
36073
- ];
36074
- function isDestructive(summary) {
36075
- return DESTRUCTIVE.some((re) => re.test(summary));
36076
- }
36077
-
36078
33675
  // src/paigy/bridge.ts
36079
33676
  function railFor(opts) {
36080
33677
  return {
@@ -36082,7 +33679,8 @@ function railFor(opts) {
36082
33679
  read: (goalId) => getGoal(goalId, opts),
36083
33680
  update: (goalId, input) => updateGoal(goalId, input, opts),
36084
33681
  // One read and back: the pump owns the waiting, so a Call must not hold a window here.
36085
- contact: (input) => contact(input, { ...opts, waits: false })
33682
+ contact: (input) => contact(input, { ...opts, waits: false }),
33683
+ create: (input) => createGoal(input, opts)
36086
33684
  };
36087
33685
  }
36088
33686
  function cancelAsks(state) {
@@ -36119,11 +33717,9 @@ async function ask(state, rail, input) {
36119
33717
  if (!state.goal) return null;
36120
33718
  try {
36121
33719
  const sent = await rail.contact({
36122
- goalIds: [state.goal.id],
36123
- ask: input.ask,
33720
+ asks: [{ ask: input.ask, parentId: state.goal.id, ...input.options ? { options: input.options } : {} }],
36124
33721
  waiting: "hard",
36125
- channel: input.call ? "call" : "notification",
36126
- ...input.options ? { options: input.options } : {}
33722
+ channel: input.call ? "call" : "notification"
36127
33723
  });
36128
33724
  const entryId = sent.requestEntryIds[0];
36129
33725
  if (!entryId) return null;
@@ -36133,37 +33729,87 @@ async function ask(state, rail, input) {
36133
33729
  return null;
36134
33730
  }
36135
33731
  }
33732
+ function checkCallOnDone(text) {
33733
+ if (!text) return false;
33734
+ return /\b(call|ring|phone)\b.*\b(done|finish(ed)?|complete(d)?)\b/i.test(text) || /\b(when|if|once)\b.*\b(done|finish(ed)?|complete(d)?)\b.*\b(call|ring|phone)\b/i.test(text) || /\bcall\s+(me|us)\b/i.test(text);
33735
+ }
33736
+ function parseQuestionOptions(text) {
33737
+ if (!text) return { question: "" };
33738
+ const trimmed = text.trim();
33739
+ const lines2 = trimmed.split("\n").map((l) => l.trim()).filter(Boolean);
33740
+ const optionLines = [];
33741
+ const questionLines = [];
33742
+ for (const line of lines2) {
33743
+ const bulletMatch = line.match(/^[-*•]\s+(.*)$/) ?? line.match(/^\d+[.)]\s+(.*)$/);
33744
+ if (bulletMatch) {
33745
+ optionLines.push(bulletMatch[1].trim());
33746
+ } else {
33747
+ questionLines.push(line);
33748
+ }
33749
+ }
33750
+ if (optionLines.length >= 2 && optionLines.length <= 6) {
33751
+ return {
33752
+ question: questionLines.join("\n\n").trim() || trimmed,
33753
+ options: optionLines.map((raw) => {
33754
+ const colonSplit = raw.match(/^([^:—–-]+)\s*[:—–-]\s*(.+)$/);
33755
+ const parenSplit = raw.match(/^([^(]+)\s*\(([^)]+)\)$/);
33756
+ if (colonSplit && colonSplit[1] && colonSplit[2]) {
33757
+ return { label: colonSplit[1].trim().slice(0, 100), hint: colonSplit[2].trim().slice(0, 250) };
33758
+ }
33759
+ if (parenSplit && parenSplit[1] && parenSplit[2]) {
33760
+ return { label: parenSplit[1].trim().slice(0, 100), hint: parenSplit[2].trim().slice(0, 250) };
33761
+ }
33762
+ return { label: raw.slice(0, 1e3) };
33763
+ })
33764
+ };
33765
+ }
33766
+ return { question: trimmed };
33767
+ }
36136
33768
  async function askPermission(event, state, rail) {
36137
33769
  return decisionFrom(await ask(state, rail, {
36138
33770
  ask: [`The agent is blocked waiting to run: ${event.summary}`, ...event.reason ? [event.reason] : []].join("\n\n"),
36139
- options: [{ label: ALLOW }, { label: "Deny" }],
36140
- call: isDestructive(event.summary)
33771
+ options: [
33772
+ { label: ALLOW, hint: "Permits the agent to run this command" },
33773
+ { label: "Deny", hint: "Blocks execution of this command" }
33774
+ ],
33775
+ call: true
36141
33776
  }));
36142
33777
  }
36143
- async function askQuestion(question, state, rail) {
36144
- return wordsOf(await ask(state, rail, { ask: question }));
33778
+ async function askQuestion(question, state, rail, opts) {
33779
+ return wordsOf(await ask(state, rail, {
33780
+ ask: question,
33781
+ call: opts?.call ?? true,
33782
+ options: opts?.options
33783
+ }));
36145
33784
  }
36146
- async function finish(result, state, rail) {
33785
+ async function finish(result, state, rail, opts) {
36147
33786
  const goal = state.goal;
36148
33787
  if (!goal) return;
36149
33788
  state.goal = void 0;
36150
33789
  const report = result?.trim() || "Done.";
33790
+ const channel = opts?.call || state.callOnDone ? "call" : "notification";
36151
33791
  try {
36152
- await rail.contact({ goalIds: [goal.id], ask: report, waiting: "none", channel: "notification" });
33792
+ await rail.contact({ asks: [{ ask: report, parentId: goal.id }], waiting: "none", channel });
36153
33793
  const { revision } = await rail.read(goal.id);
36154
33794
  await rail.update(goal.id, { revision: revision ?? goal.revision, changes: { state: "done", progress: report.slice(0, 1e4) }, reason: "The agent finished its turn without asking anything." });
36155
- } catch {
33795
+ } catch (error) {
33796
+ opts?.log?.(`\u26A0 finish contact failed: ${error.message}`);
36156
33797
  }
36157
33798
  }
36158
- async function afterTurn(event, state, rail) {
33799
+ async function afterTurn(event, state, rail, opts) {
36159
33800
  if (!event.failed && !endsWithQuestion(event.result)) {
36160
- await finish(event.result, state, rail);
33801
+ await finish(event.result, state, rail, opts);
36161
33802
  state.resting = true;
36162
33803
  return null;
36163
33804
  }
36164
- const reply = await askQuestion(event.failed ? `The agent stopped without finishing.
33805
+ const rawText = event.failed ? `The agent stopped without finishing.
36165
33806
 
36166
- ${event.result?.trim() || "No result reported."}` : event.result ?? "", state, rail);
33807
+ ${event.result?.trim() || "No result reported."}` : event.result ?? "";
33808
+ const parsed = parseQuestionOptions(rawText);
33809
+ const reply = await askQuestion(parsed.question, state, rail, {
33810
+ call: true,
33811
+ options: parsed.options
33812
+ });
36167
33813
  if (!reply) state.resting = true;
36168
33814
  return reply;
36169
33815
  }
@@ -36210,7 +33856,7 @@ function runHarness(opts) {
36210
33856
  return;
36211
33857
  }
36212
33858
  }
36213
- const reply = await afterTurn(event, state, rail);
33859
+ const reply = await afterTurn(event, state, rail, { log: opts.log });
36214
33860
  if (reply && session && running) {
36215
33861
  opts.log(`you: ${reply.split("\n")[0] ?? ""}`);
36216
33862
  session.send(reply);
@@ -36227,11 +33873,7 @@ function runHarness(opts) {
36227
33873
  ...opts.onExit ? { onExit: opts.onExit } : {},
36228
33874
  onEvent: (event) => void handle(event).catch((err) => opts.log(`\u26A0 ${err.message}`))
36229
33875
  });
36230
- if (opts.prompt) {
36231
- state.resting = false;
36232
- session.send(opts.prompt);
36233
- }
36234
- void pump(session, state, rail, { onIdle: () => running }).catch(
33876
+ void pump(session, state, rail, { onIdle: () => running, initialPrompt: opts.prompt }).catch(
36235
33877
  (e) => opts.log(`\u26A0 conversation loop stopped: ${e.message}`)
36236
33878
  );
36237
33879
  opts.log(`\u25B6 started ${opts.harness} in ${opts.cwd} (${opts.mode} mode)`);
@@ -36255,12 +33897,12 @@ function runHarness(opts) {
36255
33897
  // src/host.ts
36256
33898
  init_dist();
36257
33899
  init_catalog();
36258
- import { readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
33900
+ import { readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
36259
33901
  import { homedir as homedir6 } from "os";
36260
33902
  import { join as join6 } from "path";
36261
33903
 
36262
33904
  // src/workspaces.ts
36263
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
33905
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
36264
33906
  import { dirname as dirname2, join as join3, resolve as resolve2 } from "path";
36265
33907
  import { homedir as homedir4 } from "os";
36266
33908
  function workspacesFile() {
@@ -36268,7 +33910,7 @@ function workspacesFile() {
36268
33910
  }
36269
33911
  function listWorkspaces(deps) {
36270
33912
  try {
36271
- const parsed = JSON.parse(readFileSync2(deps.file, "utf8"));
33913
+ const parsed = JSON.parse(readFileSync3(deps.file, "utf8"));
36272
33914
  return Array.isArray(parsed) ? parsed.filter((w) => typeof w === "string") : [];
36273
33915
  } catch {
36274
33916
  return [];
@@ -36444,9 +34086,9 @@ async function slotHasWaitingWork(token, session) {
36444
34086
  }
36445
34087
  var PRESENCE_FRESH_MS = 3 * 6e4;
36446
34088
  function wakeAction(live, now, serverSeenAt) {
36447
- if (live) return "skip";
36448
- if (serverSeenAt !== void 0 && now - serverSeenAt < PRESENCE_FRESH_MS) return "skip";
36449
- return "spawn";
34089
+ if (live) return { action: "skip", why: "run" };
34090
+ if (serverSeenAt !== void 0 && now - serverSeenAt < PRESENCE_FRESH_MS) return { action: "skip", why: "presence" };
34091
+ return { action: "spawn", why: "nobody" };
36450
34092
  }
36451
34093
  function startHost(opts) {
36452
34094
  const runs = /* @__PURE__ */ new Map();
@@ -36497,6 +34139,7 @@ function startHost(opts) {
36497
34139
  mode: "bypass",
36498
34140
  prompt: "",
36499
34141
  token: spec.token,
34142
+ resume: spec.sessionId,
36500
34143
  onExit: () => {
36501
34144
  runs.delete(key);
36502
34145
  opts.log(`\u2716 ${label} ended`);
@@ -36535,7 +34178,11 @@ function startHost(opts) {
36535
34178
  const live = runs.get(key);
36536
34179
  const tokenId = slotIdentity(slot).tokenId;
36537
34180
  const seenByServer = tokenId ? presence.get(tokenId) : void 0;
36538
- if (wakeAction(!!live, Date.now(), seenByServer) === "skip") return;
34181
+ const decided = wakeAction(!!live, Date.now(), seenByServer);
34182
+ if (decided.action === "skip") {
34183
+ opts.log(decided.why === "run" ? `\u25CC ${slotName(slot) ?? slot} is running here \u2014 its pump types the work in; not spawning` : `\u25CC ${slotName(slot) ?? slot} is working somewhere this host cannot see (heartbeat) \u2014 not spawning`);
34184
+ return;
34185
+ }
36539
34186
  const token = readToken(slot);
36540
34187
  if (!token) return;
36541
34188
  const owner = ownerSession(slot);
@@ -36771,7 +34418,7 @@ function printConnectLines(link, userCode, enter) {
36771
34418
  }
36772
34419
  async function pairThisMachine() {
36773
34420
  const host = hostname().replace(/\.local$/, "");
36774
- const code = await requestCode(host, void 0, host);
34421
+ const code = await requestCode(host, host);
36775
34422
  const link = code.verification_uri_complete;
36776
34423
  console.log(await import_qrcode.default.toString(link, { type: "terminal", small: true }));
36777
34424
  printConnectLines(link, code.user_code, !!process.stdin.isTTY);
@@ -36796,7 +34443,7 @@ async function pairThisMachine() {
36796
34443
  function forwardCodexThreadId() {
36797
34444
  const cfg = join7(process.env.CODEX_HOME || join7(homedir8(), ".codex"), "config.toml");
36798
34445
  if (!existsSync5(cfg)) return;
36799
- const text = readFileSync4(cfg, "utf8");
34446
+ const text = readFileSync5(cfg, "utf8");
36800
34447
  const head = "[mcp_servers.paigy]\n";
36801
34448
  const at = text.indexOf(head);
36802
34449
  if (at < 0) return;
@@ -36939,7 +34586,7 @@ async function main() {
36939
34586
  try {
36940
34587
  const settings = join7(homedir8(), ".claude", "settings.json");
36941
34588
  if (which("claude") && existsSync5(settings)) {
36942
- const cfg = JSON.parse(readFileSync4(settings, "utf8"));
34589
+ const cfg = JSON.parse(readFileSync5(settings, "utf8"));
36943
34590
  if (!cfg["statusLine"]) {
36944
34591
  cfg["statusLine"] = { type: "command", command: "npx -y -p @paigy/mcp@latest paigy-statusline" };
36945
34592
  writeFileSync4(settings, JSON.stringify(cfg, null, 2));
@@ -37013,7 +34660,7 @@ async function main() {
37013
34660
  process.exit(1);
37014
34661
  }
37015
34662
  if (parsed.handoff) {
37016
- const slot = AGENT_NAME;
34663
+ const slot = agentName();
37017
34664
  if (!readToken(slot)) {
37018
34665
  console.error(`This terminal holds no Paigy identity (slot "${slot}" is empty) \u2014 pair or hatch first.`);
37019
34666
  process.exit(1);