agentix-cli 0.136.0 → 0.136.1

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 (46) hide show
  1. package/dist/{agent-VCGAUBER.js → agent-TMTYLAOV.js} +2 -2
  2. package/dist/{board-dashboard-JZM3FQNV.js → board-dashboard-OSI4X5ZJ.js} +2 -2
  3. package/dist/{chunk-C43E3YFT.js → chunk-4AFA6LQZ.js} +2 -2
  4. package/dist/{chunk-M5B4QG6J.js → chunk-63LV77EG.js} +2 -2
  5. package/dist/{chunk-HH7OFAEM.js → chunk-EGDY762K.js} +2 -2
  6. package/dist/{chunk-ZPJVDX2U.js → chunk-FRTELYZ4.js} +2 -2
  7. package/dist/chunk-G26UHWS4.js +105 -0
  8. package/dist/chunk-G26UHWS4.js.map +1 -0
  9. package/dist/{chunk-QCUJTAAZ.js → chunk-NVZ66ITP.js} +3 -3
  10. package/dist/{chunk-H2N7DOPT.js → chunk-QHZFMO6M.js} +2 -2
  11. package/dist/{chunk-K75LFQE3.js → chunk-QW3L5IIC.js} +2 -2
  12. package/dist/{chunk-QTDKNJXD.js → chunk-XXIZGNLT.js} +213 -213
  13. package/dist/{chunk-QTDKNJXD.js.map → chunk-XXIZGNLT.js.map} +1 -1
  14. package/dist/cli.js +1 -1
  15. package/dist/{hub-IIW2GBO5.js → hub-7AMS6ADP.js} +2 -2
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.js +1 -1
  18. package/dist/{program-WROQ55F5.js → program-IUUHETTV.js} +154 -154
  19. package/dist/program-IUUHETTV.js.map +1 -0
  20. package/dist/{promote-HDLU44MX.js → promote-VCNVE5JD.js} +2 -2
  21. package/dist/{registry-3RE5SG22.js → registry-MMNG5VZ6.js} +2 -2
  22. package/dist/rules-UVUJTVOE.js +24 -0
  23. package/dist/rules-UVUJTVOE.js.map +1 -0
  24. package/dist/{wiki-ZS6OHOWQ.js → wiki-ZQMDUXTE.js} +2 -2
  25. package/dist/wiki-enrich-NPNOSTRM.js +2 -0
  26. package/package.json +1 -1
  27. package/dist/chunk-OISCRNMW.js +0 -105
  28. package/dist/chunk-OISCRNMW.js.map +0 -1
  29. package/dist/program-WROQ55F5.js.map +0 -1
  30. package/dist/rules-HUUFXQD6.js +0 -24
  31. package/dist/rules-HUUFXQD6.js.map +0 -1
  32. package/dist/wiki-enrich-NGPFWTVA.js +0 -2
  33. /package/dist/{agent-VCGAUBER.js.map → agent-TMTYLAOV.js.map} +0 -0
  34. /package/dist/{board-dashboard-JZM3FQNV.js.map → board-dashboard-OSI4X5ZJ.js.map} +0 -0
  35. /package/dist/{chunk-C43E3YFT.js.map → chunk-4AFA6LQZ.js.map} +0 -0
  36. /package/dist/{chunk-M5B4QG6J.js.map → chunk-63LV77EG.js.map} +0 -0
  37. /package/dist/{chunk-HH7OFAEM.js.map → chunk-EGDY762K.js.map} +0 -0
  38. /package/dist/{chunk-ZPJVDX2U.js.map → chunk-FRTELYZ4.js.map} +0 -0
  39. /package/dist/{chunk-QCUJTAAZ.js.map → chunk-NVZ66ITP.js.map} +0 -0
  40. /package/dist/{chunk-H2N7DOPT.js.map → chunk-QHZFMO6M.js.map} +0 -0
  41. /package/dist/{chunk-K75LFQE3.js.map → chunk-QW3L5IIC.js.map} +0 -0
  42. /package/dist/{hub-IIW2GBO5.js.map → hub-7AMS6ADP.js.map} +0 -0
  43. /package/dist/{promote-HDLU44MX.js.map → promote-VCNVE5JD.js.map} +0 -0
  44. /package/dist/{registry-3RE5SG22.js.map → registry-MMNG5VZ6.js.map} +0 -0
  45. /package/dist/{wiki-ZS6OHOWQ.js.map → wiki-ZQMDUXTE.js.map} +0 -0
  46. /package/dist/{wiki-enrich-NGPFWTVA.js.map → wiki-enrich-NPNOSTRM.js.map} +0 -0
@@ -1,24 +0,0 @@
1
- import{d as v,i as V,k as X,m as T}from"./chunk-U6EJ53DA.js";import{k as P}from"./chunk-H4NSB54D.js";import"./chunk-MTX4UPNB.js";import{f as g,g as O}from"./chunk-QAWKN2N4.js";import"./chunk-IMLAPB7G.js";import"./chunk-OWNQ2FD4.js";import"./chunk-KEXBEUSU.js";import"./chunk-ROLSSYXE.js";import"./chunk-QIJLFPWE.js";import{createHash as ue}from"crypto";import{existsSync as de,mkdirSync as pe,readFileSync as ge,writeFileSync as me}from"fs";import{resolve as B}from"path";var U="wiki-rules",x="wiki-rules",he=["deadline","due date","due by","penalt","late fee","fine of","fined","must file","must pay","must declare","must submit","filing","obligation","compliance","tax return","\xE9ch\xE9ance","date limite","d\xE9lai","p\xE9nalit","amende","majoration","d\xE9claration","obligation","\u063A\u0631\u0627\u0645\u0629","\u0623\u062C\u0644","\u0622\u062C\u0627\u0644","\u062A\u0635\u0631\u064A\u062D","\u062E\u0637\u064A\u0629"],fe=new Set(["event","agent","device","server","app","domain","account","penalty","relief","due_date","person"]),ye=new Set(["person","organization"]),we=6e3,ke=900,W=(e,t)=>e.length>t?`${e.slice(0,t)}\u2026`:e,S=e=>typeof e=="string"?e.replace(/\s+/g," ").trim():"",G=e=>S(e).replace(/["\[\]]/g,"").slice(0,120).trim();function Ne(e=he){let t=e.map(o=>o.trim().replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).filter(Boolean);return new RegExp(`(^|[^\\p{L}\\p{N}])(${t.join("|")})`,"iu")}function $e(e,t){return t.test(`${e.article.meta.title}
2
- ${P(e.article.content)}`)}function be(e,t,o=[]){let n=new Set(o.map(g)),r=i=>i.pages.every(d=>(d.article.meta.tags??[]).includes(x)),s=i=>i.type==="legal_source"?0:i.type==="obligation"?1:2;return[...e.entities.values()].filter(i=>!r(i)).filter(i=>n.size?n.has(g(i.id))||n.has(g(i.title)):i.type==="legal_source"||i.type==="obligation"||!fe.has(i.type)&&i.pages.some(d=>$e(d,t))).sort((i,d)=>s(i)-s(d)||d.sources.length-i.sources.length||i.title.localeCompare(d.title))}function Z(e,t,o,n){let r=` ${g(o)} `,s=new Set([...(e.outgoing.get(t.id)??[]).map(i=>i.to),...(e.incoming.get(t.id)??[]).map(i=>i.from)]);return[...e.entities.values()].filter(i=>n.has(i.type)&&i.id!==t.id).filter(i=>s.has(i.id)||g(i.title).length>=3&&r.includes(` ${g(i.title)} `)).slice(0,40)}function Re(e,t,o,n){let r=`${o.article.meta.title}
3
- ${P(o.article.content)}`,s=n(o.article.meta.sources??[]).sort((l,p)=>p.date.localeCompare(l.date)).slice(0,10),i=`${r}
4
- ${s.map(l=>l.content).join(`
5
- `)}`,d=l=>l.pages.some(p=>v(p.article.meta,o.article.meta)),a=l=>[...e.entities.values()].filter(p=>p.type===l&&p.id!==t.id&&d(p));return{source:t,page:o,entries:s,known:a("obligation").slice(0,60),laws:a("legal_source").slice(0,40),parties:Z(e,t,i,ye).filter(d),authorities:Z(e,t,i,new Set(["organization"])).filter(d)}}function ee(e){let t=[`${e.agentId}/${e.article.path}`,P(e.article.content),...(e.article.meta.sources??[]).slice().sort()];return ue("sha1").update(t.join(`
6
- `)).digest("hex").slice(0,16)}function Se(e,t){let o=t.statements.filter(n=>["action","due_rule"].includes(n.property)).map(n=>`${n.property}: ${n.value}`);return`- ${t.title}${o.length?` (${o.join("; ")})`:""}`}function We(e,t,o){let n=t.page,r=[`You are writing the rules one wiki page states, so nobody has to research them again. Today is ${o}.`,"",`## The page: ${n.agentId}/${n.article.path}: "${n.article.meta.title}"`,W(P(n.article.content),we),"","## Source entries behind the page (newest first)"];for(let s of t.entries)r.push(`### entry ${s.id} (${s.date}, ${s.agentId})`,W(s.content.trim(),ke),"");return r.push("## Rule pages that already exist",...t.known.map(s=>Se(e,s)),""),r.push("## Legal source pages",...t.laws.map(s=>`- ${s.title}`),""),r.push("## People and organizations it names",...t.parties.map(s=>`- ${s.title} (${s.type})`),""),r.push("## Task","List each rule the page or the entries state: something a person or organization must do, by a deadline or on a schedule, often with a penalty when they do not.","Return one JSON object and nothing else:",'{"rules": [{"title": "\u2026", "action": "\u2026", "bearer": ["\u2026"], "deadline": "\u2026", "amount": "\u2026", "authority": "\u2026", "penalty": "\u2026", "basis": "\u2026", "procedure": "\u2026", "source": "\u2026"}]}',"","Rules:",'- title: a short name for the rule, such as "Monthly payroll tax filing". When it is one of the rule pages that already exist, use that title exactly.',"- action: what must be done, in one sentence. A rule without one is dropped.",'- bearer: who must do it. Use a listed person or organization title when it is one, else a short description such as "every employer".','- deadline: when, as the rule says it ("by the 15th of the following month"), not a computed date.',"- amount: what is paid or declared, if the rule says. authority: who it is filed with or paid to.","- penalty: what happens when it is late or missing, as stated.","- basis: the law, article or document it comes from. Use a listed legal source title when it is one.","- procedure: how it is done, in one sentence, if stated.","- source: the entry id or the page (agent/path) the rule comes from. A rule without one is dropped.","- Leave a field empty when the page and entries do not state it. Never guess a deadline, an amount or a penalty.","- Do not list one-time tasks, reminders or plans; only standing rules.","- Write in the language the page is written in.",'- No rules on the page: return {"rules": []}.'),r.join(`
7
- `)}function _e(e,t,o){let n=[],r=t.page,s=[...t.entries.map(l=>l.id),`${r.agentId}/${r.article.path}`,r.article.path],i=new Map(t.known.map(l=>[g(l.title),l])),d=[],a=new Set;for(let l of Array.isArray(e.rules)?e.rules:[]){let p=l??{},c=G(S(p.title)),u=W(S(p.action),400),$=S(p.source);if(!c){n.push("a rule with no title");continue}if(!u){n.push(`${c}: no action`);continue}if(!$||!s.some(R=>$.includes(R))){n.push(`${c}: source not among those given`);continue}if(a.has(g(c)))continue;a.add(g(c));let f=i.get(g(c)),w=o.names.get(g(c)),y=!f&&w?o.entities.get(w):void 0;if(y&&y.type!=="obligation"){n.push(`${c}: a page of type ${y.type} already has this title`);continue}let _=(Array.isArray(p.bearer)?p.bearer:[p.bearer]).map(R=>W(S(R),120)).filter(Boolean);d.push({title:f?.title??y?.title??c,existing:f??y,action:u,bearers:[...new Set(_)].slice(0,5),deadline:W(S(p.deadline),200),amount:W(S(p.amount),200),authority:W(S(p.authority),120),penalty:W(S(p.penalty),300),basis:W(S(p.basis),200),procedure:W(S(p.procedure),400),source:W($,200)})}return{rules:d,dropped:n}}function D(e,t){return t.find(n=>g(n.title)===g(e))?.title??e}function j(e,t){let o=r=>r&&/^\d{4}-\d{2}-\d{2}/.test(r)?r.slice(0,10):void 0;return t.entries.filter(r=>e.source.includes(r.id)).map(r=>o(r.date)).filter(Boolean).sort().at(-1)??o(t.entries[0]?.date)??o(t.page.article.meta.created)}function ve(e,t){let o=j(e,t),n=(s,i)=>({property:s,value:i,source:e.source,...o?{checked_at:o}:{},status:"proposed",by:U}),r=[n("action",e.action)];for(let s of e.bearers)r.push(n("bearer",D(s,t.parties)));return e.deadline&&r.push(n("due_rule",e.deadline)),e.amount&&r.push(n("amount_rule",e.amount)),e.authority&&r.push(n("authority",D(e.authority,t.authorities))),r.push(n("created_by",e.basis?D(e.basis,t.laws):t.page.article.meta.title)),e.procedure&&r.push(n("procedure",e.procedure)),r}var re=new Set(["action","due_rule","amount_rule","authority","created_by","procedure"]);function xe(e,t,o){let n=e.filter(i=>i.by===U),r=new Set(t.filter(i=>i.property!=="created_by"||o.basis||!n.some(d=>d.property==="created_by")).map(i=>i.property)),s=t.filter(i=>r.has(i.property));for(let i of n)(re.has(i.property)?!r.has(i.property):!s.some(d=>d.property===i.property&&g(d.value)===g(i.value)))&&s.push(i);return s}function te(e,t,o){let n=(e.statements??[]).filter(a=>a.by!==U||a.status==="confirmed"),r=new Set(n.filter(a=>a.status==="confirmed"&&re.has(a.property)).map(a=>a.property)),s=a=>`${a.property}
8
- ${g(a.value)}`,i=new Set(n.map(s)),d=[...n,...t.filter(a=>!r.has(a.property)&&!i.has(s(a)))];return{...e,statements:d.length?d:void 0,lastUpdated:o}}var Y="not found in the sources yet";function Ee(e,t,o){let n=c=>e.filter(u=>u.property===c),r=c=>e.find(u=>u.property===c),s=r("action"),i=c=>c&&c.source&&c.source!==s?.source?` (from ${c.source}${c.checked_at?`, ${c.checked_at}`:""})`:"",d=(c,u)=>`- **${c}:** ${u?`${u.value}${i(u)}`:Y}`,a=[...new Set([...e,...t?[t]:[]].map(c=>c.source).filter(c=>!!c))],l=[...e.filter(c=>["action","due_rule"].includes(c.property)),...t?[t]:[]].map(c=>c.checked_at).filter(c=>!!c).sort(),p=r("created_by")?.value;return[d("What to do",s),`- **Who:** ${n("bearer").length?n("bearer").map(c=>c.value).join(", "):Y}`,d("Deadline",r("due_rule")),...r("amount_rule")?[d("Amount",r("amount_rule"))]:[],...r("authority")?[d("Filed with",r("authority"))]:[],`- **Penalty:** ${t?`${t.value}${i(t)}`:Y}`,`- **Source:** ${p?`${p}, `:""}last read from [[${o}]]${a.length?` (sources: ${a.join(", ")})`:""}`,`- **Source date:** ${l[0]??"not known"}. Not yet checked with the law or the authority.`].join(`
9
- `)}var ne="## Rule summary",z="<!-- /rule-summary -->";function Ae(e,t){let o=`${ne}
10
-
11
- ${t.trim()}
12
-
13
- ${z}
14
- `,n=e.indexOf(`${ne}
15
- `),r=n<0?-1:e.indexOf(z,n);return n>=0&&r>=0?`${e.slice(0,n)}${o}${e.slice(r+z.length).replace(/^\n/,"")}`:`${o}
16
- ${e.trim()}
17
- `}function Fe(e){let t=B(e,"_rules","state.json");if(!de(t))return{sources:{}};try{let o=JSON.parse(ge(t,"utf-8"));return o&&typeof o.sources=="object"?o:{sources:{}}}catch{return{sources:{}}}}function Le(e,t){pe(B(e,"_rules"),{recursive:!0}),me(B(e,"_rules","state.json"),JSON.stringify(t,null,2))}function Ie(e,t,o,n,r){let s=o.page,i=n.get(g(t.title));if(i)return v(s.article.meta,i.meta)?i:"the rule page is readable by agents who cannot read the source";if(t.existing){let c=T(e,t.existing);if(!c)return"the rule page was copied from another machine";let u=e.getAgentWiki(c.agentId).readArticle(c.article.path);return u?v(s.article.meta,u.meta)?{agentId:c.agentId,path:c.article.path,meta:u.meta,content:u.content,created:!1}:"the rule page is readable by agents who cannot read the source":"the rule page was moved or removed during the run"}let d=s.article.meta.owner||s.agentId,a=e.getAgentWiki(s.agentId),l=`obligations/${O(t.title)}.md`;for(let c=2;a.readArticle(l);c++)l=`obligations/${O(t.title)}-${c}.md`;let p={title:t.title,class:"obligation",tags:[x],owner:d,access:s.article.meta.access,sharedWith:s.article.meta.sharedWith,created:r,lastUpdated:r,sources:[]};return{agentId:s.agentId,path:l,meta:p,content:`${t.title}.
18
- `,created:!0}}var se=e=>`penalties/${O(G(`${e} penalty`))}.md`;function Pe(e,t,o,n){let r=i=>{let d=(i??[]).filter(l=>l.property==="amount_rule"&&l.value),a=d.find(l=>l.status==="confirmed")??d[0];return a?{value:a.value,source:a.source,checked_at:a.checked_at,...a.status==="confirmed"?{confirmed:!0}:{}}:void 0},s=e.getAgentWiki(n.agentId).readArticle(se(o));if(s&&(s.meta.tags??[]).includes(x))return r(s.meta.statements);for(let i of t.entities.values()){if(i.type!=="penalty"||!i.statements.some(l=>l.property==="penalty_for"&&g(l.value)===g(o)))continue;let d=i.pages.find(l=>v(n.meta,l.article.meta)),a=d&&r(d.article.meta.statements);if(a)return a}}function Ue(e,t,o,n){let r=G(`${e.title} penalty`),s=j(e,o),i=(a,l)=>({property:a,value:l,source:e.source,...s?{checked_at:s}:{},status:"proposed",by:U}),d=[i("penalty_for",e.title),i("amount_rule",e.penalty),i("created_by",e.basis?D(e.basis,o.laws):o.page.article.meta.title)];return{path:se(e.title),meta:{title:r,class:"penalty",tags:[x],owner:t.meta.owner,access:t.meta.access,sharedWith:t.meta.sharedWith,created:n,lastUpdated:n,sources:t.meta.sources,statements:d,related:[e.title]},content:`## Overview
19
-
20
- ${e.penalty}
21
-
22
- For [[${e.title}]]. Source: ${e.source}${s?`, dated ${s}`:""}. Not yet checked with the law or the authority.
23
- `}}function ie(e,t,o,n,r,s){let i=[];for(let d of t.bearers){let a=o.parties.find(y=>g(y.title)===g(d));if(!a)continue;let l=T(e,a);if(!l){s.push(`${t.title} \u2192 ${a.title}: page copied from another machine`);continue}if(!v(n.meta,l.article.meta)){s.push(`${t.title} \u2192 ${a.title}: page readable by agents who cannot read the rule`);continue}let p=y=>(y.statements??[]).some(_=>_.property==="subject_to"&&g(_.value)===g(t.title));if(p(l.article.meta))continue;if(r){i.push(a.title);continue}let c=e.getAgentWiki(l.agentId),u=c.readArticle(l.article.path);if(!u){s.push(`${t.title} \u2192 ${a.title}: page moved or removed during the run`);continue}if(!v(n.meta,u.meta)){s.push(`${t.title} \u2192 ${a.title}: page readable by agents who cannot read the rule`);continue}if(p(u.meta))continue;let $=j(t,o),f=[...u.meta.statements??[],{property:"subject_to",value:t.title,source:t.source,...$?{checked_at:$}:{},status:"proposed",by:U}],w={...u.meta,statements:f};c.writeArticle(l.article.path,w,u.content,u.meta.owner||l.agentId)?(l.article.meta=w,i.push(a.title)):s.push(`${t.title} \u2192 ${a.title}: write refused`)}return i}async function He(e,t,o,n,r){let s=u=>r.sources[u.id]?.failures??0,i=be(t,n.words,n.only).sort((u,$)=>s(u)-s($)),d=u=>e.getSharedStore().readEntries(u),a={outcomes:[],costUsd:0,capped:!1},l=new Map,p=0,c=(u,$,f,w=!1)=>{if(n.dryRun)return;let y=r.sources[u];r.sources[u]=w?{fingerprint:y?.fingerprint??"",at:new Date().toISOString(),costUsd:f,failures:(y?.failures??0)+1}:{fingerprint:$,at:new Date().toISOString(),costUsd:f},n.save?.(r)};for(let u of i){if(p>=n.max)break;let $={source:u.id,title:u.title,rules:[],costUsd:0,dropped:[]},f=T(e,u);if(!f){n.only.length&&a.outcomes.push({...$,status:"no-page"});continue}let w=Re(t,u,f,d),y=ee(f);if(!n.force&&r.sources[u.id]?.fingerprint===y){n.only.length&&a.outcomes.push({...$,status:"unchanged"});continue}if(a.costUsd>=n.maxCostUsd){a.capped=!0;break}p++;let _=`${f.agentId}/${f.article.path}`,R;try{R=await o(We(t,w,n.today))}catch(m){a.outcomes.push({...$,page:_,status:"failed",dropped:[m.message.slice(0,200)]}),c(u.id,y,0,!0);continue}a.costUsd+=R.costUsd;let b={...$,page:_,status:"no-reply",costUsd:R.costUsd},J=V(R.text);if(!J){a.outcomes.push(b),c(u.id,y,R.costUsd);continue}let M=_e(J,w,t);if(b.dropped=M.dropped,M.rules.length===0){b.status="no-rules",a.outcomes.push(b),c(u.id,y,R.costUsd);continue}let N=!1;for(let m of M.rules){let h=Ie(e,m,w,l,n.today);if(typeof h=="string"){b.dropped.push(`${m.title}: ${h}`);continue}let ae=xe(h.meta.statements??[],ve(m,w),m),q=te(h.meta,ae,n.today),F=Pe(e,t,m.title,h),L=F?.confirmed||!m.penalty?F:{value:m.penalty,source:m.source,checked_at:j(m,w)},H=Ee(q.statements??[],L,f.article.meta.title),Q=(h.meta.tags??[]).includes(x)?X(h.content,H):Ae(h.content,H),oe=[...new Set([...h.meta.related??[],f.article.meta.title,...L?[G(`${m.title} penalty`)]:[]])],ce=[...new Set([...h.meta.sources??[],...w.entries.filter(k=>m.source.includes(k.id)).map(k=>k.id)])],E={...q,related:oe,sources:ce},A={title:m.title,page:`${h.agentId}/${h.path}`,created:h.created,deadline:(E.statements??[]).some(k=>k.property==="due_rule"),penalty:!!L,linked:[]};if(n.dryRun){A.preview=H,A.linked=ie(e,m,w,h,!0,b.dropped),b.rules.push(A);continue}let I=e.getAgentWiki(h.agentId);if(!I.writeArticle(h.path,E,Q,h.meta.owner||h.agentId)){b.dropped.push(`${m.title}: write refused`),N=!0;continue}if(l.set(g(m.title),{...h,meta:E,content:Q,created:!1}),m.penalty&&!F?.confirmed){let k=Ue(m,{...h,meta:E},w,n.today),C=I.readArticle(k.path);if(!C)I.writeArticle(k.path,k.meta,k.content,k.meta.owner);else if((C.meta.tags??[]).includes(x)){let le=te({...k.meta,created:C.meta.created,statements:C.meta.statements},k.meta.statements??[],n.today);I.writeArticle(k.path,le,k.content,k.meta.owner)}else b.dropped.push(`${m.title}: ${k.path} already exists`)}A.linked=ie(e,m,w,{...h,meta:E},!1,b.dropped),I.rebuildIndex(),b.rules.push(A)}b.status=n.dryRun?"dry-run":b.rules.length?"written":N?"failed":"no-rules",a.outcomes.push(b);let K=n.dryRun?null:e.getAgentWiki(f.agentId).readArticle(f.article.path);K&&(y=ee({agentId:f.agentId,article:K})),c(u.id,y,R.costUsd,N&&b.rules.length===0)}return a}export{he as DEFAULT_RULE_WORDS,U as RULES_BY,x as RULES_TAG,We as buildRulesPrompt,_e as checkRules,Pe as knownPenalty,Fe as loadRulesState,xe as mergeRuleStatements,Ee as ruleOverview,be as ruleSources,ve as ruleStatements,Ne as ruleWordsPattern,Re as rulesContext,ee as rulesFingerprint,He as runRules,Le as saveRulesState,j as sourceDate,$e as statesRules,te as withRuleStatements,Ae as withRuleSummary};
24
- //# sourceMappingURL=rules-HUUFXQD6.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/wiki/rules.ts"],"sourcesContent":["// --- Rule pages: one page per obligation, with deadline, penalty, source and check date (#811) ---\n//\n// Agents research the same rule again and again (a filing deadline, a\n// late fee) because the answer stays inside the page or chat where it\n// came up. This job reads the pages that state rules: legal sources,\n// obligation pages agents wrote, and any other page whose text speaks of\n// deadlines, penalties or filings. One model call per source page\n// returns the rules it states. Each rule is checked against what the\n// call was shown, then written once as an obligation page:\n// - statements for the obligation lens (action, bearer, due, amount,\n// authority, created by, procedure), each with its source and the\n// date of that source, marked proposed until the owner confirms them;\n// - a penalty page linked to it with `penalty_for`;\n// - `subject_to` on the page of each person or organization that must\n// follow it, so their Obligations panel lists it.\n// A later source that states less keeps what an earlier one stated: a\n// field is replaced only when the new source gives it. The model gets no\n// tools and every write goes through the store, which keeps the old version.\n\nimport { createHash } from \"crypto\"\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\"\nimport { resolve } from \"path\"\nimport type { WikiHub } from \"./hub\"\nimport type { WikiArticleMeta, WikiEntry } from \"./types\"\nimport { normName, slugify, type Entity, type GraphPage, type WikiGraph } from \"./ontology/graph\"\nimport type { WikiStatement } from \"./ontology/types\"\nimport { bodyOf } from \"./ontology/view-entity\"\nimport { parseEnrichReply, readableAlongside, targetPage, withOverview, type EnrichCall } from \"./enrich\"\n\nexport const RULES_BY = \"wiki-rules\"\n/** Tag on the pages this job creates; they are never read as a source. */\nexport const RULES_TAG = \"wiki-rules\"\n\n/** Words that mark a page as stating a rule. Stems, matched at a word start. */\nexport const DEFAULT_RULE_WORDS = [\n \"deadline\", \"due date\", \"due by\", \"penalt\", \"late fee\", \"fine of\", \"fined\", \"must file\", \"must pay\", \"must declare\",\n \"must submit\", \"filing\", \"obligation\", \"compliance\", \"tax return\",\n \"échéance\", \"date limite\", \"délai\", \"pénalit\", \"amende\", \"majoration\", \"déclaration\", \"obligation\",\n \"غرامة\", \"أجل\", \"آجال\", \"تصريح\", \"خطية\",\n]\n\n/** Types never read as a rule source: things that happen or run, not rules. */\nconst SKIP_TYPES = new Set([\"event\", \"agent\", \"device\", \"server\", \"app\", \"domain\", \"account\", \"penalty\", \"relief\", \"due_date\", \"person\"])\n/** Types a rule's bearer may link to; anything else stays text. */\nconst BEARER_TYPES = new Set([\"person\", \"organization\"])\n\nconst PAGE_CHARS = 6000\nconst ENTRY_CHARS = 900\nconst clip = (s: string, n: number) => (s.length > n ? `${s.slice(0, n)}…` : s)\nconst str = (v: unknown): string => (typeof v === \"string\" ? v.replace(/\\s+/g, \" \").trim() : \"\")\n/** Frontmatter keeps a title on one quoted line. */\nconst cleanTitle = (s: string) => str(s).replace(/[\"\\[\\]]/g, \"\").slice(0, 120).trim()\n\nexport function ruleWordsPattern(words: string[] = DEFAULT_RULE_WORDS): RegExp {\n const escaped = words.map(w => w.trim().replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")).filter(Boolean)\n return new RegExp(`(^|[^\\\\p{L}\\\\p{N}])(${escaped.join(\"|\")})`, \"iu\")\n}\n\nexport interface RulesContext {\n /** The entity whose page is read. */\n source: Entity\n page: GraphPage\n entries: WikiEntry[]\n /** Obligation pages that already exist, so a known rule is updated, not doubled. */\n known: Entity[]\n /** Legal source pages a rule may cite as its basis. */\n laws: Entity[]\n /** People and organizations the page links or names. */\n parties: Entity[]\n /** Organizations a rule may name as its authority. */\n authorities: Entity[]\n}\n\nexport interface RuleDraft {\n title: string\n /** Set when the rule matches an existing obligation page. */\n existing?: Entity\n action: string\n bearers: string[]\n deadline: string\n amount: string\n authority: string\n penalty: string\n basis: string\n procedure: string\n source: string\n}\n\nexport interface RulesResult {\n rules: RuleDraft[]\n dropped: string[]\n}\n\n/** True when the page reads like it states a rule. */\nexport function statesRules(page: GraphPage, words: RegExp): boolean {\n return words.test(`${page.article.meta.title}\\n${bodyOf(page.article.content)}`)\n}\n\n/**\n * Entities whose page this job reads: legal sources and obligation pages\n * first, then any other page whose text matches the rule words. Pages\n * this job created are skipped.\n */\nexport function ruleSources(g: WikiGraph, words: RegExp, only: string[] = []): Entity[] {\n const wanted = new Set(only.map(normName))\n const ours = (e: Entity) => e.pages.every(p => (p.article.meta.tags ?? []).includes(RULES_TAG))\n const rank = (e: Entity) => (e.type === \"legal_source\" ? 0 : e.type === \"obligation\" ? 1 : 2)\n return [...g.entities.values()]\n .filter(e => !ours(e))\n .filter(e => wanted.size\n ? wanted.has(normName(e.id)) || wanted.has(normName(e.title))\n : e.type === \"legal_source\" || e.type === \"obligation\" || (!SKIP_TYPES.has(e.type) && e.pages.some(p => statesRules(p, words))))\n .sort((a, b) => rank(a) - rank(b) || b.sources.length - a.sources.length || a.title.localeCompare(b.title))\n}\n\n/** Entities of a type whose title appears in the text, or linked to `e`. */\nfunction partiesOf(g: WikiGraph, e: Entity, text: string, types: Set<string>): Entity[] {\n const hay = ` ${normName(text)} `\n const linked = new Set([...(g.outgoing.get(e.id) ?? []).map(x => x.to), ...(g.incoming.get(e.id) ?? []).map(x => x.from)])\n return [...g.entities.values()]\n .filter(x => types.has(x.type) && x.id !== e.id)\n .filter(x => linked.has(x.id) || (normName(x.title).length >= 3 && hay.includes(` ${normName(x.title)} `)))\n .slice(0, 40)\n}\n\n/** What one call for `source` may read: its page and the entries behind it. */\nexport function rulesContext(g: WikiGraph, source: Entity, page: GraphPage, readEntries: (ids: string[]) => WikiEntry[]): RulesContext {\n const text = `${page.article.meta.title}\\n${bodyOf(page.article.content)}`\n const entries = readEntries(page.article.meta.sources ?? []).sort((a, b) => b.date.localeCompare(a.date)).slice(0, 10)\n const all = `${text}\\n${entries.map(x => x.content).join(\"\\n\")}`\n const visible = (x: Entity) => x.pages.some(p => readableAlongside(p.article.meta, page.article.meta))\n const of = (type: string) => [...g.entities.values()].filter(x => x.type === type && x.id !== source.id && visible(x))\n return {\n source,\n page,\n entries,\n known: of(\"obligation\").slice(0, 60),\n laws: of(\"legal_source\").slice(0, 40),\n parties: partiesOf(g, source, all, BEARER_TYPES).filter(visible),\n authorities: partiesOf(g, source, all, new Set([\"organization\"])).filter(visible),\n }\n}\n\n/** Changes when the source page's text or the entries behind it change.\n * A `subject_to` link this job adds to the page does not change it. */\nexport function rulesFingerprint(page: GraphPage): string {\n const parts = [`${page.agentId}/${page.article.path}`, bodyOf(page.article.content), ...(page.article.meta.sources ?? []).slice().sort()]\n return createHash(\"sha1\").update(parts.join(\"\\n\")).digest(\"hex\").slice(0, 16)\n}\n\nfunction knownLine(g: WikiGraph, e: Entity): string {\n const facts = e.statements.filter(s => [\"action\", \"due_rule\"].includes(s.property)).map(s => `${s.property}: ${s.value}`)\n return `- ${e.title}${facts.length ? ` (${facts.join(\"; \")})` : \"\"}`\n}\n\nexport function buildRulesPrompt(g: WikiGraph, ctx: RulesContext, today: string): string {\n const p = ctx.page\n const lines = [\n `You are writing the rules one wiki page states, so nobody has to research them again. Today is ${today}.`,\n \"\",\n `## The page: ${p.agentId}/${p.article.path}: \"${p.article.meta.title}\"`,\n clip(bodyOf(p.article.content), PAGE_CHARS),\n \"\",\n \"## Source entries behind the page (newest first)\",\n ]\n for (const en of ctx.entries) lines.push(`### entry ${en.id} (${en.date}, ${en.agentId})`, clip(en.content.trim(), ENTRY_CHARS), \"\")\n lines.push(\"## Rule pages that already exist\", ...ctx.known.map(e => knownLine(g, e)), \"\")\n lines.push(\"## Legal source pages\", ...ctx.laws.map(e => `- ${e.title}`), \"\")\n lines.push(\"## People and organizations it names\", ...ctx.parties.map(e => `- ${e.title} (${e.type})`), \"\")\n lines.push(\n \"## Task\",\n \"List each rule the page or the entries state: something a person or organization must do, by a deadline or on a schedule, often with a penalty when they do not.\",\n \"Return one JSON object and nothing else:\",\n `{\"rules\": [{\"title\": \"…\", \"action\": \"…\", \"bearer\": [\"…\"], \"deadline\": \"…\", \"amount\": \"…\", \"authority\": \"…\", \"penalty\": \"…\", \"basis\": \"…\", \"procedure\": \"…\", \"source\": \"…\"}]}`,\n \"\",\n \"Rules:\",\n \"- title: a short name for the rule, such as \\\"Monthly payroll tax filing\\\". When it is one of the rule pages that already exist, use that title exactly.\",\n \"- action: what must be done, in one sentence. A rule without one is dropped.\",\n \"- bearer: who must do it. Use a listed person or organization title when it is one, else a short description such as \\\"every employer\\\".\",\n \"- deadline: when, as the rule says it (\\\"by the 15th of the following month\\\"), not a computed date.\",\n \"- amount: what is paid or declared, if the rule says. authority: who it is filed with or paid to.\",\n \"- penalty: what happens when it is late or missing, as stated.\",\n \"- basis: the law, article or document it comes from. Use a listed legal source title when it is one.\",\n \"- procedure: how it is done, in one sentence, if stated.\",\n \"- source: the entry id or the page (agent/path) the rule comes from. A rule without one is dropped.\",\n \"- Leave a field empty when the page and entries do not state it. Never guess a deadline, an amount or a penalty.\",\n \"- Do not list one-time tasks, reminders or plans; only standing rules.\",\n \"- Write in the language the page is written in.\",\n \"- No rules on the page: return {\\\"rules\\\": []}.\",\n )\n return lines.join(\"\\n\")\n}\n\n/** Keep only rules with an action and a source the call was shown. */\nexport function checkRules(raw: Record<string, unknown>, ctx: RulesContext, g: WikiGraph): RulesResult {\n const dropped: string[] = []\n const p = ctx.page\n const sourceIds = [...ctx.entries.map(x => x.id), `${p.agentId}/${p.article.path}`, p.article.path]\n const known = new Map(ctx.known.map(e => [normName(e.title), e]))\n const rules: RuleDraft[] = []\n const seen = new Set<string>()\n for (const item of Array.isArray(raw.rules) ? raw.rules : []) {\n const r = (item ?? {}) as Record<string, unknown>\n const title = cleanTitle(str(r.title))\n const action = clip(str(r.action), 400)\n const source = str(r.source)\n if (!title) { dropped.push(\"a rule with no title\"); continue }\n if (!action) { dropped.push(`${title}: no action`); continue }\n if (!source || !sourceIds.some(id => source.includes(id))) { dropped.push(`${title}: source not among those given`); continue }\n if (seen.has(normName(title))) continue\n seen.add(normName(title))\n const existing = known.get(normName(title))\n const taken = g.names.get(normName(title))\n const clash = !existing && taken ? g.entities.get(taken) : undefined\n if (clash && clash.type !== \"obligation\") { dropped.push(`${title}: a page of type ${clash.type} already has this title`); continue }\n const bearers = (Array.isArray(r.bearer) ? r.bearer : [r.bearer]).map(b => clip(str(b), 120)).filter(Boolean)\n rules.push({\n title: existing?.title ?? clash?.title ?? title,\n existing: existing ?? clash,\n action,\n bearers: [...new Set(bearers)].slice(0, 5),\n deadline: clip(str(r.deadline), 200),\n amount: clip(str(r.amount), 200),\n authority: clip(str(r.authority), 120),\n penalty: clip(str(r.penalty), 300),\n basis: clip(str(r.basis), 200),\n procedure: clip(str(r.procedure), 400),\n source: clip(source, 200),\n })\n }\n return { rules, dropped }\n}\n\n/** The title of a listed page when `value` names one, else the value. */\nfunction asPage(value: string, list: Entity[]): string {\n const hit = list.find(e => normName(e.title) === normName(value))\n return hit?.title ?? value\n}\n\n/**\n * The date of what the rule was read from: the entry it cites, else the\n * newest entry behind the page, else the day the page was created. Never\n * the run date: nothing was checked at the law or the authority.\n */\nexport function sourceDate(r: Pick<RuleDraft, \"source\">, ctx: RulesContext): string | undefined {\n const day = (d?: string) => (d && /^\\d{4}-\\d{2}-\\d{2}/.test(d) ? d.slice(0, 10) : undefined)\n const cited = ctx.entries.filter(x => r.source.includes(x.id)).map(x => day(x.date)).filter(Boolean).sort()\n return cited.at(-1) ?? day(ctx.entries[0]?.date) ?? day(ctx.page.article.meta.created)\n}\n\n/** Statements an obligation page gets for one rule, proposed until the owner confirms them. */\nexport function ruleStatements(r: RuleDraft, ctx: RulesContext): WikiStatement[] {\n const checked = sourceDate(r, ctx)\n const st = (property: string, value: string): WikiStatement => ({\n property, value, source: r.source, ...(checked ? { checked_at: checked } : {}), status: \"proposed\", by: RULES_BY,\n })\n const out = [st(\"action\", r.action)]\n for (const b of r.bearers) out.push(st(\"bearer\", asPage(b, ctx.parties)))\n if (r.deadline) out.push(st(\"due_rule\", r.deadline))\n if (r.amount) out.push(st(\"amount_rule\", r.amount))\n if (r.authority) out.push(st(\"authority\", asPage(r.authority, ctx.authorities)))\n out.push(st(\"created_by\", r.basis ? asPage(r.basis, ctx.laws) : ctx.page.article.meta.title))\n if (r.procedure) out.push(st(\"procedure\", r.procedure))\n return out\n}\n\n/** Properties a rule holds one value of; `bearer` may hold several. */\nconst SINGLE = new Set([\"action\", \"due_rule\", \"amount_rule\", \"authority\", \"created_by\", \"procedure\"])\n\n/**\n * This job's statements for a rule after reading one more source: a\n * field the new source states replaces the earlier one; a field it leaves\n * empty keeps the earlier value with its own source and date. A basis the\n * new source does not name (`created_by` set to the page read) does not\n * replace a law an earlier source named. Bearers add up.\n */\nexport function mergeRuleStatements(earlier: WikiStatement[], fresh: WikiStatement[], r: Pick<RuleDraft, \"basis\">): WikiStatement[] {\n const prev = earlier.filter(s => s.by === RULES_BY)\n const stated = new Set(fresh.filter(s => s.property !== \"created_by\" || r.basis || !prev.some(p => p.property === \"created_by\")).map(s => s.property))\n const out = fresh.filter(s => stated.has(s.property))\n for (const s of prev) {\n if (SINGLE.has(s.property) ? !stated.has(s.property) : !out.some(o => o.property === s.property && normName(o.value) === normName(s.value))) out.push(s)\n }\n return out\n}\n\n/** Statements merged in: this job's earlier ones replaced, others kept. A\n * statement the owner confirmed stays, and wins over a new value. */\nexport function withRuleStatements(meta: WikiArticleMeta, statements: WikiStatement[], today: string): WikiArticleMeta {\n const kept = (meta.statements ?? []).filter(s => s.by !== RULES_BY || s.status === \"confirmed\")\n const confirmed = new Set(kept.filter(s => s.status === \"confirmed\" && SINGLE.has(s.property)).map(s => s.property))\n const key = (s: WikiStatement) => `${s.property}\\n${normName(s.value)}`\n const taken = new Set(kept.map(key))\n const all = [...kept, ...statements.filter(s => !confirmed.has(s.property) && !taken.has(key(s)))]\n return { ...meta, statements: all.length ? all : undefined, lastUpdated: today }\n}\n\n/** A penalty as stated, with where it was read and that source's date. */\nexport interface PenaltyFact {\n value: string\n source?: string\n checked_at?: string\n /** The owner confirmed it: it wins over what a new source states. */\n confirmed?: boolean\n}\n\nconst missing = \"not found in the sources yet\"\n\n/** The plain-words summary at the top of an obligation page, built from\n * the statements the page holds after the merge. */\nexport function ruleOverview(statements: WikiStatement[], penalty: PenaltyFact | undefined, readFrom: string): string {\n const all = (p: string) => statements.filter(s => s.property === p)\n const one = (p: string) => statements.find(s => s.property === p)\n const action = one(\"action\")\n // A field read from another source than the action says which.\n const from = (s?: { source?: string; checked_at?: string }) =>\n s && s.source && s.source !== action?.source ? ` (from ${s.source}${s.checked_at ? `, ${s.checked_at}` : \"\"})` : \"\"\n const line = (label: string, s?: WikiStatement) => `- **${label}:** ${s ? `${s.value}${from(s)}` : missing}`\n const sources = [...new Set([...statements, ...(penalty ? [penalty] : [])].map(s => s.source).filter((x): x is string => !!x))]\n const dates = [...statements.filter(s => [\"action\", \"due_rule\"].includes(s.property)), ...(penalty ? [penalty] : [])]\n .map(s => s.checked_at).filter((x): x is string => !!x).sort()\n const basis = one(\"created_by\")?.value\n return [\n line(\"What to do\", action),\n `- **Who:** ${all(\"bearer\").length ? all(\"bearer\").map(s => s.value).join(\", \") : missing}`,\n line(\"Deadline\", one(\"due_rule\")),\n ...(one(\"amount_rule\") ? [line(\"Amount\", one(\"amount_rule\"))] : []),\n ...(one(\"authority\") ? [line(\"Filed with\", one(\"authority\"))] : []),\n `- **Penalty:** ${penalty ? `${penalty.value}${from(penalty)}` : missing}`,\n `- **Source:** ${basis ? `${basis}, ` : \"\"}last read from [[${readFrom}]]${sources.length ? ` (sources: ${sources.join(\", \")})` : \"\"}`,\n `- **Source date:** ${dates[0] ?? \"not known\"}. Not yet checked with the law or the authority.`,\n ].join(\"\\n\")\n}\n\nconst SUMMARY_HEAD = \"## Rule summary\"\nconst SUMMARY_END = \"<!-- /rule-summary -->\"\n\n/**\n * The summary on a page this job did not create. It goes in its own\n * section, which only this job rewrites, so the page's own Overview is\n * never replaced.\n */\nexport function withRuleSummary(content: string, summary: string): string {\n const section = `${SUMMARY_HEAD}\\n\\n${summary.trim()}\\n\\n${SUMMARY_END}\\n`\n const start = content.indexOf(`${SUMMARY_HEAD}\\n`)\n const end = start < 0 ? -1 : content.indexOf(SUMMARY_END, start)\n if (start >= 0 && end >= 0) return `${content.slice(0, start)}${section}${content.slice(end + SUMMARY_END.length).replace(/^\\n/, \"\")}`\n return `${section}\\n${content.trim()}\\n`\n}\n\nexport interface RulesState {\n sources: Record<string, { fingerprint: string; at: string; costUsd?: number; failures?: number }>\n}\n\nexport function loadRulesState(wikiDir: string): RulesState {\n const file = resolve(wikiDir, \"_rules\", \"state.json\")\n if (!existsSync(file)) return { sources: {} }\n try {\n const v = JSON.parse(readFileSync(file, \"utf-8\"))\n return v && typeof v.sources === \"object\" ? v : { sources: {} }\n } catch {\n return { sources: {} }\n }\n}\n\nexport function saveRulesState(wikiDir: string, state: RulesState): void {\n mkdirSync(resolve(wikiDir, \"_rules\"), { recursive: true })\n writeFileSync(resolve(wikiDir, \"_rules\", \"state.json\"), JSON.stringify(state, null, 2))\n}\n\nexport interface RulesOptions {\n /** Entity ids or titles; empty means every page that states rules. */\n only: string[]\n words: RegExp\n max: number\n maxCostUsd: number\n dryRun: boolean\n force: boolean\n today: string\n save?: (state: RulesState) => void\n}\n\nexport interface RuleWrite {\n title: string\n /** agent/path of the obligation page. */\n page: string\n created: boolean\n deadline: boolean\n penalty: boolean\n /** Bearer pages that got a `subject_to` link. */\n linked: string[]\n /** Dry runs: the summary that would be written. */\n preview?: string\n}\n\nexport interface RulesOutcome {\n source: string\n title: string\n page?: string\n status: \"written\" | \"dry-run\" | \"unchanged\" | \"no-page\" | \"no-reply\" | \"no-rules\" | \"failed\"\n rules: RuleWrite[]\n costUsd: number\n dropped: string[]\n}\n\nexport interface RulesRun {\n outcomes: RulesOutcome[]\n costUsd: number\n capped: boolean\n}\n\ninterface Target {\n agentId: string\n path: string\n meta: WikiArticleMeta\n content: string\n created: boolean\n}\n\n/**\n * Where a rule is written: the existing obligation page when one is\n * owned here and no wider audience than the source can read it, else a\n * new page in the source page's wiki with the source page's access.\n */\nfunction ruleTarget(hub: WikiHub, r: RuleDraft, ctx: RulesContext, made: Map<string, Target>, today: string): Target | string {\n const src = ctx.page\n const again = made.get(normName(r.title))\n if (again) return readableAlongside(src.article.meta, again.meta) ? again : \"the rule page is readable by agents who cannot read the source\"\n if (r.existing) {\n const page = targetPage(hub, r.existing)\n if (!page) return \"the rule page was copied from another machine\"\n // The run waited for the model: merge onto what is on disk now, not\n // the copy read when the run started.\n const now = hub.getAgentWiki(page.agentId).readArticle(page.article.path)\n if (!now) return \"the rule page was moved or removed during the run\"\n if (!readableAlongside(src.article.meta, now.meta)) return \"the rule page is readable by agents who cannot read the source\"\n return { agentId: page.agentId, path: page.article.path, meta: now.meta, content: now.content, created: false }\n }\n const owner = src.article.meta.owner || src.agentId\n const store = hub.getAgentWiki(src.agentId)\n let path = `obligations/${slugify(r.title)}.md`\n for (let n = 2; store.readArticle(path); n++) path = `obligations/${slugify(r.title)}-${n}.md`\n const meta: WikiArticleMeta = {\n title: r.title, class: \"obligation\", tags: [RULES_TAG], owner, access: src.article.meta.access,\n sharedWith: src.article.meta.sharedWith, created: today, lastUpdated: today, sources: [],\n }\n return { agentId: src.agentId, path, meta, content: `${r.title}.\\n`, created: true }\n}\n\nconst penaltyPath = (title: string) => `penalties/${slugify(cleanTitle(`${title} penalty`))}.md`\n\n/**\n * The penalty a rule already has: on the page this job wrote for it, else\n * on any penalty page linked to it with `penalty_for`. A confirmed\n * statement is preferred over a proposed one on the same page.\n */\nexport function knownPenalty(hub: WikiHub, g: WikiGraph, title: string, t: Pick<Target, \"agentId\" | \"meta\">): PenaltyFact | undefined {\n const fact = (statements?: WikiStatement[]): PenaltyFact | undefined => {\n const all = (statements ?? []).filter(x => x.property === \"amount_rule\" && x.value)\n const s = all.find(x => x.status === \"confirmed\") ?? all[0]\n return s ? { value: s.value, source: s.source, checked_at: s.checked_at, ...(s.status === \"confirmed\" ? { confirmed: true } : {}) } : undefined\n }\n const own = hub.getAgentWiki(t.agentId).readArticle(penaltyPath(title))\n if (own && (own.meta.tags ?? []).includes(RULES_TAG)) return fact(own.meta.statements)\n for (const e of g.entities.values()) {\n if (e.type !== \"penalty\" || !e.statements.some(s => s.property === \"penalty_for\" && normName(s.value) === normName(title))) continue\n const page = e.pages.find(p => readableAlongside(t.meta, p.article.meta))\n const f = page && fact(page.article.meta.statements)\n if (f) return f\n }\n return undefined\n}\n\nfunction penaltyPage(r: RuleDraft, t: Target, ctx: RulesContext, today: string): { path: string; meta: WikiArticleMeta; content: string } {\n const title = cleanTitle(`${r.title} penalty`)\n const checked = sourceDate(r, ctx)\n const st = (property: string, value: string): WikiStatement => ({\n property, value, source: r.source, ...(checked ? { checked_at: checked } : {}), status: \"proposed\", by: RULES_BY,\n })\n const statements = [st(\"penalty_for\", r.title), st(\"amount_rule\", r.penalty), st(\"created_by\", r.basis ? asPage(r.basis, ctx.laws) : ctx.page.article.meta.title)]\n return {\n path: penaltyPath(r.title),\n meta: {\n title, class: \"penalty\", tags: [RULES_TAG], owner: t.meta.owner, access: t.meta.access, sharedWith: t.meta.sharedWith,\n created: today, lastUpdated: today, sources: t.meta.sources, statements, related: [r.title],\n },\n content: `## Overview\\n\\n${r.penalty}\\n\\nFor [[${r.title}]]. Source: ${r.source}${checked ? `, dated ${checked}` : \"\"}. Not yet checked with the law or the authority.\\n`,\n }\n}\n\n/** Add `subject_to` to each bearer's page that may show the rule. */\nfunction linkBearers(hub: WikiHub, r: RuleDraft, ctx: RulesContext, t: Target, dryRun: boolean, dropped: string[]): string[] {\n const linked: string[] = []\n for (const b of r.bearers) {\n const e = ctx.parties.find(x => normName(x.title) === normName(b))\n if (!e) continue\n const page = targetPage(hub, e)\n if (!page) { dropped.push(`${r.title} → ${e.title}: page copied from another machine`); continue }\n // The link shows the rule's title on the bearer's page.\n if (!readableAlongside(t.meta, page.article.meta)) { dropped.push(`${r.title} → ${e.title}: page readable by agents who cannot read the rule`); continue }\n const linkedTo = (m: WikiArticleMeta) => (m.statements ?? []).some(s => s.property === \"subject_to\" && normName(s.value) === normName(r.title))\n if (linkedTo(page.article.meta)) continue\n if (dryRun) { linked.push(e.title); continue }\n // Write onto the page as it is now, not the copy read at the start.\n const store = hub.getAgentWiki(page.agentId)\n const now = store.readArticle(page.article.path)\n if (!now) { dropped.push(`${r.title} → ${e.title}: page moved or removed during the run`); continue }\n if (!readableAlongside(t.meta, now.meta)) { dropped.push(`${r.title} → ${e.title}: page readable by agents who cannot read the rule`); continue }\n if (linkedTo(now.meta)) continue\n const checked = sourceDate(r, ctx)\n const statements = [...(now.meta.statements ?? []), { property: \"subject_to\", value: r.title, source: r.source, ...(checked ? { checked_at: checked } : {}), status: \"proposed\" as const, by: RULES_BY }]\n // A link added is not an edit of the page: `lastUpdated` stays.\n const meta = { ...now.meta, statements }\n if (store.writeArticle(page.article.path, meta, now.content, now.meta.owner || page.agentId)) {\n page.article.meta = meta\n linked.push(e.title)\n } else {\n dropped.push(`${r.title} → ${e.title}: write refused`)\n }\n }\n return linked\n}\n\nexport async function runRules(hub: WikiHub, g: WikiGraph, call: EnrichCall, opts: RulesOptions, state: RulesState): Promise<RulesRun> {\n const failures = (e: Entity) => state.sources[e.id]?.failures ?? 0\n const candidates = ruleSources(g, opts.words, opts.only).sort((a, b) => failures(a) - failures(b))\n const readEntries = (ids: string[]) => hub.getSharedStore().readEntries(ids)\n const run: RulesRun = { outcomes: [], costUsd: 0, capped: false }\n const made = new Map<string, Target>()\n let calls = 0\n const remember = (id: string, fp: string, costUsd: number, failed = false) => {\n if (opts.dryRun) return\n const prev = state.sources[id]\n state.sources[id] = failed\n ? { fingerprint: prev?.fingerprint ?? \"\", at: new Date().toISOString(), costUsd, failures: (prev?.failures ?? 0) + 1 }\n : { fingerprint: fp, at: new Date().toISOString(), costUsd }\n opts.save?.(state)\n }\n\n for (const e of candidates) {\n if (calls >= opts.max) break\n const base = { source: e.id, title: e.title, rules: [] as RuleWrite[], costUsd: 0, dropped: [] as string[] }\n const page = targetPage(hub, e)\n if (!page) { if (opts.only.length) run.outcomes.push({ ...base, status: \"no-page\" }); continue }\n const ctx = rulesContext(g, e, page, readEntries)\n let fp = rulesFingerprint(page)\n if (!opts.force && state.sources[e.id]?.fingerprint === fp) {\n if (opts.only.length) run.outcomes.push({ ...base, status: \"unchanged\" })\n continue\n }\n if (run.costUsd >= opts.maxCostUsd) { run.capped = true; break }\n\n calls++\n const where = `${page.agentId}/${page.article.path}`\n let reply: { text: string; costUsd: number }\n try {\n reply = await call(buildRulesPrompt(g, ctx, opts.today))\n } catch (err) {\n run.outcomes.push({ ...base, page: where, status: \"failed\", dropped: [(err as Error).message.slice(0, 200)] })\n remember(e.id, fp, 0, true)\n continue\n }\n run.costUsd += reply.costUsd\n const outcome: RulesOutcome = { ...base, page: where, status: \"no-reply\", costUsd: reply.costUsd }\n const parsed = parseEnrichReply(reply.text)\n if (!parsed) { run.outcomes.push(outcome); remember(e.id, fp, reply.costUsd); continue }\n const checked = checkRules(parsed, ctx, g)\n outcome.dropped = checked.dropped\n if (checked.rules.length === 0) {\n outcome.status = \"no-rules\"\n run.outcomes.push(outcome)\n remember(e.id, fp, reply.costUsd)\n continue\n }\n\n let failed = false\n for (const r of checked.rules) {\n const t = ruleTarget(hub, r, ctx, made, opts.today)\n if (typeof t === \"string\") { outcome.dropped.push(`${r.title}: ${t}`); continue }\n // What an earlier source stated stays when this one leaves it out.\n const statements = mergeRuleStatements(t.meta.statements ?? [], ruleStatements(r, ctx), r)\n const meta0 = withRuleStatements(t.meta, statements, opts.today)\n // A penalty the owner confirmed wins, as on the rule page itself.\n const known = knownPenalty(hub, g, r.title, t)\n const penalty = known?.confirmed || !r.penalty ? known : { value: r.penalty, source: r.source, checked_at: sourceDate(r, ctx) }\n const summary = ruleOverview(meta0.statements ?? [], penalty, page.article.meta.title)\n // A page this job did not create keeps its own Overview.\n const ours = (t.meta.tags ?? []).includes(RULES_TAG)\n const content = ours ? withOverview(t.content, summary) : withRuleSummary(t.content, summary)\n const related = [...new Set([...(t.meta.related ?? []), page.article.meta.title, ...(penalty ? [cleanTitle(`${r.title} penalty`)] : [])])]\n const sources = [...new Set([...(t.meta.sources ?? []), ...ctx.entries.filter(x => r.source.includes(x.id)).map(x => x.id)])]\n const meta = { ...meta0, related, sources }\n const write: RuleWrite = {\n title: r.title, page: `${t.agentId}/${t.path}`, created: t.created,\n deadline: (meta.statements ?? []).some(s => s.property === \"due_rule\"), penalty: !!penalty, linked: [],\n }\n if (opts.dryRun) {\n write.preview = summary\n write.linked = linkBearers(hub, r, ctx, t, true, outcome.dropped)\n outcome.rules.push(write)\n continue\n }\n const store = hub.getAgentWiki(t.agentId)\n if (!store.writeArticle(t.path, meta, content, t.meta.owner || t.agentId)) {\n outcome.dropped.push(`${r.title}: write refused`)\n failed = true\n continue\n }\n made.set(normName(r.title), { ...t, meta, content, created: false })\n if (r.penalty && !known?.confirmed) {\n const pen = penaltyPage(r, { ...t, meta }, ctx, opts.today)\n const old = store.readArticle(pen.path)\n // A penalty page someone else wrote at that path is left alone; on\n // ours, statements the owner confirmed stay.\n if (!old) store.writeArticle(pen.path, pen.meta, pen.content, pen.meta.owner)\n else if ((old.meta.tags ?? []).includes(RULES_TAG)) {\n const merged = withRuleStatements({ ...pen.meta, created: old.meta.created, statements: old.meta.statements }, pen.meta.statements ?? [], opts.today)\n store.writeArticle(pen.path, merged, pen.content, pen.meta.owner)\n } else outcome.dropped.push(`${r.title}: ${pen.path} already exists`)\n }\n write.linked = linkBearers(hub, r, ctx, { ...t, meta }, false, outcome.dropped)\n store.rebuildIndex()\n outcome.rules.push(write)\n }\n outcome.status = opts.dryRun ? \"dry-run\" : outcome.rules.length ? \"written\" : failed ? \"failed\" : \"no-rules\"\n run.outcomes.push(outcome)\n // A rule written onto the source page itself changes its text; the\n // next run must not pay to read back what this one wrote.\n const now = opts.dryRun ? null : hub.getAgentWiki(page.agentId).readArticle(page.article.path)\n if (now) fp = rulesFingerprint({ agentId: page.agentId, article: now })\n remember(e.id, fp, reply.costUsd, failed && outcome.rules.length === 0)\n }\n return run\n}\n"],"mappings":"4TAmBA,OAAS,cAAAA,OAAkB,SAC3B,OAAS,cAAAC,GAAY,aAAAC,GAAW,gBAAAC,GAAc,iBAAAC,OAAqB,KACnE,OAAS,WAAAC,MAAe,OAQjB,IAAMC,EAAW,aAEXC,EAAY,aAGZC,GAAqB,CAChC,WAAY,WAAY,SAAU,SAAU,WAAY,UAAW,QAAS,YAAa,WAAY,eACrG,cAAe,SAAU,aAAc,aAAc,aACrD,iBAAY,cAAe,WAAS,aAAW,SAAU,aAAc,iBAAe,aACtF,iCAAS,qBAAO,2BAAQ,iCAAS,0BACnC,EAGMC,GAAa,IAAI,IAAI,CAAC,QAAS,QAAS,SAAU,SAAU,MAAO,SAAU,UAAW,UAAW,SAAU,WAAY,QAAQ,CAAC,EAElIC,GAAe,IAAI,IAAI,CAAC,SAAU,cAAc,CAAC,EAEjDC,GAAa,IACbC,GAAc,IACdC,EAAO,CAACC,EAAWC,IAAeD,EAAE,OAASC,EAAI,GAAGD,EAAE,MAAM,EAAGC,CAAC,UAAOD,EACvEE,EAAOC,GAAwB,OAAOA,GAAM,SAAWA,EAAE,QAAQ,OAAQ,GAAG,EAAE,KAAK,EAAI,GAEvFC,EAAcJ,GAAcE,EAAIF,CAAC,EAAE,QAAQ,WAAY,EAAE,EAAE,MAAM,EAAG,GAAG,EAAE,KAAK,EAE7E,SAASK,GAAiBC,EAAkBZ,GAA4B,CAC7E,IAAMa,EAAUD,EAAM,IAAIE,GAAKA,EAAE,KAAK,EAAE,QAAQ,sBAAuB,MAAM,CAAC,EAAE,OAAO,OAAO,EAC9F,OAAO,IAAI,OAAO,uBAAuBD,EAAQ,KAAK,GAAG,KAA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Ac,CAAC,EAAGrB,EAAK,KAAK,EACpJhB,EAAM,aAAaqC,EAAI,KAAME,GAAQF,EAAI,QAASA,EAAI,KAAK,KAAK,OAC3DP,EAAQ,QAAQ,KAAK,GAAGnG,EAAE,UAAU0G,EAAI,qBAAqB,EAEtED,EAAM,OAAS1B,GAAYjB,EAAK9D,EAAGZ,EAAK,CAAE,GAAGsF,EAAG,KAAA/C,CAAK,EAAG,GAAOwE,EAAQ,OAAO,EAC9E9B,EAAM,aAAa,EACnB8B,EAAQ,MAAM,KAAKM,CAAK,EAE1BN,EAAQ,OAASd,EAAK,OAAS,UAAYc,EAAQ,MAAM,OAAS,UAAYL,EAAS,SAAW,WAClGL,EAAI,SAAS,KAAKU,CAAO,EAGzB,IAAMhC,EAAMkB,EAAK,OAAS,KAAOvB,EAAI,aAAa5G,EAAK,OAAO,EAAE,YAAYA,EAAK,QAAQ,IAAI,EACzFiH,IAAKyB,EAAK9G,GAAiB,CAAE,QAAS5B,EAAK,QAAS,QAASiH,CAAI,CAAC,GACtEwB,EAASjI,EAAE,GAAIkI,EAAIK,EAAM,QAASH,GAAUK,EAAQ,MAAM,SAAW,CAAC,EAExE,OAAOV,CACT","names":["createHash","existsSync","mkdirSync","readFileSync","writeFileSync","resolve","RULES_BY","RULES_TAG","DEFAULT_RULE_WORDS","SKIP_TYPES","BEARER_TYPES","PAGE_CHARS","ENTRY_CHARS","clip","s","n","str","v","cleanTitle","ruleWordsPattern","words","escaped","w","statesRules","page","bodyOf","ruleSources","g","only","wanted","normName","ours","e","p","rank","a","b","partiesOf","text","types","hay","linked","x","rulesContext","source","readEntries","entries","all","visible","readableAlongside","of","type","rulesFingerprint","parts","createHash","knownLine","facts","buildRulesPrompt","ctx","today","lines","en","checkRules","raw","dropped","sourceIds","known","rules","seen","item","r","title","action","id","existing","taken","clash","bearers","asPage","value","list","sourceDate","day","d","ruleStatements","checked","st","property","out","SINGLE","mergeRuleStatements","earlier","fresh","prev","stated","o","withRuleStatements","meta","statements","kept","confirmed","key","missing","ruleOverview","penalty","readFrom","one","from","line","label","sources","dates","basis","SUMMARY_HEAD","SUMMARY_END","withRuleSummary","content","summary","section","start","end","loadRulesState","wikiDir","file","resolve","existsSync","readFileSync","saveRulesState","state","mkdirSync","writeFileSync","ruleTarget","hub","made","src","again","targetPage","now","owner","store","path","slugify","penaltyPath","knownPenalty","t","fact","own","f","penaltyPage","linkBearers","dryRun","linkedTo","m","runRules","call","opts","failures","candidates","ids","run","calls","remember","fp","costUsd","failed","base","where","reply","err","outcome","parsed","parseEnrichReply","meta0","withOverview","related","write","pen","old","merged"]}
@@ -1,2 +0,0 @@
1
- import{a,b}from"./chunk-K75LFQE3.js";import"./chunk-QIJLFPWE.js";export{a as claudeCall,b as registerWikiEnrich};
2
- //# sourceMappingURL=wiki-enrich-NGPFWTVA.js.map