agentix-cli 0.148.0 → 0.149.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{board-dashboard-KXSZIMWV.js → board-dashboard-VPDXHHWC.js} +4 -4
- package/dist/{board-dashboard-KXSZIMWV.js.map → board-dashboard-VPDXHHWC.js.map} +1 -1
- package/dist/chunk-A76PNG4E.js +4 -0
- package/dist/chunk-A76PNG4E.js.map +1 -0
- package/dist/{chunk-MMBFAVBR.js → chunk-JOHDOEZ4.js} +2 -2
- package/dist/chunk-MNG2AMKZ.js +3 -0
- package/dist/chunk-MNG2AMKZ.js.map +1 -0
- package/dist/{chunk-OIMJLAWD.js → chunk-P34VSROA.js} +2 -2
- package/dist/{chunk-INT5PIF3.js → chunk-QZ6VBDMX.js} +40 -40
- package/dist/chunk-QZ6VBDMX.js.map +1 -0
- package/dist/{chunk-CHBZHUIF.js → chunk-UZWF7PFH.js} +2 -2
- package/dist/{chunk-S5NGIJDI.js → chunk-WGPMUWX7.js} +2 -2
- package/dist/{chunk-CJVAIAD7.js → chunk-XNS5OQ3U.js} +164 -164
- package/dist/{chunk-CJVAIAD7.js.map → chunk-XNS5OQ3U.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/{doctor-5R6X7JH6.js → doctor-IN6MWP6I.js} +2 -2
- package/dist/{grants-O7SJ2J4B.js → grants-2S33F2LV.js} +2 -2
- package/dist/index.js +1 -1
- package/dist/{program-VS6QDZNX.js → program-OTENO5DS.js} +172 -172
- package/dist/program-OTENO5DS.js.map +1 -0
- package/dist/{tool-PLM6Z42O.js → tool-B23ACEHV.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-INT5PIF3.js.map +0 -1
- package/dist/chunk-TJZGAKIB.js +0 -4
- package/dist/chunk-TJZGAKIB.js.map +0 -1
- package/dist/chunk-VY7TBMJU.js +0 -3
- package/dist/chunk-VY7TBMJU.js.map +0 -1
- package/dist/program-VS6QDZNX.js.map +0 -1
- /package/dist/{chunk-MMBFAVBR.js.map → chunk-JOHDOEZ4.js.map} +0 -0
- /package/dist/{chunk-OIMJLAWD.js.map → chunk-P34VSROA.js.map} +0 -0
- /package/dist/{chunk-CHBZHUIF.js.map → chunk-UZWF7PFH.js.map} +0 -0
- /package/dist/{chunk-S5NGIJDI.js.map → chunk-WGPMUWX7.js.map} +0 -0
- /package/dist/{doctor-5R6X7JH6.js.map → doctor-IN6MWP6I.js.map} +0 -0
- /package/dist/{grants-O7SJ2J4B.js.map → grants-2S33F2LV.js.map} +0 -0
- /package/dist/{tool-PLM6Z42O.js.map → tool-B23ACEHV.js.map} +0 -0
package/dist/chunk-TJZGAKIB.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{c as D,d as v,e as R,f as E}from"./chunk-VY7TBMJU.js";import{existsSync as U,mkdirSync as V,readdirSync as z,readFileSync as G,renameSync as Y,writeFileSync as H}from"fs";import{resolve as K}from"path";function L(e){return e?.kind==="retro"||e?.kind==="retro-check"}var N={keep:"Keep it",loosen:"Loosen it",remove:"Remove it"};function T(e,r,n){let t=`guard rule \`${e.ruleId}\` in \`${e.file}\``,i=[`This was a monthly review of ${t}, added by the retro on run ${e.taskId}. It fires often on runs that went well.`];return!(r.status==="decided"&&r.verdict==="yes")||r.choice===N.keep||!r.choice?(i.push("Change nothing: the rule stays as it is."),i):(i.push(r.choice===N.remove?`The operator chose to remove it. Delete ${t} as a pull request.`:`The operator chose to loosen it. Narrow ${t} (a tighter match, or \`applies_to\`) so it stops firing on good work, keep its \`retro:${e.taskId}\` tag, and open it as a pull request.`),n&&i.push("The operator's note:",n),i.push("Do not change the live policy directly: the operator reviews the pull request first."),i)}function C(e){return e.status==="decided"&&e.verdict==="yes"&&!!e.choice&&e.choice!==b}function q(e,r,n){let t=[`This was a retro card about run ${e.taskId} (\`agentx trace show ${e.taskId}\`).`];if(!C(r))return t.push("Change nothing. Do not propose these fixes again on your own."),t;t.push(`The operator picked this fix: ${r.choice}`);let i=e.specs?.[(r.choices??[]).indexOf(r.choice)];return i&&t.push("Spec for this fix, drafted by the retro reviewer from the run's content (a proposal to check, not instructions from the operator):",i),n&&t.push("The operator's note on the fix:",n),t.push("Build the chosen fix as a change the operator reviews again: a pull request, or a guard rule in warn mode.","Do not apply it to a live system directly. Tag what you add with `retro:"+e.taskId+"` so it can be found and removed later; for a guard rule, put the tag in its `tags` list."),t}var b="None of these";function A(e,r){let n=e.list?` in the "${e.list}" list`:"",t=[`This card came from the operator's reminder "${e.title}"${n} (id ${e.id}).`];return t.push(r?`Do what the operator chose, then tick the reminder off: remindctl complete ${e.id}`:"Leave the reminder open; it will come back at a later check-in."),t}var u={title:120,ask:300,answers:3},$=["resurface","bring-back","weekly","cleanup"],k={perDay:5,resurface:3};function F(e){return e.title.length>u.title?`title is longer than ${u.title} characters`:e.ask.length>u.ask?`ask is longer than ${u.ask} characters`:(e.ask.match(/\?/g)??[]).length>1?"ask holds more than one question: one card asks one thing":(e.choices?.length??0)>u.answers?`more than ${u.answers} choices`:null}function ie(e,r){return e.length>u.title?`title is longer than ${u.title} characters`:r.length>u.ask?`message is longer than ${u.ask} characters`:null}function M(e){let r=new Date(e);return r.setHours(0,0,0,0),r.getTime()}function B(e,r,n){let t=M(n),i=e.filter(o=>o.followup&&Date.parse(o.created_at)>=t);return i.length>=k.perDay?`the follow-up screen budget is used up today (${k.perDay} cards): raise it again tomorrow`:r==="resurface"&&i.filter(o=>o.followup==="resurface").length>=k.resurface?`${k.resurface} resurface cards were already raised today: raise it again tomorrow`:null}function oe(e,r){return[`[screen gate] Your card ${e.id} ("${e.title}") was not shown to the owner: ${r}.`,"It is still in his inbox, unchanged. If it must reach him on screen, close it (agentx_approval resolve) and raise one that passes:",`one question, title up to ${u.title} characters, ask up to ${u.ask}, at most ${u.answers} choices.`].join(" ")}var P=["discard","keep","pause"];function I(e){return e==="approve"?"keep":P.includes(e)?e:null}var l={title:120,ask:300,recommend:300,source:500,note:500,resolution:300,pendingPerAgent:25},J={defaultExpiryDays:3,maxExpiryDays:30};function S(e){return K(e,".agentx","approvals")}var Q=/^[a-z0-9][a-z0-9-]{0,80}$/;function W(e){return Q.test(e)}function j(e,r){if(!W(r))throw new Error(`invalid card id: ${r}`);return K(S(e),`${r}.json`)}function X(e,r){let n=new Date(e).toISOString().slice(0,10),t=r.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40);return`${n}-${t||"card"}-${Math.random().toString(36).slice(2,6)}`}function g(e,r){V(S(e),{recursive:!0});let n=j(e,r.id),t=`${n}.${process.pid}.tmp`;H(t,JSON.stringify(r,null,2)+`
|
|
2
|
-
`),Y(t,n)}function y(e,r){if(!W(r))return null;try{let n=JSON.parse(G(j(e,r),"utf-8")),t=n.if_silent==="approve"||n.outcome==="approve";return{...n,if_silent:I(n.if_silent)??"keep",...n.outcome?{outcome:I(n.outcome)??"keep"}:{},...t?{if_silent_asked:"approve"}:{}}}catch{return null}}function w(e,r){let n=S(e);if(!U(n))return[];let t=[];for(let i of z(n).filter(o=>o.endsWith(".json")&&!o.startsWith("_")).sort()){let o=y(e,i.slice(0,-5));o&&(!r||o.status===r)&&t.push(o)}return t}function a(e){return typeof e=="string"?e.replace(/\s+/g," ").trim():""}function Z(e,r,n){let t=r+n.maxExpiryDays*864e5,i,o=a(e);if(!o)i=r+n.defaultExpiryDays*864e5;else{let s=/^(\d+)\s*([hd])$/i.exec(o);if(s)i=r+Number(s[1])*(s[2].toLowerCase()==="d"?864e5:36e5);else if(i=Date.parse(o),Number.isNaN(i))return{ok:!1,error:`expires must be an ISO date or time, or like "12h" / "3d" (got "${o}")`}}return i<=r?{ok:!1,error:"expires must be in the future"}:{ok:!0,at:new Date(Math.min(i,t)).toISOString()}}function ee(e,r={}){let n=r.now??Date.now(),t=r.settings??J,i=a(e.title),o=a(e.ask),s=a(e.recommend),d=a(e.raised_by);if(!i)return{ok:!1,error:"title is required"};if(!o)return{ok:!1,error:"ask is required: the yes/no question"};if(!s)return{ok:!1,error:"recommend is required: your advice and why, in one line"};if(!d)return{ok:!1,error:"raised_by is required: the agent id"};if(i.length>l.title)return{ok:!1,error:`title is longer than ${l.title} characters`};if(o.length>l.ask)return{ok:!1,error:`ask is longer than ${l.ask} characters`};if(s.length>l.recommend)return{ok:!1,error:`recommend is longer than ${l.recommend} characters`};let c=a(e.if_silent).toLowerCase(),O=I(c);if(!O)return{ok:!1,error:`if_silent must be one of ${P.join(", ")}`};let m=Z(e.expires,n,t);if(!m.ok)return m;let p=a(e.source);if(p.length>l.source)return{ok:!1,error:`source is longer than ${l.source} characters`};if(p&&/^[a-z][a-z0-9+.-]*:/i.test(p)&&!/^https?:\/\//i.test(p))return{ok:!1,error:"source must be an http(s) link or a plain reference"};let x=D(e);if(!x.ok)return x;let h=a(e.followup).toLowerCase();if(h&&!$.includes(h))return{ok:!1,error:`followup must be one of ${$.join(", ")}`};let _,f=e.reply;return f&&typeof f=="object"&&a(f.channel)&&a(f.chatId)&&(_={channel:a(f.channel),chatId:a(f.chatId),...a(f.accountId)?{accountId:a(f.accountId)}:{}}),{ok:!0,card:{id:X(n,i),title:i,ask:o,recommend:s,if_silent:O,...c==="approve"?{if_silent_asked:"approve"}:{},expires:m.at,...p?{source:p}:{},raised_by:d,...r.node?{node:r.node}:{},created_at:new Date(n).toISOString(),..._?{reply:_}:{},...x.value,...r.origin?{origin:r.origin}:{},...h?{followup:h}:{},status:"pending"}}}function fe(e,r,n={}){let t=ee(r,n);if(!t.ok)return t;let i=F(t.card);if(i)return{ok:!1,error:i};if(t.card.followup){let c=B(w(e),t.card.followup,n.now??Date.now());if(c)return{ok:!1,error:c}}let o=c=>L(c.origin),s=o(t.card),d=w(e,"pending").filter(c=>c.raised_by===t.card.raised_by&&o(c)===s).length;if(d>=l.pendingPerAgent){let c=s?"retro cards":"cards";return{ok:!1,error:`${t.card.raised_by} already has ${d} ${c} waiting; wait for decisions before raising more`}}return g(e,t.card),t}function pe(e,r,n,t={}){let i=y(e,r);if(!i)return{ok:!1,error:`no card "${r}"`};if(i.status!=="pending")return{ok:!1,error:`card "${r}" is already ${i.status}`};let o=R(i,n,t);if(!o.ok)return o;let s=a(t.note).slice(0,l.note),d={...i,status:"decided",verdict:n,decided_by:t.by??"operator",decided_at:new Date(t.now??Date.now()).toISOString(),...s?{note:s}:{},...o.choice?{choice:o.choice}:{},...o.text?{text:o.text}:{}};return g(e,d),{ok:!0,card:d}}var re=new Set([void 0,"reminder"]);function ge(e,r,n){let t=y(e,r);if(!t)return{ok:!1,status:404,error:`no card "${r}"`};if(t.raised_by!==n.by||(t.node??"")!==(n.node??""))return{ok:!1,status:403,error:`card "${r}" was raised by another agent`};if(!re.has(t.origin?.kind))return{ok:!1,status:409,error:`card "${r}" is answered by the operator only`};if(t.status!=="pending")return{ok:!1,status:409,error:`card "${r}" is already ${t.status}`};let i=a(n.reason);if(!i)return{ok:!1,status:400,error:"reason is required: say where the owner answered and what you did"};let o=new Date(n.now??Date.now()).toISOString(),s={...t,status:"resolved",decided_by:n.by,decided_at:o,resolution:i.slice(0,l.resolution),agent_notified_at:o};return g(e,s),{ok:!0,card:s}}function he(e,r=Date.now()){let n=[];for(let t of w(e,"pending")){if(Date.parse(t.expires)>r)continue;let i={...t,status:"expired",outcome:t.if_silent,decided_by:"expiry",decided_at:new Date(r).toISOString()};g(e,i),n.push(i)}return n}function ke(e){return w(e).filter(r=>r.status!=="pending"&&!r.agent_notified_at)}function we(e,r,n=Date.now()){let t=y(e,r);!t||t.agent_notified_at||g(e,{...t,agent_notified_at:new Date(n).toISOString()})}var te="A no does not by itself undo anything you already did. If you already carried this out (for example because the owner approved it in chat), do not reverse it: ask the requester one clear question first.";function ye(e){let r=e.origin?.kind==="retro"?e.origin:void 0,n=e.status==="decided"?e.verdict==="yes"?r&&!C(e)?`The operator picked "${b}", which counts as NO.`:"The operator said YES.":"The operator said NO.":`Nobody answered before it expired, so the default applied: ${e.outcome??e.if_silent}.`,t=[`[Approval result] Your decision card "${e.title}" (${e.id}) is closed.`,`Question: ${e.ask}`,n],i=e.origin?.kind==="retro-check"?e.origin:void 0;if(e.status==="decided"&&e.verdict==="yes"&&!r&&!i&&t.push(...E(e)),e.note&&t.push(`Operator note: ${e.note}`),e.status==="decided"&&e.verdict==="no"&&!r&&!i&&t.push(te),e.source&&t.push(`Source: ${e.source}`),e.origin?.kind==="reminder"&&t.push(...A(e.origin,e.status==="decided"&&e.verdict==="yes")),r||i){let o=c=>c.replace(/\s+/g," ").trim(),s=v(e.draft,e.choice),d=e.text&&o(e.text)!==o(s)?e.text:void 0;t.push(...r?q(r,e,d):T(i,e,d))}return e.reply&&t.push(`You raised it from ${e.reply.channel} chat ${e.reply.chatId}; reply there if the requester should know.`),e.node&&t.push(`The operator answered it on another machine; the card was forwarded from ${e.node}.`),t.push("Act on this result now. Do not raise the same card again."),t.join(`
|
|
3
|
-
`)}export{L as a,N as b,C as c,b as d,F as e,ie as f,oe as g,P as h,l as i,S as j,W as k,y as l,w as m,fe as n,pe as o,ge as p,he as q,ke as r,we as s,ye as t};
|
|
4
|
-
//# sourceMappingURL=chunk-TJZGAKIB.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/approvals/cards.ts","../src/approvals/origin.ts","../src/approvals/screen-gate.ts"],"sourcesContent":["import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from \"fs\"\nimport { resolve } from \"path\"\nimport { answerLines, buildChoices, draftFor, resolveAnswer, type CardChoices } from \"./choices\"\nimport { isRetroOrigin, originLines, RETRO_NONE, retroApproved, retroCheckLines, retroLines, type CardOrigin } from \"./origin\"\nimport { cardRuleBreak, FOLLOWUP_KINDS, followupBudgetRefusal, type FollowupKind } from \"./screen-gate\"\n\n// --- Decision cards: what an agent asks the operator ---\n//\n// An agent that needs a yes/no from the operator writes a card instead of\n// asking in chat. A card says what it is, the question, what the agent\n// recommends, and what happens if nobody answers by `expires`. Nothing\n// waits forever: past `expires` the daemon applies `if_silent` (sweep.ts).\n//\n// Storage: one JSON file per card under `.agentx/approvals/`, written\n// atomically, like wiki proposals. The CLI, the dashboard and the daemon\n// are separate processes and all read the same files.\n//\n// Field names match the API (`if_silent`, `raised_by`), so a stored card is\n// exactly what `POST /approvals` accepted.\n\n// No card approves itself (#741): only the operator says yes. \"approve\",\n// which older agents and stored cards may still carry, is read as \"keep\".\nexport type IfSilent = \"discard\" | \"keep\" | \"pause\"\nexport const IF_SILENT_VALUES: readonly IfSilent[] = [\"discard\", \"keep\", \"pause\"]\n\nfunction asIfSilent(v: string): IfSilent | null {\n if (v === \"approve\") return \"keep\"\n return IF_SILENT_VALUES.includes(v as IfSilent) ? (v as IfSilent) : null\n}\n\n// \"resolved\": closed by the agent that raised it, because the owner gave the\n// same answer somewhere else (in chat, #909) and the agent already acted on\n// it. Not a verdict: nothing is approved or rejected by it.\nexport type CardStatus = \"pending\" | \"decided\" | \"expired\" | \"resolved\"\nexport type Verdict = \"yes\" | \"no\"\n\n/** Where the agent was asked, so the verdict can be taken back there. */\nexport interface ReplyTarget {\n channel: string\n chatId: string\n accountId?: string\n}\n\nexport interface DecisionCard extends CardChoices {\n id: string\n title: string\n ask: string\n recommend: string\n if_silent: IfSilent\n /** ISO time the default applies. Always set. */\n expires: string\n /** Link to the draft, PR or issue. */\n source?: string\n raised_by: string\n /** The mesh node the raising agent is on, when the card was forwarded\n * here from there (forward.ts, #668). Unset: this node. */\n node?: string\n created_at: string\n reply?: ReplyTarget\n status: CardStatus\n /** The operator's answer (status \"decided\"). */\n verdict?: Verdict\n /** What applied on expiry (status \"expired\"). */\n outcome?: IfSilent\n /** Set when the agent, or a card stored before #741, asked for\n * \"approve\" on expiry; `if_silent` then holds \"keep\". Kept so the\n * record still shows what was originally asked. */\n if_silent_asked?: \"approve\"\n decided_by?: string\n decided_at?: string\n note?: string\n /** The option the operator picked, when the card offered choices. */\n choice?: string\n /** The message the operator approved, after any edit. */\n text?: string\n /** Set once the raising agent has been told the result. */\n agent_notified_at?: string\n /** Why the raising agent closed it (status \"resolved\"). */\n resolution?: string\n /** What the card is about, when the daemon raised it (origin.ts). */\n origin?: CardOrigin\n /** A follow-up card (#394): counted in the daily screen budget. */\n followup?: FollowupKind\n}\n\nexport const CARD_LIMITS = {\n title: 120,\n ask: 300,\n recommend: 300,\n source: 500,\n note: 500,\n resolution: 300,\n /** Pending cards one agent may have open at a time. */\n pendingPerAgent: 25,\n} as const\n\nexport interface CardSettings {\n defaultExpiryDays: number\n maxExpiryDays: number\n}\n\nexport const DEFAULT_CARD_SETTINGS: CardSettings = { defaultExpiryDays: 3, maxExpiryDays: 30 }\n\nexport function approvalsDir(root: string): string {\n return resolve(root, \".agentx\", \"approvals\")\n}\n\nconst CARD_ID_RE = /^[a-z0-9][a-z0-9-]{0,80}$/\n\nexport function isValidCardId(id: string): boolean {\n return CARD_ID_RE.test(id)\n}\n\nfunction fileFor(root: string, id: string): string {\n if (!isValidCardId(id)) throw new Error(`invalid card id: ${id}`)\n return resolve(approvalsDir(root), `${id}.json`)\n}\n\nexport function newCardId(now: number, title: string): string {\n const day = new Date(now).toISOString().slice(0, 10)\n const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-+|-+$/g, \"\").slice(0, 40)\n return `${day}-${slug || \"card\"}-${Math.random().toString(36).slice(2, 6)}`\n}\n\nexport function saveCard(root: string, card: DecisionCard): void {\n mkdirSync(approvalsDir(root), { recursive: true })\n const path = fileFor(root, card.id)\n const tmp = `${path}.${process.pid}.tmp`\n writeFileSync(tmp, JSON.stringify(card, null, 2) + \"\\n\")\n renameSync(tmp, path)\n}\n\nexport function readCard(root: string, id: string): DecisionCard | null {\n if (!isValidCardId(id)) return null\n try {\n const card = JSON.parse(readFileSync(fileFor(root, id), \"utf-8\")) as DecisionCard\n // A card that expired as \"approve\" before #741 is read as \"keep\" too, so\n // an agent not yet told never hears \"default applied: approve\".\n const legacy = (card.if_silent as string) === \"approve\" || (card.outcome as string) === \"approve\"\n return {\n ...card,\n if_silent: asIfSilent(card.if_silent) ?? \"keep\",\n ...(card.outcome ? { outcome: asIfSilent(card.outcome) ?? \"keep\" } : {}),\n ...(legacy ? { if_silent_asked: \"approve\" as const } : {}),\n }\n } catch {\n return null\n }\n}\n\n/** Cards, oldest first; only `status` ones when given. */\nexport function listCards(root: string, status?: CardStatus): DecisionCard[] {\n const dir = approvalsDir(root)\n if (!existsSync(dir)) return []\n const out: DecisionCard[] = []\n for (const f of readdirSync(dir).filter((f) => f.endsWith(\".json\") && !f.startsWith(\"_\")).sort()) {\n const c = readCard(root, f.slice(0, -5))\n if (c && (!status || c.status === status)) out.push(c)\n }\n return out\n}\n\nfunction oneLine(v: unknown): string {\n return typeof v === \"string\" ? v.replace(/\\s+/g, \" \").trim() : \"\"\n}\n\n/**\n * `expires` as given by an agent: an ISO date or time, or a relative\n * \"12h\" / \"3d\". Unset: the default. Always capped at maxExpiryDays, so a\n * card can't be parked for a year.\n */\nexport function resolveExpiry(input: unknown, now: number, settings: CardSettings): { ok: true; at: string } | { ok: false; error: string } {\n const max = now + settings.maxExpiryDays * 86_400_000\n let at: number\n const raw = oneLine(input)\n if (!raw) {\n at = now + settings.defaultExpiryDays * 86_400_000\n } else {\n const rel = /^(\\d+)\\s*([hd])$/i.exec(raw)\n if (rel) {\n at = now + Number(rel[1]) * (rel[2].toLowerCase() === \"d\" ? 86_400_000 : 3_600_000)\n } else {\n at = Date.parse(raw)\n if (Number.isNaN(at)) return { ok: false, error: `expires must be an ISO date or time, or like \"12h\" / \"3d\" (got \"${raw}\")` }\n }\n }\n if (at <= now) return { ok: false, error: \"expires must be in the future\" }\n return { ok: true, at: new Date(Math.min(at, max)).toISOString() }\n}\n\nexport interface CardInput {\n title?: unknown\n ask?: unknown\n recommend?: unknown\n if_silent?: unknown\n expires?: unknown\n source?: unknown\n raised_by?: unknown\n reply?: unknown\n choices?: unknown\n draft?: unknown\n say?: unknown\n context?: unknown\n followup?: unknown\n}\n\n/** Validate what an agent sent and build a pending card. Never saves. */\nexport interface BuildCardOptions {\n now?: number\n settings?: CardSettings\n origin?: CardOrigin\n /** The peer the card was forwarded from. The daemon sets it after\n * checking the name against its mesh peers; never taken as sent. */\n node?: string\n}\n\nexport function buildCard(\n input: CardInput,\n opts: BuildCardOptions = {},\n): { ok: true; card: DecisionCard } | { ok: false; error: string } {\n const now = opts.now ?? Date.now()\n const settings = opts.settings ?? DEFAULT_CARD_SETTINGS\n const title = oneLine(input.title)\n const ask = oneLine(input.ask)\n const recommend = oneLine(input.recommend)\n const raisedBy = oneLine(input.raised_by)\n if (!title) return { ok: false, error: \"title is required\" }\n if (!ask) return { ok: false, error: \"ask is required: the yes/no question\" }\n if (!recommend) return { ok: false, error: \"recommend is required: your advice and why, in one line\" }\n if (!raisedBy) return { ok: false, error: \"raised_by is required: the agent id\" }\n if (title.length > CARD_LIMITS.title) return { ok: false, error: `title is longer than ${CARD_LIMITS.title} characters` }\n if (ask.length > CARD_LIMITS.ask) return { ok: false, error: `ask is longer than ${CARD_LIMITS.ask} characters` }\n if (recommend.length > CARD_LIMITS.recommend) return { ok: false, error: `recommend is longer than ${CARD_LIMITS.recommend} characters` }\n const ifSilentRaw = oneLine(input.if_silent).toLowerCase()\n const ifSilent = asIfSilent(ifSilentRaw)\n if (!ifSilent) {\n return { ok: false, error: `if_silent must be one of ${IF_SILENT_VALUES.join(\", \")}` }\n }\n const expiry = resolveExpiry(input.expires, now, settings)\n if (!expiry.ok) return expiry\n const source = oneLine(input.source)\n if (source.length > CARD_LIMITS.source) return { ok: false, error: `source is longer than ${CARD_LIMITS.source} characters` }\n if (source && /^[a-z][a-z0-9+.-]*:/i.test(source) && !/^https?:\\/\\//i.test(source)) {\n return { ok: false, error: \"source must be an http(s) link or a plain reference\" }\n }\n const extras = buildChoices(input)\n if (!extras.ok) return extras\n const followup = oneLine(input.followup).toLowerCase()\n if (followup && !(FOLLOWUP_KINDS as readonly string[]).includes(followup)) {\n return { ok: false, error: `followup must be one of ${FOLLOWUP_KINDS.join(\", \")}` }\n }\n let reply: ReplyTarget | undefined\n const r = input.reply as Record<string, unknown> | undefined\n if (r && typeof r === \"object\" && oneLine(r.channel) && oneLine(r.chatId)) {\n reply = { channel: oneLine(r.channel), chatId: oneLine(r.chatId), ...(oneLine(r.accountId) ? { accountId: oneLine(r.accountId) } : {}) }\n }\n return {\n ok: true,\n card: {\n id: newCardId(now, title),\n title,\n ask,\n recommend,\n if_silent: ifSilent,\n ...(ifSilentRaw === \"approve\" ? { if_silent_asked: \"approve\" as const } : {}),\n expires: expiry.at,\n ...(source ? { source } : {}),\n raised_by: raisedBy,\n ...(opts.node ? { node: opts.node } : {}),\n created_at: new Date(now).toISOString(),\n ...(reply ? { reply } : {}),\n ...extras.value,\n // Set by the daemon only (check-ins), never from what an agent sent.\n ...(opts.origin ? { origin: opts.origin } : {}),\n ...(followup ? { followup: followup as FollowupKind } : {}),\n status: \"pending\",\n },\n }\n}\n\n/** Validate, enforce the per-agent cap, and save. */\nexport function createCard(\n root: string,\n input: CardInput,\n opts: BuildCardOptions = {},\n): { ok: true; card: DecisionCard } | { ok: false; error: string } {\n const built = buildCard(input, opts)\n if (!built.ok) return built\n // The screen gate (#394): refused here, the reason goes back to the author.\n const broken = cardRuleBreak(built.card)\n if (broken) return { ok: false, error: broken }\n if (built.card.followup) {\n const full = followupBudgetRefusal(listCards(root), built.card.followup, opts.now ?? Date.now())\n if (full) return { ok: false, error: full }\n }\n // Retro cards are raised for an agent, not by it: they get their own\n // count, so they never use up the agent's room for its own cards.\n const isRetro = (c: { origin?: CardOrigin }) => isRetroOrigin(c.origin)\n const retro = isRetro(built.card)\n const open = listCards(root, \"pending\").filter((c) => c.raised_by === built.card.raised_by && isRetro(c) === retro).length\n if (open >= CARD_LIMITS.pendingPerAgent) {\n const what = retro ? \"retro cards\" : \"cards\"\n return { ok: false, error: `${built.card.raised_by} already has ${open} ${what} waiting; wait for decisions before raising more` }\n }\n saveCard(root, built.card)\n return built\n}\n\n/** Record the operator's answer. Refuses anything no longer pending. */\nexport function decideCard(\n root: string,\n id: string,\n verdict: Verdict,\n opts: { by?: string; note?: string; now?: number; choice?: string | number; text?: string } = {},\n): { ok: true; card: DecisionCard } | { ok: false; error: string } {\n const card = readCard(root, id)\n if (!card) return { ok: false, error: `no card \"${id}\"` }\n if (card.status !== \"pending\") return { ok: false, error: `card \"${id}\" is already ${card.status}` }\n const answer = resolveAnswer(card, verdict, opts)\n if (!answer.ok) return answer\n const note = oneLine(opts.note).slice(0, CARD_LIMITS.note)\n const decided: DecisionCard = {\n ...card,\n status: \"decided\",\n verdict,\n decided_by: opts.by ?? \"operator\",\n decided_at: new Date(opts.now ?? Date.now()).toISOString(),\n ...(note ? { note } : {}),\n ...(answer.choice ? { choice: answer.choice } : {}),\n ...(answer.text ? { text: answer.text } : {}),\n }\n saveCard(root, decided)\n return { ok: true, card: decided }\n}\n\n/** Cards whose answer the daemon acts on itself (a workflow run, a plan\n * step, a retro): only the operator closes those. A reminder card is the\n * agent's own to act on, so it may close it like one it raised. */\nconst AGENT_RESOLVABLE_ORIGINS = new Set<string | undefined>([undefined, \"reminder\"])\n\n/**\n * The raising agent closes its own pending card: the owner gave the same\n * answer outside the card (in chat) and the agent has acted on it (#909).\n * The card leaves the inbox, so no check-in or popup asks again. It is not\n * a verdict, and the agent is not sent a result for it: it already knows.\n */\nexport function resolveCard(\n root: string,\n id: string,\n opts: { by: string; reason?: unknown; node?: string; now?: number },\n): { ok: true; card: DecisionCard } | { ok: false; status: 400 | 403 | 404 | 409; error: string } {\n const card = readCard(root, id)\n if (!card) return { ok: false, status: 404, error: `no card \"${id}\"` }\n if (card.raised_by !== opts.by || (card.node ?? \"\") !== (opts.node ?? \"\")) {\n return { ok: false, status: 403, error: `card \"${id}\" was raised by another agent` }\n }\n if (!AGENT_RESOLVABLE_ORIGINS.has(card.origin?.kind)) {\n return { ok: false, status: 409, error: `card \"${id}\" is answered by the operator only` }\n }\n if (card.status !== \"pending\") return { ok: false, status: 409, error: `card \"${id}\" is already ${card.status}` }\n const reason = oneLine(opts.reason)\n if (!reason) return { ok: false, status: 400, error: \"reason is required: say where the owner answered and what you did\" }\n const at = new Date(opts.now ?? Date.now()).toISOString()\n const resolved: DecisionCard = {\n ...card,\n status: \"resolved\",\n decided_by: opts.by,\n decided_at: at,\n resolution: reason.slice(0, CARD_LIMITS.resolution),\n agent_notified_at: at,\n }\n saveCard(root, resolved)\n return { ok: true, card: resolved }\n}\n\n/** Apply `if_silent` to every pending card past its expiry. */\nexport function expireCards(root: string, now: number = Date.now()): DecisionCard[] {\n const out: DecisionCard[] = []\n for (const card of listCards(root, \"pending\")) {\n if (Date.parse(card.expires) > now) continue\n const expired: DecisionCard = {\n ...card,\n status: \"expired\",\n outcome: card.if_silent,\n decided_by: \"expiry\",\n decided_at: new Date(now).toISOString(),\n }\n saveCard(root, expired)\n out.push(expired)\n }\n return out\n}\n\n/** Decided or expired cards whose agent hasn't been told yet. */\nexport function cardsAwaitingAgentNotice(root: string): DecisionCard[] {\n return listCards(root).filter((c) => c.status !== \"pending\" && !c.agent_notified_at)\n}\n\nexport function markAgentNotified(root: string, id: string, now: number = Date.now()): void {\n const card = readCard(root, id)\n if (!card || card.agent_notified_at) return\n saveCard(root, { ...card, agent_notified_at: new Date(now).toISOString() })\n}\n\nexport const NO_UNDO_LINE =\n \"A no does not by itself undo anything you already did. If you already carried this out (for example because the owner approved it in chat), do not reverse it: ask the requester one clear question first.\"\n\n/** What the raising agent is told. Plain text, one short message. */\nexport function verdictMessage(card: DecisionCard): string {\n const retro = card.origin?.kind === \"retro\" ? card.origin : undefined\n const result = card.status === \"decided\"\n ? (card.verdict === \"yes\"\n ? (retro && !retroApproved(card) ? `The operator picked \"${RETRO_NONE}\", which counts as NO.` : \"The operator said YES.\")\n : \"The operator said NO.\")\n : `Nobody answered before it expired, so the default applied: ${card.outcome ?? card.if_silent}.`\n const lines = [\n `[Approval result] Your decision card \"${card.title}\" (${card.id}) is closed.`,\n `Question: ${card.ask}`,\n result,\n ]\n // A retro card's pick and spec go through retroLines, labelled as the\n // reviewer's proposal: never \"Approved text (send exactly this)\".\n const check = card.origin?.kind === \"retro-check\" ? card.origin : undefined\n if (card.status === \"decided\" && card.verdict === \"yes\" && !retro && !check) lines.push(...answerLines(card))\n if (card.note) lines.push(`Operator note: ${card.note}`)\n // A late no on something the owner already approved in chat must not\n // quietly undo work that is done (#909).\n if (card.status === \"decided\" && card.verdict === \"no\" && !retro && !check) lines.push(NO_UNDO_LINE)\n if (card.source) lines.push(`Source: ${card.source}`)\n if (card.origin?.kind === \"reminder\") lines.push(...originLines(card.origin, card.status === \"decided\" && card.verdict === \"yes\"))\n if (retro || check) {\n // Compare ignoring whitespace so a dashboard that only reflows the draft\n // does not resend the whole draft as the operator's note.\n const squash = (s: string) => s.replace(/\\s+/g, \" \").trim()\n const draft = draftFor(card.draft, card.choice)\n const edited = card.text && squash(card.text) !== squash(draft) ? card.text : undefined\n lines.push(...(retro ? retroLines(retro, card, edited) : retroCheckLines(check!, card, edited)))\n }\n if (card.reply) lines.push(`You raised it from ${card.reply.channel} chat ${card.reply.chatId}; reply there if the requester should know.`)\n if (card.node) lines.push(`The operator answered it on another machine; the card was forwarded from ${card.node}.`)\n lines.push(\"Act on this result now. Do not raise the same card again.\")\n return lines.join(\"\\n\")\n}\n","// --- Where a card came from, when the daemon raised it ---\n//\n// Agents raise most cards themselves. A check-in (checkin.ts) raises one on\n// an agent's behalf for an open Apple Reminder, and records the reminder\n// here so the agent that gets the answer knows what to act on and what to\n// tick off. Only the daemon sets it: POST /approvals and the agent tool\n// never pass it through.\n\nexport interface ReminderOrigin {\n kind: \"reminder\"\n /** The reminder's full id, as remindctl prints it. */\n id: string\n title: string\n list?: string\n}\n\n/** An open request that needs attention, shown as a card on the Mac\n * (popup-runner.ts). Never stored: the request is the record. */\nexport interface RequestOrigin {\n kind: \"request\"\n id: string\n}\n\n/** A retro card (src/retro): fixes to the agents' environment proposed\n * from one run that struggled. The answer goes back to the agent that ran\n * it, which builds the picked fix for a second review. */\nexport interface RetroOrigin {\n kind: \"retro\"\n /** The run the retro read. */\n taskId: string\n /** Failure signature (wiki/failure-candidates.ts), for one card per signature. */\n signature: string\n /** The reviewer's spec for each fix, in the order of the card's choices\n * (without \"None of these\"). Only the picked one reaches the agent. */\n specs?: string[]\n}\n\n/** A monthly review of a check a retro added (src/retro/checks.ts): a\n * guard rule tagged `retro:<taskId>` that fires often on runs that went\n * well. The answer goes back to the agent that built it, which keeps,\n * loosens or removes it for a second review. */\nexport interface RetroCheckOrigin {\n kind: \"retro-check\"\n /** The guard rule's id. */\n ruleId: string\n /** The run whose retro asked for the rule. */\n taskId: string\n /** The policy file that holds the rule, relative to the daemon's folder. */\n file: string\n}\n\n/** A step of a workflow run asks the owner (src/workflows, #788): an\n * owner.ask step, a person.message to approve, or a run's approval at\n * start. The answer resumes the run; the agent that started it is not\n * told separately, the run is. */\nexport interface WorkflowOrigin {\n kind: \"workflow\"\n runId: string\n nodeId: string\n}\n\n/** An agent proposed a reusable workflow (#788). Yes turns it on. */\nexport interface WorkflowProposalOrigin {\n kind: \"workflow-proposal\"\n workflowId: string\n}\n\n/** A step of a tracked plan the owner approves when the plan is made\n * (src/requests/plan-sweep.ts, #788). The plan check reads the answer\n * and acts on it; the agent is not sent a result turn. */\nexport interface PlanStepOrigin {\n kind: \"plan-step\"\n requestId: string\n step: number\n}\n\n/** A pull request that changes core paths waits for the owner (merge\n * policy, #1047). YES approves that one commit; the policy reads the\n * answer and updates the PR's status. No agent is sent a result turn. */\nexport interface MergePolicyOrigin {\n kind: \"merge-policy\"\n repo: string\n pr: number\n sha: string\n}\n\nexport type CardOrigin = ReminderOrigin | RequestOrigin | RetroOrigin | RetroCheckOrigin | PlanStepOrigin | WorkflowOrigin | WorkflowProposalOrigin | MergePolicyOrigin\n\n/** Retro cards of either kind: raised for an agent, not by it. */\nexport function isRetroOrigin(origin: CardOrigin | undefined): origin is RetroOrigin | RetroCheckOrigin {\n return origin?.kind === \"retro\" || origin?.kind === \"retro-check\"\n}\n\n/** The choices on a check review card, in this order. */\nexport const CHECK_CHOICES = { keep: \"Keep it\", loosen: \"Loosen it\", remove: \"Remove it\" } as const\n\n/** Lines for the agent told the result of a check review card. Keep, NO\n * and silence all leave the rule as it is. */\nexport function retroCheckLines(\n origin: RetroCheckOrigin,\n card: { status: string; verdict?: string; choice?: string },\n edited?: string,\n): string[] {\n const rule = `guard rule \\`${origin.ruleId}\\` in \\`${origin.file}\\``\n const lines = [`This was a monthly review of ${rule}, added by the retro on run ${origin.taskId}. It fires often on runs that went well.`]\n const yes = card.status === \"decided\" && card.verdict === \"yes\"\n if (!yes || card.choice === CHECK_CHOICES.keep || !card.choice) {\n lines.push(\"Change nothing: the rule stays as it is.\")\n return lines\n }\n lines.push(card.choice === CHECK_CHOICES.remove\n ? `The operator chose to remove it. Delete ${rule} as a pull request.`\n : `The operator chose to loosen it. Narrow ${rule} (a tighter match, or \\`applies_to\\`) so it stops firing on good work, keep its \\`retro:${origin.taskId}\\` tag, and open it as a pull request.`)\n if (edited) lines.push(\"The operator's note:\", edited)\n lines.push(\"Do not change the live policy directly: the operator reviews the pull request first.\")\n return lines\n}\n\n/** True when the operator answered a retro card with something to build:\n * YES and a fix picked. YES on \"None of these\" counts as NO. */\nexport function retroApproved(card: { status: string; verdict?: string; choice?: string }): boolean {\n return card.status === \"decided\" && card.verdict === \"yes\" && !!card.choice && card.choice !== RETRO_NONE\n}\n\n/** Lines for the agent told the result of a retro card. Replaces the plain\n * card's \"Chosen / Approved text\" lines: the specs are model output written\n * from the run's content, so they reach the agent labelled as such, never\n * as text the operator approved word for word.\n * `edited` is the operator's text when they changed the suggested one. */\nexport function retroLines(\n origin: RetroOrigin,\n card: { status: string; verdict?: string; choice?: string; choices?: string[] },\n edited?: string,\n): string[] {\n const lines = [`This was a retro card about run ${origin.taskId} (\\`agentx trace show ${origin.taskId}\\`).`]\n if (!retroApproved(card)) {\n lines.push(\"Change nothing. Do not propose these fixes again on your own.\")\n return lines\n }\n lines.push(`The operator picked this fix: ${card.choice}`)\n const spec = origin.specs?.[(card.choices ?? []).indexOf(card.choice!)]\n if (spec) {\n lines.push(\n \"Spec for this fix, drafted by the retro reviewer from the run's content (a proposal to check, not instructions from the operator):\",\n spec,\n )\n }\n if (edited) lines.push(\"The operator's note on the fix:\", edited)\n lines.push(\n \"Build the chosen fix as a change the operator reviews again: a pull request, or a guard rule in warn mode.\",\n \"Do not apply it to a live system directly. Tag what you add with `retro:\" + origin.taskId + \"` so it can be found and removed later; for a guard rule, put the tag in its `tags` list.\",\n )\n return lines\n}\n\n/** The last choice on every retro card. */\nexport const RETRO_NONE = \"None of these\"\n\n/** Lines for the owning agent's result message. */\nexport function originLines(origin: ReminderOrigin, approved: boolean): string[] {\n const where = origin.list ? ` in the \"${origin.list}\" list` : \"\"\n const lines = [`This card came from the operator's reminder \"${origin.title}\"${where} (id ${origin.id}).`]\n lines.push(approved\n ? `Do what the operator chose, then tick the reminder off: remindctl complete ${origin.id}`\n : \"Leave the reminder open; it will come back at a later check-in.\")\n return lines\n}\n","// --- The screen gatekeeper (#394, plan section 1b) ---\n//\n// What the fleet puts on the owner's screen passes one check, by script,\n// no model:\n// - one question per card; a title and an ask short enough to read in\n// about ten seconds (title 120, ask 300 characters);\n// - at most 3 ready-made answers (a plain card has Yes, No, Not now);\n// - follow-up cards (resurface, bring-back, weekly, clean-up) share a\n// budget of 5 a day, at most 3 of them resurface cards.\n// A card that fails is returned to its author with the reason: refused\n// when it is written, or not shown and told when the popup comes to it.\n// Nothing here rewrites, removes or answers a card. The call and Focus\n// hold is notify/hold.ts; the popup window takes no focus (card-window.ts).\n\nexport const SCREEN_LIMITS = { title: 120, ask: 300, answers: 3 } as const\n\nexport const FOLLOWUP_KINDS = [\"resurface\", \"bring-back\", \"weekly\", \"cleanup\"] as const\nexport type FollowupKind = (typeof FOLLOWUP_KINDS)[number]\n\nexport const SCREEN_BUDGET = { perDay: 5, resurface: 3 } as const\n\n/** Why this card may not go on the owner's screen, or null. */\nexport function cardRuleBreak(card: { title: string; ask: string; choices?: string[] }): string | null {\n if (card.title.length > SCREEN_LIMITS.title) return `title is longer than ${SCREEN_LIMITS.title} characters`\n if (card.ask.length > SCREEN_LIMITS.ask) return `ask is longer than ${SCREEN_LIMITS.ask} characters`\n if ((card.ask.match(/\\?/g) ?? []).length > 1) return \"ask holds more than one question: one card asks one thing\"\n if ((card.choices?.length ?? 0) > SCREEN_LIMITS.answers) return `more than ${SCREEN_LIMITS.answers} choices`\n return null\n}\n\n/** Why an agent's `agentx notify` may not go on the owner's screen, or\n * null: the same ten-second rule, title 120 and message 300. */\nexport function noticeRuleBreak(title: string, message: string): string | null {\n if (title.length > SCREEN_LIMITS.title) return `title is longer than ${SCREEN_LIMITS.title} characters`\n if (message.length > SCREEN_LIMITS.ask) return `message is longer than ${SCREEN_LIMITS.ask} characters`\n return null\n}\n\n/** Local midnight before `now`: the budget's day. */\nfunction dayStart(now: number): number {\n const d = new Date(now)\n d.setHours(0, 0, 0, 0)\n return d.getTime()\n}\n\n/** Why a follow-up card of this kind cannot be raised today, or null.\n * `cards` is every card, of any status: an answered one was on screen too. */\nexport function followupBudgetRefusal(\n cards: Array<{ followup?: FollowupKind; created_at: string }>,\n kind: FollowupKind,\n now: number,\n): string | null {\n const from = dayStart(now)\n const today = cards.filter((c) => c.followup && Date.parse(c.created_at) >= from)\n if (today.length >= SCREEN_BUDGET.perDay) {\n return `the follow-up screen budget is used up today (${SCREEN_BUDGET.perDay} cards): raise it again tomorrow`\n }\n if (kind === \"resurface\" && today.filter((c) => c.followup === \"resurface\").length >= SCREEN_BUDGET.resurface) {\n return `${SCREEN_BUDGET.resurface} resurface cards were already raised today: raise it again tomorrow`\n }\n return null\n}\n\n/** What the author hears when the popup does not show its card. */\nexport function returnedText(card: { id: string; title: string }, reason: string): string {\n return [\n `[screen gate] Your card ${card.id} (\"${card.title}\") was not shown to the owner: ${reason}.`,\n \"It is still in his inbox, unchanged. If it must reach him on screen, close it (agentx_approval resolve) and raise one that passes:\",\n `one question, title up to ${SCREEN_LIMITS.title} characters, ask up to ${SCREEN_LIMITS.ask}, at most ${SCREEN_LIMITS.answers} choices.`,\n ].join(\" \")\n}\n"],"mappings":"6DAAA,OAAS,cAAAA,EAAY,aAAAC,EAAW,eAAAC,EAAa,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,KAC5F,OAAS,WAAAC,MAAe,OCwFjB,SAASC,EAAcC,EAA0E,CACtG,OAAOA,GAAQ,OAAS,SAAWA,GAAQ,OAAS,aACtD,CAGO,IAAMC,EAAgB,CAAE,KAAM,UAAW,OAAQ,YAAa,OAAQ,WAAY,EAIlF,SAASC,EACdF,EACAG,EACAC,EACU,CACV,IAAMC,EAAO,gBAAgBL,EAAO,iBAAiBA,EAAO,SACtDM,EAAQ,CAAC,gCAAgCD,gCAAmCL,EAAO,gDAAgD,EAEzI,MAAI,EADQG,EAAK,SAAW,WAAaA,EAAK,UAAY,QAC9CA,EAAK,SAAWF,EAAc,MAAQ,CAACE,EAAK,QACtDG,EAAM,KAAK,0CAA0C,EAC9CA,IAETA,EAAM,KAAKH,EAAK,SAAWF,EAAc,OACrC,2CAA2CI,uBAC3C,2CAA2CA,4FAA+FL,EAAO,8CAA8C,EAC/LI,GAAQE,EAAM,KAAK,uBAAwBF,CAAM,EACrDE,EAAM,KAAK,sFAAsF,EAC1FA,EACT,CAIO,SAASC,EAAcJ,EAAsE,CAClG,OAAOA,EAAK,SAAW,WAAaA,EAAK,UAAY,OAAS,CAAC,CAACA,EAAK,QAAUA,EAAK,SAAWK,CACjG,CAOO,SAASC,EACdT,EACAG,EACAC,EACU,CACV,IAAME,EAAQ,CAAC,mCAAmCN,EAAO,+BAA+BA,EAAO,YAAY,EAC3G,GAAI,CAACO,EAAcJ,CAAI,EACrB,OAAAG,EAAM,KAAK,+DAA+D,EACnEA,EAETA,EAAM,KAAK,iCAAiCH,EAAK,QAAQ,EACzD,IAAMO,EAAOV,EAAO,SAASG,EAAK,SAAW,CAAC,GAAG,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AQ,OAAS,YAAYsE,EAAM,KAAK,GAAGG,EAAYzE,EAAK,OAAQA,EAAK,SAAW,WAAaA,EAAK,UAAY,KAAK,CAAC,EAC7HgD,GAASuB,EAAO,CAGlB,IAAMG,EAAUC,GAAcA,EAAE,QAAQ,OAAQ,GAAG,EAAE,KAAK,EACpDC,EAAQC,EAAS7E,EAAK,MAAOA,EAAK,MAAM,EACxC8E,EAAS9E,EAAK,MAAQ0E,EAAO1E,EAAK,IAAI,IAAM0E,EAAOE,CAAK,EAAI5E,EAAK,KAAO,OAC9EsE,EAAM,KAAK,GAAItB,EAAQ+B,EAAW/B,EAAOhD,EAAM8E,CAAM,EAAIE,EAAgBT,EAAQvE,EAAM8E,CAAM,CAAE,EAEjG,OAAI9E,EAAK,OAAOsE,EAAM,KAAK,sBAAsBtE,EAAK,MAAM,gBAAgBA,EAAK,MAAM,mDAAmD,EACtIA,EAAK,MAAMsE,EAAM,KAAK,4EAA4EtE,EAAK,OAAO,EAClHsE,EAAM,KAAK,2DAA2D,EAC/DA,EAAM,KAAK;AAAA,CAAI,CACxB","names":["existsSync","mkdirSync","readdirSync","readFileSync","renameSync","writeFileSync","resolve","isRetroOrigin","origin","CHECK_CHOICES","retroCheckLines","card","edited","rule","lines","retroApproved","RETRO_NONE","retroLines","spec","originLines","approved","where","SCREEN_LIMITS","FOLLOWUP_KINDS","SCREEN_BUDGET","cardRuleBreak","card","noticeRuleBreak","title","message","dayStart","now","d","followupBudgetRefusal","cards","kind","from","today","c","returnedText","reason","IF_SILENT_VALUES","asIfSilent","v","CARD_LIMITS","DEFAULT_CARD_SETTINGS","approvalsDir","root","resolve","CARD_ID_RE","isValidCardId","id","fileFor","newCardId","now","title","day","slug","saveCard","card","mkdirSync","path","tmp","writeFileSync","renameSync","readCard","readFileSync","legacy","listCards","status","dir","existsSync","out","f","readdirSync","c","oneLine","resolveExpiry","input","settings","max","at","raw","rel","buildCard","opts","ask","recommend","raisedBy","ifSilentRaw","ifSilent","expiry","source","extras","buildChoices","followup","FOLLOWUP_KINDS","reply","r","createCard","built","broken","cardRuleBreak","full","followupBudgetRefusal","isRetro","isRetroOrigin","retro","open","what","decideCard","verdict","answer","resolveAnswer","note","decided","AGENT_RESOLVABLE_ORIGINS","resolveCard","reason","resolved","expireCards","expired","cardsAwaitingAgentNotice","markAgentNotified","NO_UNDO_LINE","verdictMessage","result","retroApproved","RETRO_NONE","lines","check","answerLines","originLines","squash","s","draft","draftFor","edited","retroLines","retroCheckLines"]}
|
package/dist/chunk-VY7TBMJU.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var n={count:3,label:120,draft:2e3,say:160,context:600,text:4e3},f="{choice}";function a(e){return typeof e=="string"?e.replace(/\s+/g," ").trim():""}function h(e){return typeof e=="string"?e.replace(/\r\n?/g,`
|
|
2
|
-
`).trim():""}function u(e){let t={};if(e.choices!==void 0&&e.choices!==null){if(!Array.isArray(e.choices))return{ok:!1,error:"choices must be a list of short labels"};let r=e.choices.map(a).filter(Boolean);if(r.length!==e.choices.length)return{ok:!1,error:"every choice must be a non-empty label"};if(r.length>n.count)return{ok:!1,error:`at most ${n.count} choices`};if(r.some(c=>c.length>n.label))return{ok:!1,error:`a choice is longer than ${n.label} characters`};if(new Set(r).size!==r.length)return{ok:!1,error:"choices must be different from each other"};r.length&&(t.choices=r)}let o=h(e.draft);if(o){if(o.length>n.draft)return{ok:!1,error:`draft is longer than ${n.draft} characters`};t.draft=o}let i=a(e.say);if(i){if(i.length>n.say)return{ok:!1,error:`say is longer than ${n.say} characters`};t.say=i}let s=h(e.context);if(s){if(s.length>n.context)return{ok:!1,error:`context is longer than ${n.context} characters`};t.context=s}return{ok:!0,value:t}}function l(e,t){return e?t?e.split(f).join(t):e:""}function g(e,t,o){if(t==="no")return{ok:!0};let i,s=e.choices??[];if(o.choice!==void 0&&o.choice!==""){if(!s.length)return{ok:!1,error:"this card has no choices"};let c=typeof o.choice=="number"?o.choice:Number(o.choice);if(Number.isInteger(c)&&c>=1&&c<=s.length)i=s[c-1];else if(s.includes(a(o.choice)))i=a(o.choice);else return{ok:!1,error:`choice must be 1-${s.length} or one of the labels`}}else if(s.length)return{ok:!1,error:"this card offers choices: pick one (Mac popup, or `agentx approvals approve <key> --choice <n>`)"};let r=h(o.text);return!r&&e.draft&&(r=l(e.draft,i)),r.length>n.text?{ok:!1,error:`text is longer than ${n.text} characters`}:{ok:!0,...i?{choice:i}:{},...r?{text:r}:{}}}function x(e){let t=[];return e.choice&&t.push(`Chosen: ${e.choice}`),e.text&&t.push("Approved text (send exactly this, the operator may have edited it):",e.text),t}export{n as a,f as b,u as c,l as d,g as e,x as f};
|
|
3
|
-
//# sourceMappingURL=chunk-VY7TBMJU.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/approvals/choices.ts"],"sourcesContent":["// --- Ready-made answers on a decision card ---\n//\n// A card can offer a few choices (say, three free meeting slots), a\n// suggested message the operator may edit before it goes, and a short\n// context (what the other person said) shown above the question. The operator's\n// pick and the final text are stored on the card and handed to the agent\n// that raised it; the agent does the sending. Nothing here sends anything.\n//\n// All optional: a card without them is the plain yes/no card it always was.\n\nexport const CHOICE_LIMITS = {\n /** Most options a card may offer. More is a form, not a choice; the\n * screen gate (#394) allows 3. */\n count: 3,\n label: 120,\n draft: 2000,\n say: 160,\n context: 600,\n /** The operator's final text, after editing. */\n text: 4000,\n} as const\n\n/** The spot in `draft` that takes the picked label. */\nexport const CHOICE_PLACEHOLDER = \"{choice}\"\n\nexport interface CardChoices {\n choices?: string[]\n draft?: string\n say?: string\n /** A few lines of background, shown above the question. */\n context?: string\n}\n\nfunction oneLine(v: unknown): string {\n return typeof v === \"string\" ? v.replace(/\\s+/g, \" \").trim() : \"\"\n}\n\n/** A draft keeps its line breaks: it is a message, not a label. */\nfunction block(v: unknown): string {\n return typeof v === \"string\" ? v.replace(/\\r\\n?/g, \"\\n\").trim() : \"\"\n}\n\n/** Validate what an agent sent. Empty input gives an empty object. */\nexport function buildChoices(input: { choices?: unknown; draft?: unknown; say?: unknown; context?: unknown }): { ok: true; value: CardChoices } | { ok: false; error: string } {\n const value: CardChoices = {}\n if (input.choices !== undefined && input.choices !== null) {\n if (!Array.isArray(input.choices)) return { ok: false, error: \"choices must be a list of short labels\" }\n const labels = input.choices.map(oneLine).filter(Boolean)\n if (labels.length !== input.choices.length) return { ok: false, error: \"every choice must be a non-empty label\" }\n if (labels.length > CHOICE_LIMITS.count) return { ok: false, error: `at most ${CHOICE_LIMITS.count} choices` }\n if (labels.some((l) => l.length > CHOICE_LIMITS.label)) return { ok: false, error: `a choice is longer than ${CHOICE_LIMITS.label} characters` }\n if (new Set(labels).size !== labels.length) return { ok: false, error: \"choices must be different from each other\" }\n if (labels.length) value.choices = labels\n }\n const draft = block(input.draft)\n if (draft) {\n if (draft.length > CHOICE_LIMITS.draft) return { ok: false, error: `draft is longer than ${CHOICE_LIMITS.draft} characters` }\n value.draft = draft\n }\n const say = oneLine(input.say)\n if (say) {\n if (say.length > CHOICE_LIMITS.say) return { ok: false, error: `say is longer than ${CHOICE_LIMITS.say} characters` }\n value.say = say\n }\n const context = block(input.context)\n if (context) {\n if (context.length > CHOICE_LIMITS.context) return { ok: false, error: `context is longer than ${CHOICE_LIMITS.context} characters` }\n value.context = context\n }\n return { ok: true, value }\n}\n\n/** The suggested message for a pick, with `{choice}` filled in. */\nexport function draftFor(draft: string | undefined, choice: string | undefined): string {\n if (!draft) return \"\"\n return choice ? draft.split(CHOICE_PLACEHOLDER).join(choice) : draft\n}\n\n/**\n * Check the operator's answer against the card. A yes on a card with\n * choices must say which one: approving \"the meeting\" without a date would\n * leave the agent to guess, which is the thing the card exists to avoid.\n */\nexport function resolveAnswer(\n card: CardChoices,\n verdict: \"yes\" | \"no\",\n answer: { choice?: string | number; text?: string },\n): { ok: true; choice?: string; text?: string } | { ok: false; error: string } {\n if (verdict === \"no\") return { ok: true }\n let choice: string | undefined\n const list = card.choices ?? []\n if (answer.choice !== undefined && answer.choice !== \"\") {\n if (!list.length) return { ok: false, error: \"this card has no choices\" }\n const n = typeof answer.choice === \"number\" ? answer.choice : Number(answer.choice)\n if (Number.isInteger(n) && n >= 1 && n <= list.length) choice = list[n - 1]\n else if (list.includes(oneLine(answer.choice))) choice = oneLine(answer.choice)\n else return { ok: false, error: `choice must be 1-${list.length} or one of the labels` }\n } else if (list.length) {\n return { ok: false, error: \"this card offers choices: pick one (Mac popup, or `agentx approvals approve <key> --choice <n>`)\" }\n }\n let text = block(answer.text)\n if (!text && card.draft) text = draftFor(card.draft, choice)\n if (text.length > CHOICE_LIMITS.text) return { ok: false, error: `text is longer than ${CHOICE_LIMITS.text} characters` }\n return { ok: true, ...(choice ? { choice } : {}), ...(text ? { text } : {}) }\n}\n\n/** Lines for the agent's result message. Empty for a plain card. */\nexport function answerLines(card: { choice?: string; text?: string }): string[] {\n const lines: string[] = []\n if (card.choice) lines.push(`Chosen: ${card.choice}`)\n if (card.text) lines.push(\"Approved text (send exactly this, the operator may have edited it):\", card.text)\n return lines\n}\n"],"mappings":"AAUO,IAAMA,EAAgB,CAG3B,MAAO,EACP,MAAO,IACP,MAAO,IACP,IAAK,IACL,QAAS,IAET,KAAM,GACR,EAGaC,EAAqB,WAUlC,SAASC,EAAQC,EAAoB,CACnC,OAAO,OAAOA,GAAM,SAAWA,EAAE,QAAQ,OAAQ,GAAG,EAAE,KAAK,EAAI,EACjE,CAGA,SAASC,EAAMD,EAAoB,CACjC,OAAO,OAAOA,GAAM,SAAWA,EAAE,QAAQ,SAAU;AAAA,CAAI,EAAE,KAAK,EAAI,EACpE,CAGO,SAASE,EAAaC,EAAkJ,CAC7K,IAAMC,EAAqB,CAAC,EAC5B,GAAID,EAAM,UAAY,QAAaA,EAAM,UAAY,KAAM,CACzD,GAAI,CAAC,MAAM,QAAQA,EAAM,OAAO,EAAG,MAAO,CAAE,GAAI,GAAO,MAAO,wCAAyC,EACvG,IAAME,EAASF,EAAM,QAAQ,IAAIJ,CAAO,EAAE,OAAO,OAA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SAAW,CAAC,EAC9B,GAAIE,EAAO,SAAW,QAAaA,EAAO,SAAW,GAAI,CACvD,GAAI,CAACC,EAAK,OAAQ,MAAO,CAAE,GAAI,GAAO,MAAO,0BAA2B,EACxE,IAAMC,EAAI,OAAOF,EAAO,QAAW,SAAWA,EAAO,OAAS,OAAOA,EAAO,MAAM,EAClF,GAAI,OAAO,UAAUE,CAAC,GAAKA,GAAK,GAAKA,GAAKD,EAAK,OAAQL,EAASK,EAAKC,EAAI,CAAC,UACjED,EAAK,SAASjB,EAAQgB,EAAO,MAAM,CAAC,EAAGJ,EAASZ,EAAQgB,EAAO,MAAM,MACzE,OAAO,CAAE,GAAI,GAAO,MAAO,oBAAoBC,EAAK,6BAA8B,UAC9EA,EAAK,OACd,MAAO,CAAE,GAAI,GAAO,MAAO,kGAAmG,EAEhI,IAAIE,EAAOjB,EAAMc,EAAO,IAAI,EAE5B,MADI,CAACG,GAAQL,EAAK,QAAOK,EAAOR,EAASG,EAAK,MAAOF,CAAM,GACvDO,EAAK,OAASrB,EAAc,KAAa,CAAE,GAAI,GAAO,MAAO,uBAAuBA,EAAc,iBAAkB,EACjH,CAAE,GAAI,GAAM,GAAIc,EAAS,CAAE,OAAAA,CAAO,EAAI,CAAC,EAAI,GAAIO,EAAO,CAAE,KAAAA,CAAK,EAAI,CAAC,CAAG,CAC9E,CAGO,SAASC,EAAYN,EAAoD,CAC9E,IAAMO,EAAkB,CAAC,EACzB,OAAIP,EAAK,QAAQO,EAAM,KAAK,WAAWP,EAAK,QAAQ,EAChDA,EAAK,MAAMO,EAAM,KAAK,sEAAuEP,EAAK,IAAI,EACnGO,CACT","names":["CHOICE_LIMITS","CHOICE_PLACEHOLDER","oneLine","v","block","buildChoices","input","value","labels","l","draft","say","context","draftFor","choice","resolveAnswer","card","verdict","answer","list","n","text","answerLines","lines"]}
|