@autonomos/core 0.7.0 → 0.8.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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{z as e}from"zod";import{existsSync as t,lstatSync as n,readFileSync as r,readdirSync as i,statSync as a}from"node:fs";import{dirname as o,isAbsolute as s,join as c,relative as l,resolve as u,sep as d}from"node:path";import f from"js-yaml";const p=`0.7.0-alpha`,m=`.autonomos`,h=`manifest.json`,g=`PROTOCOL.md`,_=`TASKS.md`,v=`AGENT.md`,ee=`worklogs`,te=`specs`,y=`decisions`,b=`archive`,x=e.object({workflowsDir:e.string().optional(),targetDir:e.string().optional(),skillsDir:e.string().optional(),commandsDir:e.string().optional(),globalTargetDir:e.string().optional(),fileExtension:e.string()}).refine(e=>!!e.workflowsDir||!!e.targetDir||!!e.skillsDir,{message:"At least one of `workflowsDir`, `targetDir`, or `skillsDir` must be defined"}),S=e.object({name:e.string().min(1),preferred:e.boolean(),installer:x}),C=e.object({platforms:e.record(e.string(),S)}),w=e.object({protocolVersion:e.string().describe(`Version of the Agent Protocol specification`),cliVersion:e.string().describe(`Version of the CLI that last updated this project`),initializedAt:e.string().datetime().describe(`ISO timestamp of project initialization`),lastUpdated:e.string().datetime().describe(`ISO timestamp of last protocol update`)}),T=[`🔴 Critical`,`🟠 High`,`🔵 Medium`,`⚪ Low`],E=[`S`,`M`,`L`,`XL`];function D(e=`Project`){return`---
1
+ import{z as e}from"zod";import{existsSync as t,lstatSync as n,readFileSync as r,readdirSync as i,statSync as a}from"node:fs";import{dirname as o,isAbsolute as s,join as c,posix as l,relative as u,resolve as d,sep as f}from"node:path";import p from"js-yaml";const m=`0.8.0-alpha`,h=`.autonomos`,g=`manifest.json`,ee=`PROTOCOL.md`,_=`TASKS.md`,v=`AGENT.md`,y=`worklogs`,te=`specs`,ne=`decisions`,b=`archive`,re=2,x=`ISSUES.md`,ie=`closed`,ae=`worklogs-format-1`,oe=`README.md`,S={rootAgentBytes:8e3,localAgentBytes:4e3,tasksBytes:16e3,issuesBytes:24e3,taskEntryChars:300,worklogBytes:2500},C=e.object({workflowsDir:e.string().optional(),targetDir:e.string().optional(),skillsDir:e.string().optional(),commandsDir:e.string().optional(),promptsDir:e.string().optional(),globalTargetDir:e.string().optional(),fileExtension:e.string(),_note:e.string().optional()}).refine(e=>!!e.workflowsDir||!!e.targetDir||!!e.skillsDir||!!e.commandsDir||!!e.promptsDir,{message:"At least one of `workflowsDir`, `targetDir`, `skillsDir`, `commandsDir`, or `promptsDir` must be defined"}),w=e.object({name:e.string().min(1),preferred:e.boolean(),installer:C}),T=e.object({platforms:e.record(e.string(),w)}),E=e.object({protocolVersion:e.string().describe(`Version of the Agent Protocol specification`),cliVersion:e.string().describe(`Version of the CLI that last updated this project`),initializedAt:e.string().datetime().describe(`ISO timestamp of project initialization`),lastUpdated:e.string().datetime().describe(`ISO timestamp of last protocol update`),artifactFormat:e.number().int().positive().optional().describe(`Layout version of project-owned records; absent means 1`)}),se=[`🔴 Critical`,`🟠 High`,`🔵 Medium`,`⚪ Low`],ce=[`S`,`M`,`L`,`XL`];function D(e=`Project`){return`---
2
2
  name: "${e}"
3
3
  type: "project"
4
4
  status: "active"
@@ -35,40 +35,42 @@ status: "active"
35
35
  - **Stack:** *(frameworks, libs specific to this module)*
36
36
  - **Conventions:** *(naming, exports, test patterns)*
37
37
  - **Constraints:** *(known issues, tech debt)*
38
- `}const ne=D(),re=O(`module`);function k(e){let t=new Date().toISOString();return{protocolVersion:p,cliVersion:e,initializedAt:t,lastUpdated:t}}function A(e){return JSON.stringify(e,null,4)+`
39
- `}function j(e){let t=JSON.parse(e);return w.parse(t)}const M=`# AUTONOMOS PROTOCOL (v${p})
38
+ `}const le=D(),ue=O(`module`);function de(e){let t=new Date().toISOString();return{protocolVersion:m,cliVersion:e,initializedAt:t,lastUpdated:t,artifactFormat:2}}function fe(e){return JSON.stringify(e,null,4)+`
39
+ `}function pe(e){let t=JSON.parse(e);return E.parse(t)}function me(e){return e.artifactFormat??1}const k=`# AUTONOMOS PROTOCOL (v${m})
40
40
 
41
41
  > This file defines the project's AI workflow contract. The workflows execute it. Do not duplicate workflow steps here.
42
42
 
43
43
  ## Quick Reference
44
44
 
45
- | Action | How |
46
- | -------------------------------- | ---------------------------------------------------------------------------------- |
47
- | Start a session | Read the \`/session\` workflow |
48
- | Start a task | Read the \`/task\` workflow |
49
- | Triage a problem or proposal | Read the optional \`/issue\` workflow |
50
- | Adopt existing project knowledge | Read the optional \`/adopt\` workflow |
51
- | Reconcile drift and archive history | Read the \`/reconcile\` workflow |
52
- | Design or critique a surface | Read the optional \`/design\` workflow |
53
- | End a session | Read the \`/crystallize\` workflow |
54
- | Get context | Read root \`AGENT.md\`, then only the selected scope's ancestor chain |
55
- | Resolve objective | Explicit user request first; otherwise resume \`[/]\` or pick highest-priority \`[ ]\` |
56
- | Log session work | Create \`.autonomos/worklogs/YYYY-MM-DD-[TASK_ID].md\` |
45
+ | Action | How |
46
+ | ----------------------------------- | ---------------------------------------------------------------------------------- |
47
+ | Start a session | Read the \`/session\` workflow |
48
+ | Start a task | Read the \`/task\` workflow |
49
+ | Triage a problem or proposal | Read the optional \`/issue\` workflow |
50
+ | Adopt existing project knowledge | Read the optional \`/adopt\` workflow |
51
+ | Reconcile drift and archive history | Read the \`/reconcile\` workflow |
52
+ | Design or critique a surface | Read the optional \`/design\` workflow |
53
+ | End a session | Read the \`/crystallize\` workflow |
54
+ | Get context | Read root \`AGENT.md\`, then only the selected scope's ancestor chain |
55
+ | Resolve objective | Explicit user request first; otherwise resume \`[/]\` or pick highest-priority \`[ ]\` |
56
+ | Log session work | Create \`.autonomos/worklogs/YYYY-MM-DD-[TASK_ID].md\` (shape in \`/crystallize\`) |
57
+ | Close finished work | \`autonomos close <ID>\` → \`.autonomos/archive/closed/\` |
58
+ | Check context budgets | \`autonomos status\`; upgrade old records with \`autonomos migrate\` |
57
59
 
58
60
  ## File Map
59
61
 
60
- | File | Location | Role |
61
- | --------------- | -------------------------- | ------------------------------------------------- |
62
- | \`AGENT.md\` | Root + any subdirectory | Durable guidance for its directory scope |
63
- | \`TASKS.md\` | \`.autonomos/TASKS.md\` | Current task state and optional Current direction |
64
- | \`ISSUES.md\` | \`.autonomos/ISSUES.md\` | Optional problem, proposal, and question intake |
65
- | \`worklogs/\` | \`.autonomos/worklogs/\` | Historical session evidence, not current guidance |
66
- | \`archive/\` | \`.autonomos/archive/\` | Optional history, searched only when justified |
67
- | \`specs/\` | \`.autonomos/specs/\` | Optional project-owned normative target state |
68
- | \`decisions/\` | \`.autonomos/decisions/\` | Optional project-owned decision records (ADRs) |
69
- | \`DESIGN.md\` | Root or target scope | Optional project-owned visual/interaction direction |
70
- | \`PROTOCOL.md\` | \`.autonomos/PROTOCOL.md\` | This file — read-only reference |
71
- | \`manifest.json\` | \`.autonomos/manifest.json\` | Protocol version metadata |
62
+ | File | Location | Role |
63
+ | --------------- | -------------------------- | --------------------------------------------------------------------- |
64
+ | \`AGENT.md\` | Root + any subdirectory | Durable guidance for its directory scope |
65
+ | \`TASKS.md\` | \`.autonomos/TASKS.md\` | Open tasks and optional Current direction |
66
+ | \`ISSUES.md\` | \`.autonomos/ISSUES.md\` | Optional intake: open and accepted issues only |
67
+ | \`worklogs/\` | \`.autonomos/worklogs/\` | Historical session evidence, not current guidance |
68
+ | \`archive/\` | \`.autonomos/archive/\` | History (\`closed/\` registries, batches), searched only when justified |
69
+ | \`specs/\` | \`.autonomos/specs/\` | Optional project-owned normative target state |
70
+ | \`decisions/\` | \`.autonomos/decisions/\` | Optional project-owned decision records (ADRs) |
71
+ | \`DESIGN.md\` | Root or target scope | Optional project-owned visual/interaction direction |
72
+ | \`PROTOCOL.md\` | \`.autonomos/PROTOCOL.md\` | This file — read-only reference |
73
+ | \`manifest.json\` | \`.autonomos/manifest.json\` | Protocol version and artifact format |
72
74
 
73
75
  ## Design Direction Boundary
74
76
 
@@ -148,36 +150,26 @@ Only user/project governance accepts a specification or decision as normative. A
148
150
 
149
151
  ## Current Context and Archival Lifecycle
150
152
 
151
- - Current context must support ordinary work without archives. Keep applicable guidance, accepted requirements/decisions, unresolved work, dependencies and necessary next actions discoverable. Acceptance is independent of implementation; dated temporary directives remain active until lifted or their stated end condition is met.
152
- - A completed task or resolved/declined issue is an archival candidate only when its own scope is settled and still-needed outcomes/constraints/references are retained in current context. Explicitly abandoned work may be archived with its reason, without claiming it was completed. A completed child does not satisfy unmet parent acceptance criteria.
153
- - Record new task completion dates as \`Completed: YYYY-MM-DD\`; do not infer missing old dates from worklog filenames. Age, a checkbox, absent code or a newer statement alone is not proof of obsolescence.
154
- - Group archival at coherent completed-work boundaries, not per task or calendar interval. No Sprint object or scheduled maintenance is required. Correct certain in-scope drift proactively during normal work; use \`/reconcile\` for investigation, consolidation and archival.
155
- - Before moving history, consolidate current knowledge in its existing narrowest home. Optional \`Current direction\` in \`TASKS.md\` explains present aims, recent consequential outcomes and next work; rewrite it rather than append chronology. Keep progress out of \`AGENT.md\`.
156
- - Create project-owned \`.autonomos/archive/README.md\` and meaningful batch directories on first use only. A batch can contain \`TASKS.md\`, \`ISSUES.md\`, \`worklogs/\` and provenance for retired guidance. Group/split batches by useful scope; there is no fixed age, size or mandatory per-record schema.
157
- - Archive means move, not delete or rewrite conclusions. Preserve historical record content, identifiers and provenance; repair relative paths when necessary. Preserve original mixed-source text when retiring only some claims. Applicable specs/decisions stay current independently of execution records. Extraction into new normative artifacts still uses \`/adopt\`.
158
- - The archive index maps batch topics to records, not a second task journal. Search by ID or subject only when a specific question requires history; neither archives nor their entire index are routine startup context. Keep only necessary dependency/outcome pointers in current records, not a permanent stub for every completed task.
159
- - Archived task and issue IDs remain reserved. Before assigning an ID, search current and archived registries. With a CLI, \`readTaskRegistry(root, { history: true })\` exposes task references and duplicates; plain Markdown search works without it.
160
- - Verify exact source text before edits, retained current knowledge, IDs and resolvable references after moves. Do not confuse tool annotations with file content or historical validation with a current observation. Re-read shared files before writing and preserve unrelated concurrent changes. Stop when a second pass yields no deterministic correction.
161
- - \`autonomos status\` summarizes the current task registry; \`--history\` adds separate archived counts and read/collision diagnostics. Archived means historical, not necessarily completed. History uses batch \`TASKS.md\` files, not arbitrary worklog checklists.
162
- - Archives are project-owned, like specs and decisions. Initialization, updates and integrity checks neither create empty archives nor overwrite, relocate or judge their contents. Installing a new protocol performs no automatic cleanup. Version-control policy stays project-owned; Git is not required for archival or retrieval.
163
-
164
- Example (only files needed by a batch are created):
165
-
166
- \`\`\`text
167
- .autonomos/
168
- TASKS.md
169
- ISSUES.md
170
- archive/
171
- README.md
172
- realtime-experiment-retirement/
173
- TASKS.md
174
- ISSUES.md
175
- worklogs/
176
- \`\`\`
153
+ - Current context must support ordinary work without archives, and its size follows open work, not project age. Keep applicable guidance, accepted requirements/decisions, unresolved work, dependencies and necessary next actions discoverable. Acceptance is independent of implementation; dated temporary directives remain active until lifted or their stated end condition is met.
154
+ - \`TASKS.md\` holds \`[ ]\`, \`[/]\` and \`[!]\` tasks; \`ISSUES.md\` holds open and accepted issues. When work closes, move its record in the same session to the append-only \`.autonomos/archive/closed/TASKS.md\` or \`ISSUES.md\` (\`autonomos close <ID>\`, or by hand). Unfinished work may be closed only as abandoned, with its reason. A completed child does not satisfy unmet parent acceptance criteria; a parent with open children stays current.
155
+ - Record new task completion dates as \`Completed: YYYY-MM-DD\`; do not infer missing old dates. Age, a checkbox, absent code or a newer statement alone is not proof of obsolescence.
156
+ - Before moving history, consolidate still-needed knowledge in its existing narrowest home. Optional \`Current direction\` in \`TASKS.md\` explains present aims, recent consequential outcomes and next work; rewrite it rather than append chronology. Keep progress out of \`AGENT.md\`.
157
+ - Other history may form named batches under \`.autonomos/archive/<batch>/\` via \`/reconcile\`; create \`archive/README.md\` and batch directories on first use only. The index maps topics to records; it is not a second journal.
158
+ - Archive means move, not delete or rewrite conclusions. Preserve historical record content, identifiers and provenance; repair relative paths when necessary. Applicable specs/decisions stay current independently of execution records. Extraction into new normative artifacts still uses \`/adopt\`.
159
+ - Archived task and issue IDs remain reserved. Before assigning an ID, search current and archived registries (\`autonomos status --history\` reports duplicates).
160
+ - Verify exact source text before edits and resolvable references after moves. Re-read shared files before writing and preserve unrelated concurrent changes.
161
+
162
+ ## Context Budgets
163
+
164
+ Advisory limits reported by \`autonomos status\` (\`--strict\` makes them fail): root \`AGENT.md\` 8,000 bytes, local \`AGENT.md\` 4,000 bytes, \`TASKS.md\` 16 KB, \`ISSUES.md\` 24 KB, one task entry 300 characters, one worklog 2,500 bytes, and no closed record in current registries. Over budget, consolidate or move knowledge to its narrowest home before adding more. Root \`AGENT.md\` admits only guidance that applies to most tasks in the project.
165
+
166
+ ## Artifact Format and Migration
167
+
168
+ \`manifest.json\` records \`artifactFormat\` (absent means 1); this protocol defines format 2. Installing a new protocol performs no automatic cleanup: \`autonomos update\` only replaces managed artifacts. \`autonomos migrate\` is the explicit, content-preserving upgrade: it closes finished records, moves pre-format-2 worklogs to \`.autonomos/archive/worklogs-format-1/\` so they stop serving as examples, repairs references and records the format. Run it with \`--dry-run\` first on a clean working tree, then resolve the remaining \`status\` findings with \`/reconcile\`.
177
169
 
178
170
  ## Task Format
179
171
 
180
- \`- [Status] **[ID]** Title \\\`Priority\\\` \\\`Complexity\\\`\`
172
+ One line per task: \`\` - [Status] **[ID]** Title \`Priority\` \`Complexity\` \`\` plus, when useful, \`Completed: YYYY-MM-DD\`, a short note and links to its issue or worklog. Evidence, measurements and progress belong in the worklog, not the task entry.
181
173
 
182
174
  | Status | Priority | Complexity |
183
175
  | ----------------- | ------------- | ---------- |
@@ -191,7 +183,7 @@ Example (only files needed by a batch are created):
191
183
  - **Language:** English unless AGENT.md says otherwise.
192
184
  - **Tone:** Technical, concise, fact-based.
193
185
  - **Continuity:** Refer to previous work as "we" or "the project".
194
- `,N=M,P=`# PROJECT TASKS & ROADMAP
186
+ `,he=k,ge=`# PROJECT TASKS & ROADMAP
195
187
 
196
188
  > **LEGEND**
197
189
  > **Priority:** [🔴 Critical] [🟠 High] [🔵 Medium] [⚪ Low]
@@ -205,28 +197,31 @@ Example (only files needed by a batch are created):
205
197
  ## 🔮 Backlog
206
198
 
207
199
  *(Add future tasks here)*
208
- `;function F(e){let t=e.date??new Date().toISOString().split(`T`)[0];return`# WORKLOG: [${e.taskId}] ${e.taskName}
209
- **Date:** ${t}
210
- **Agent Status:** [${e.status}]
211
-
212
- ## 📝 Description
213
- ${e.description}
214
-
215
- ## 🛠 Technical Details
216
- - **Files Modified:**
217
- ${e.filesModified.map(e=>` - ${e}`).join(`
218
- `)}
219
- - **Key Decisions:**
220
- ${e.decisions.map(e=>` - ${e}`).join(`
221
- `)}
222
- - **Challenges:**
223
- ${e.challenges.map(e=>` - ${e}`).join(`
224
- `)}
225
-
226
- ## ⏭ Next Steps / Context for Successor
227
- ${e.nextSteps.map(e=>`- ${e}`).join(`
228
- `)}
229
- `}function I(e){switch(e){case`DONE`:return`Complete`;case`BLOCKED`:return`Blocked`;default:return`Partial`}}function L(e,n=process.cwd()){let r=u(n),i=R(e,r),a=l(r,i);if(a.startsWith(`..`)||s(a))throw Error(`Target "${e}" is outside the project root "${r}". findAncestorAgents only handles paths within the project.`);let d=z(V(i)?i:o(i),r),f=[];for(let e of d){let n=c(e,v);t(n)&&f.push({dir:e,path:n,relativeDir:B(e,r)})}return f}function R(e,t){return s(e)?e:c(t,e)}function z(e,t){let n=l(t,e);if(n===``||n===`.`)return[t];let r=n.split(d).filter(e=>e!==``&&e!==`.`),i=[t],a=t;for(let e of r)a=c(a,e),i.push(a);return i}function B(e,t){let n=l(t,e);return n===``?`.`:n}function V(e){try{return a(e).isDirectory()}catch{return!1}}var H=class{static parse(e){let t=e,n={},r=e.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(r)try{n=f.load(r[1]),t=e.slice(r[0].length).trim()}catch(e){console.error(`Failed to parse Agent frontmatter:`,e)}let i=t.split(/\r?\n/),a=[],o=n.name??`Unknown Agent`,s=null,c=[];for(let e of i){if(e.startsWith(`# `)&&!n.name){let t=e.replace(`# `,``).trim();o=t.toUpperCase().startsWith(`AGENT CONTEXT:`)?t.slice(14).replace(/^[:\s-]+/,``).trim():t;continue}if(e.startsWith(`## `)){s&&(s.content=c.join(`
200
+ `,A=e=>e?.length?`
201
+ `+e.map(e=>`- ${e}`).join(`
202
+ `):` none`;function _e(e){return`# [${e.taskId}] ${e.title}
203
+
204
+ Outcome: ${e.outcome}
205
+ Decisions:${A(e.decisions)}
206
+ Validation:${A(e.validation)}
207
+ Open:${A(e.open)}
208
+ `}function ve(e){switch(e){case`DONE`:return`Complete`;case`BLOCKED`:return`Blocked`;default:return`Partial`}}function ye(e,n=process.cwd()){let r=d(n),i=be(e,r),a=u(r,i);if(a.startsWith(`..`)||s(a))throw Error(`Target "${e}" is outside the project root "${r}". findAncestorAgents only handles paths within the project.`);let l=xe(M(i)?i:o(i),r),f=[];for(let e of l){let n=c(e,v);t(n)&&f.push({dir:e,path:n,relativeDir:j(e,r)})}return f}function be(e,t){return s(e)?e:c(t,e)}function xe(e,t){let n=u(t,e);if(n===``||n===`.`)return[t];let r=n.split(f).filter(e=>e!==``&&e!==`.`),i=[t],a=t;for(let e of r)a=c(a,e),i.push(a);return i}function j(e,t){let n=u(t,e);return n===``?`.`:n}function M(e){try{return a(e).isDirectory()}catch{return!1}}var Se=class{static parse(e){let t=e,n={},r=e.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(r)try{n=p.load(r[1]),t=e.slice(r[0].length).trim()}catch(e){console.error(`Failed to parse Agent frontmatter:`,e)}let i=t.split(/\r?\n/),a=[],o=n.name??`Unknown Agent`,s=null,c=[];for(let e of i){if(e.startsWith(`# `)&&!n.name){let t=e.replace(`# `,``).trim();o=t.toUpperCase().startsWith(`AGENT CONTEXT:`)?t.slice(14).replace(/^[:\s-]+/,``).trim():t;continue}if(e.startsWith(`## `)){s&&(s.content=c.join(`
230
209
  `).trim(),a.push(s)),s={title:e.replace(`## `,``).trim(),content:``},c=[];continue}s&&c.push(e)}return s&&(s.content=c.join(`
231
- `).trim(),a.push(s)),{title:o,sections:a,metadata:n}}};const U=[m,`.git`];function W(e){if(!e)return null;let n=u(e);for(;;){if(U.some(e=>t(c(n,e))))return n;let e=o(n);if(e===n)return null;n=e}}function G(e,t){return!e||!t?!1:u(e)===u(t)}function K(e,t){let n=l(t,e);return n===``||n===`.`?`.`:n.startsWith(`..${d}`)||n===`..`||s(n)?u(e):n}var q=class{static references(e){let t=[],n;for(let[r,i]of e.split(/\r?\n/).entries()){let e=i.match(/^\s{0,3}(`{3,}|~{3,})/);if(e?.[1]){n?e[1][0]===n[0]&&e[1].length>=n.length&&!i.slice(e[0].length).trim()&&(n=void 0):n=e[1];continue}if(n)continue;let a=i.match(/^\s*- \[([ x/!])\] \*\*\[([^\]]+)\]\*\*/);a?.[1]&&a[2]?.trim()&&t.push({id:a[2].trim(),status:this.mapStatus(a[1]),line:r+1})}return t}static parse(e){let t=[],n=e.split(/\r?\n/),r=/- \[([ x/!])\] \*\*\[(.+)\]\*\* (.+) `Priority: (.+)` `Complexity: (.+)`/;for(let e of n){let n=e.match(r);if(n){let[,e=` `,r=``,i=``,a=``,o=``]=n;t.push({id:r,title:i.trim(),priority:a,complexity:o,status:this.mapStatus(e)})}}return t}static mapStatus(e){switch(e){case` `:return`TODO`;case`/`:return`IN_PROGRESS`;case`x`:return`DONE`;case`!`:return`BLOCKED`;default:return`TODO`}}};function J(e,t={}){let a={current:[],archived:[],duplicateIds:[],warnings:[],complete:!0};function o(t,n){a.complete=!1,a.warnings.push(`${l(e,t)}: ${n}`)}function s(t,i){try{if(!n(t).isFile()){o(t,`Expected a regular task registry; symbolic links are not followed`);return}i.push(...q.references(r(t,`utf8`)).map(n=>({...n,path:l(e,t)})))}catch(e){o(t,e instanceof Error?e.message:String(e))}}function u(e,t=!1){try{if(!n(e).isDirectory()){o(e,`Expected an archive directory; symbolic links are not followed`);return}for(let t of i(e,{withFileTypes:!0}).sort((e,t)=>e.name.localeCompare(t.name))){let n=c(e,t.name);t.isSymbolicLink()?o(n,`Skipped symbolic link in archive`):t.isDirectory()?u(n):t.name===`TASKS.md`&&s(n,a.archived)}}catch(n){if(t&&n.code===`ENOENT`)return;o(e,n instanceof Error?n.message:String(n))}}let d=c(e,m);try{if(!n(d).isDirectory())return o(d,`Expected a regular project directory; symbolic links are not followed`),a}catch(e){return e.code!==`ENOENT`&&o(d,e instanceof Error?e.message:String(e)),a}let f=c(d,_);try{n(f),s(f,a.current)}catch(e){e.code!==`ENOENT`&&o(f,e instanceof Error?e.message:String(e))}t.history&&u(c(e,m,b),!0);let p=new Set,h=new Set;for(let e of[...a.current,...a.archived])p.has(e.id)&&h.add(e.id),p.add(e.id);return a.duplicateIds=[...h].sort(),a}const Y=C.parse({$schema:`./harness-codes.schema.json`,_comment:"Autonomos harness codes. Each entry tells `autonomos init` where to write the protocol workflow files. The shape is intentionally minimal: only what the installer needs. To add a new harness, add an entry here. To remove one, delete it. The schema is enforced at load time by Zod (see schemas/harness-codes.ts).",platforms:{cline:{name:`Cline`,preferred:!0,installer:{workflowsDir:`.clinerules/workflows`,fileExtension:`.md`,_note:"In Cline, a single .md file in .clinerules/workflows/ acts as both a workflow (auto-discovered via the frontmatter `description` field) and a slash command (invoked via /<name>)."}},"claude-code":{name:`Claude Code`,preferred:!0,installer:{workflowsDir:`.claude/skills`,commandsDir:`.claude/commands`,fileExtension:`.md`}},codex:{name:`Codex`,preferred:!0,installer:{workflowsDir:`.agents/skills`,fileExtension:`.md`,globalTargetDir:`~/.codex/skills`,_note:`OpenAI Codex. Uses the cross-tool .agents/skills/ standard.`}},antigravity:{name:`Antigravity`,preferred:!0,installer:{workflowsDir:`.agent/workflows`,fileExtension:`.md`,globalTargetDir:`~/.gemini/antigravity/skills`,_note:"Google Antigravity. Uses `.agent/workflows/` (not `.agent/skills/`). Singular `.agent/` (NOT the cross-tool `.agents/` standard). Cannot be deduplicated with the others."}},opencode:{name:`OpenCode`,preferred:!0,installer:{workflowsDir:`.agents/skills`,commandsDir:`.opencode/commands`,fileExtension:`.md`}},kilocode:{name:`KiloCode`,preferred:!0,installer:{workflowsDir:`.agents/skills`,fileExtension:`.md`,globalTargetDir:`~/.kilocode/skills`}}}});function X(e){let t=Y.platforms[e];if(!t){let t=Object.keys(Y.platforms).join(`, `);throw Error(`Unknown harness: "${e}". Known harnesses: ${t}`)}return t}function Z(){return Object.entries(Y.platforms).map(([e,t])=>({id:e,harness:t}))}function ie(){return Z().filter(({harness:e})=>e.preferred)}function ae(e,t=`.`){let n=new Map;for(let r of e){let{installer:e}=X(r);oe(n,e,r,t)}return Array.from(n.values())}function oe(e,t,n,r){let i=t.fileExtension;t.workflowsDir?Q(e,$(r,t.workflowsDir),i,n):t.targetDir?Q(e,$(r,t.targetDir),i,n):t.skillsDir&&Q(e,$(r,t.skillsDir),i,n),t.commandsDir&&Q(e,$(r,t.commandsDir),i,n)}function Q(e,t,n,r){let i=e.get(t);i?i.usedBy.includes(r)||i.usedBy.push(r):e.set(t,{path:t,fileExtension:n,usedBy:[r]})}function $(e,t){return e===`.`||e===``?t:t.startsWith(`/`)?`${e}${t}`:`${e}/${t}`}function se(){return Y}export{v as AGENT_FILE,ne as AGENT_TEMPLATE,b as ARCHIVE_DIR,m as AUTONOMOS_DIR,H as AgentParser,E as COMPLEXITIES,y as DECISIONS_DIR,C as HarnessCodesSchema,S as HarnessSchema,x as InstallerSchema,re as LOCAL_AGENT_TEMPLATE,h as MANIFEST_FILE,w as ManifestSchema,T as PRIORITIES,g as PROTOCOL_FILE,M as PROTOCOL_TEMPLATE,N as PROTOCOL_TEMPLATE_V2026_1,p as PROTOCOL_VERSION,te as SPECS_DIR,_ as TASKS_FILE,P as TASKS_TEMPLATE,q as TaskParser,ee as WORKLOGS_DIR,k as createManifest,K as displayRelative,L as findAncestorAgents,W as findProjectRoot,D as generateAgentTemplate,O as generateLocalAgentTemplate,A as generateManifestContent,F as generateWorklogContent,X as getHarness,se as getRawHarnessCodes,G as isSamePath,Z as listHarnesses,ie as listPreferredHarnesses,I as mapTaskStatusToWorklogStatus,j as parseManifest,J as readTaskRegistry,ae as resolveTargets};
210
+ `).trim(),a.push(s)),{title:o,sections:a,metadata:n}}};const Ce=[h,`.git`];function we(e){if(!e)return null;let n=d(e);for(;;){if(Ce.some(e=>t(c(n,e))))return n;let e=o(n);if(e===n)return null;n=e}}function Te(e,t){return!e||!t?!1:d(e)===d(t)}function Ee(e,t){let n=u(t,e);return n===``||n===`.`?`.`:n.startsWith(`..${f}`)||n===`..`||s(n)?d(e):n}var N=class{static references(e){let t=[],n;for(let[r,i]of e.split(/\r?\n/).entries()){let e=i.match(/^\s{0,3}(`{3,}|~{3,})/);if(e?.[1]){n?e[1][0]===n[0]&&e[1].length>=n.length&&!i.slice(e[0].length).trim()&&(n=void 0):n=e[1];continue}if(n)continue;let a=i.match(/^\s*- \[([ x/!])\] \*\*\[([^\]]+)\]\*\*/);a?.[1]&&a[2]?.trim()&&t.push({id:a[2].trim(),status:this.mapStatus(a[1]),line:r+1})}return t}static parse(e){let t=[],n=e.split(/\r?\n/),r=/- \[([ x/!])\] \*\*\[(.+)\]\*\* (.+) `Priority: (.+)` `Complexity: (.+)`/;for(let e of n){let n=e.match(r);if(n){let[,e=` `,r=``,i=``,a=``,o=``]=n;t.push({id:r,title:i.trim(),priority:a,complexity:o,status:this.mapStatus(e)})}}return t}static mapStatus(e){switch(e){case` `:return`TODO`;case`/`:return`IN_PROGRESS`;case`x`:return`DONE`;case`!`:return`BLOCKED`;default:return`TODO`}}};function De(e,t={}){let a={current:[],archived:[],duplicateIds:[],warnings:[],complete:!0};function o(t,n){a.complete=!1,a.warnings.push(`${u(e,t)}: ${n}`)}function s(t,i){try{if(!n(t).isFile()){o(t,`Expected a regular task registry; symbolic links are not followed`);return}i.push(...N.references(r(t,`utf8`)).map(n=>({...n,path:u(e,t)})))}catch(e){o(t,e instanceof Error?e.message:String(e))}}function l(e,t=!1){try{if(!n(e).isDirectory()){o(e,`Expected an archive directory; symbolic links are not followed`);return}for(let t of i(e,{withFileTypes:!0}).sort((e,t)=>e.name.localeCompare(t.name))){let n=c(e,t.name);t.isSymbolicLink()?o(n,`Skipped symbolic link in archive`):t.isDirectory()?l(n):t.name===`TASKS.md`&&s(n,a.archived)}}catch(n){if(t&&n.code===`ENOENT`)return;o(e,n instanceof Error?n.message:String(n))}}let d=c(e,h);try{if(!n(d).isDirectory())return o(d,`Expected a regular project directory; symbolic links are not followed`),a}catch(e){return e.code!==`ENOENT`&&o(d,e instanceof Error?e.message:String(e)),a}let f=c(d,_);try{n(f),s(f,a.current)}catch(e){e.code!==`ENOENT`&&o(f,e instanceof Error?e.message:String(e))}t.history&&l(c(e,h,b),!0);let p=new Set,m=new Set;for(let e of[...a.current,...a.archived])p.has(e.id)&&m.add(e.id),p.add(e.id);return a.duplicateIds=[...m].sort(),a}const P=T.parse({$schema:`./harness-codes.schema.json`,_comment:"Autonomos harness codes. Each entry tells `autonomos init` where to write the protocol workflow files. The shape is intentionally minimal: only what the installer needs. To add a new harness, add an entry here. To remove one, delete it. The schema is enforced at load time by Zod (see schemas/harness-codes.ts).",platforms:{cline:{name:`Cline`,preferred:!0,installer:{workflowsDir:`.clinerules/workflows`,fileExtension:`.md`,_note:"In Cline, a single .md file in .clinerules/workflows/ acts as both a workflow (auto-discovered via the frontmatter `description` field) and a slash command (invoked via /<name>)."}},"claude-code":{name:`Claude Code`,preferred:!0,installer:{commandsDir:`.claude/commands`,skillsDir:`.agents/skills`,fileExtension:`.md`}},codex:{name:`Codex`,preferred:!0,installer:{promptsDir:`.codex/prompts`,skillsDir:`.agents/skills`,fileExtension:`.md`,globalTargetDir:`~/.codex/prompts`,_note:`OpenAI Codex CLI. Slash commands live in .codex/prompts/, skills live in the cross-tool .agents/skills/ standard.`}},antigravity:{name:`Antigravity`,preferred:!0,installer:{workflowsDir:`.agents/workflows`,skillsDir:`.agents/skills`,fileExtension:`.md`,globalTargetDir:`~/.gemini/config/workflows`,_note:`Google Antigravity. Workflows live in .agents/workflows/, skills live in the cross-tool .agents/skills/ standard.`}},opencode:{name:`OpenCode`,preferred:!0,installer:{commandsDir:`.opencode/commands`,skillsDir:`.agents/skills`,fileExtension:`.md`}},kilocode:{name:`KiloCode`,preferred:!0,installer:{workflowsDir:`.agents/workflows`,skillsDir:`.agents/skills`,fileExtension:`.md`,globalTargetDir:`~/.kilocode/skills`}}}});function F(e){let t=P.platforms[e];if(!t){let t=Object.keys(P.platforms).join(`, `);throw Error(`Unknown harness: "${e}". Known harnesses: ${t}`)}return t}function I(){return Object.entries(P.platforms).map(([e,t])=>({id:e,harness:t}))}function Oe(){return I().filter(({harness:e})=>e.preferred)}function ke(e,t=`.`){let n=new Map;for(let r of e){let{installer:e}=F(r);Ae(n,e,r,t)}return Array.from(n.values())}function Ae(e,t,n,r){let i=t.fileExtension;t.workflowsDir&&L(e,R(r,t.workflowsDir),i,`flat`,n),t.commandsDir&&L(e,R(r,t.commandsDir),i,`flat`,n),t.promptsDir&&L(e,R(r,t.promptsDir),i,`flat`,n),t.targetDir&&L(e,R(r,t.targetDir),i,`flat`,n),t.skillsDir&&L(e,R(r,t.skillsDir),i,`skill`,n)}function L(e,t,n,r,i){let a=e.get(t);a?a.usedBy.includes(i)||a.usedBy.push(i):e.set(t,{path:t,fileExtension:n,kind:r,usedBy:[i]})}function R(e,t){return e===`.`||e===``?t:t.startsWith(`/`)?`${e}${t}`:`${e}/${t}`}function je(){return P}const Me=/^\s*- \[([ x/!])\] \*\*\[([^\]]+)\]\*\*/,z=/^(#{1,6})[ \t]+(\S.*)?$/,Ne=/^\s{0,3}(`{3,}|~{3,})/,Pe=/^##\s+\[([^\]]+)\]/,Fe=/^\s*[-*]\s*(?:\*\*)?status:?(?:\*\*)?:?[ \t]*(?:\*\*)?([a-z-]+)/i,B=[`resolved`,`declined`,`closed`,`superseded`,`rejected`];function V(e){return e.split(/\r?\n/)}function H(e){let t=[],n;for(let r of e){let e=r.match(Ne);if(e?.[1]){if(!n){n=e[1],t.push(!0);continue}if(e[1][0]===n[0]&&e[1].length>=n.length&&!r.slice(e[0].length).trim()){n=void 0,t.push(!0);continue}}t.push(n!==void 0)}return t}function U(e){return(e.match(/^\s*/)?.[0]??``).replace(/\t/g,` `).length}function W(e){let t=V(e),n=H(t),r=[],i=[];for(let e=0;e<t.length;e++){let a=t[e]??``;if(n[e])continue;let o=a.match(z);if(o?.[1]){let e=o[1].length;for(;i.length&&(i.at(-1)?.level??0)>=e;)i.pop();i.push({level:e,text:(o[2]??``).trim()});continue}let s=a.match(Me);if(!s)continue;let c=U(a),l=e+1,u=e+1;for(;l<t.length;){let e=t[l]??``;if(!n[l]&&e.trim()===``){l++;continue}if(n[l]&&!n[l-1]&&U(e)<=c||!n[l]&&U(e)<=c||!n[l]&&z.test(e))break;l++,u=l}r.push({id:(s[2]??``).trim(),status:s[1]??` `,start:e,end:u,headings:i.filter(e=>e.level>1).map(e=>e.text),text:t.slice(e,u).join(`
211
+ `)})}return r}function G(e){let t=V(e),n=H(t),r=[];for(let e=0;e<t.length;e++)!n[e]&&/^#{1,2}\s/.test(t[e]??``)&&r.push(e);let i=[];for(let[e,n]of r.entries()){let a=(t[n]??``).match(Pe)?.[1]?.trim();if(!a)continue;let o=r[e+1]??t.length;for(;o>n+1&&(t[o-1]??``).trim()===``;)o--;let s=t.slice(n,o),c=``;for(let e of s){let t=e.match(Fe);if(t?.[1]){c=t[1].toLowerCase();break}}i.push({id:a,status:c,start:n,end:o,text:s.join(`
212
+ `)})}return i}function K(e){return B.includes(e.toLowerCase())}function Ie(e,t){return t.some(t=>t.start>e.start&&t.start<e.end&&t.status!==`x`)}function q(e,t){let n=V(e),r=H(n),i=new Set;for(let e of t)for(let t=e.start;t<e.end;t++)i.add(t);let a=(e,t)=>t?0:e.match(z)?.[1]?.length??0,o=new Set;for(let e=0;e<n.length;e++){let t=a(n[e]??``,r[e]);if(!(t<2))for(let s=e+1;s<n.length;s++){let c=a(n[s]??``,r[s]);if(c&&c<=t)break;if(i.has(s)){o.add(e);break}}}let s=n.map((e,t)=>({text:e,index:t})).filter(e=>!i.has(e.index));for(let e=!0;e;){e=!1;let t=H(s.map(e=>e.text));for(let n=s.length-1;n>=0;n--){let r=s[n];if(!r||!o.has(r.index))continue;let i=a(r.text,t[n]);if(i<2)continue;let c=n+1,l=!0;for(;c<s.length;c++){let e=s[c]?.text??``,n=a(e,t[c]);if(n&&n<=i)break;if(n||e.trim()!==``){l=!1;break}}if(l){s=[...s.slice(0,n),...s.slice(c)],e=!0;break}}}let c=[];for(let{text:e}of s)e.trim()===``&&(c.at(-1)??`x`).trim()===``||c.push(e);for(;c.length&&(c.at(-1)??``).trim()===``;)c.pop();return c.join(`
213
+ `)+`
214
+ `}function Le(e,t){let n=W(e),r=[];for(let e of n)r.some(t=>e.start>=t.start&&e.start<t.end)||!t(e)||Ie(e,n)||r.push(e);return r.length?{remaining:q(e,r),moved:r}:{remaining:e,moved:r}}function Re(e,t){let n=G(e).filter(t);return n.length?{remaining:q(e,n),moved:n}:{remaining:e,moved:n}}function ze(e){let t=e.split(`
215
+ `),n=U(t[0]??``);return n?t.map(e=>U(e)>=n?e.slice(n):e).join(`
216
+ `):e}function Be(e,t){if(/Completed:\s*\d{4}-\d{2}-\d{2}/.test(e))return e;let[n=``,...r]=e.split(`
217
+ `),i=n.match(/`Complexity: [^`]+`/);return[i?n.replace(i[0],`${i[0]} \`Completed: ${t}\``):`${n} \`Completed: ${t}\``,...r].join(`
218
+ `)}function Ve(e,t,n){let[r=``,...i]=e.split(`
219
+ `);return[`${r} \`Abandoned: ${t}\` — ${n}`,...i].join(`
220
+ `)}function He(e,t,n,r){let i=`# ${t===`tasks`?`Closed tasks`:`Closed issues`}\n\n> Append-only history moved out of \`.autonomos/${t===`tasks`?`TASKS.md`:`ISSUES.md`}\`. Not startup context; search by ID.\n`,a=[e&&e.trim()?e.replace(/\s*$/,`
221
+ `):i];r&&a.push(`## ${r}\n`);let o=t===`issues`?`
222
+
223
+ `:`
224
+ `;return a.push(n.map(e=>e.replace(/\s*$/,``)).join(o)+`
225
+ `),a.join(`
226
+ `)}const Ue=new Set([`node_modules`,`dist`,`build`,`coverage`]);function J(e){return Buffer.byteLength(r(e,`utf8`))}function Y(e){return`${e.toLocaleString(`en-US`)} bytes`}function X(e){try{return n(e).isFile()?r(e,`utf8`):void 0}catch{return}}function Z(e){let t=[],n=e=>{let r;try{r=i(e,{withFileTypes:!0})}catch{return}for(let i of r)i.isFile()&&i.name===`AGENT.md`?t.push(c(e,i.name)):i.isDirectory()&&!i.name.startsWith(`.`)&&!Ue.has(i.name)&&n(c(e,i.name))};return n(e),t.sort()}function We(e,n={}){let r={...S,...n.budgets},a=[],o=c(e,h),s=t=>u(e,t),l=n.artifactFormat??1;l<2&&a.push({code:`format-outdated`,path:s(c(o,`manifest.json`)),message:`Records use artifact format ${l}; run \`autonomos migrate\` to reach format 2.`});let d=c(o,_),f=X(d);if(f!==void 0){let e=W(f),t=e.filter(e=>e.status===`x`).map(e=>e.id);t.length&&a.push({code:`closed-tasks-in-current`,path:s(d),message:`${t.length} completed task(s) still in the current registry; run \`autonomos close <ID>\`.`,items:t});let n=Buffer.byteLength(f);n>r.tasksBytes&&a.push({code:`tasks-size`,path:s(d),message:`${Y(n)} exceeds the ${Y(r.tasksBytes)} budget.`});let i=e.filter(e=>e.status!==`x`&&e.text.length>r.taskEntryChars).sort((e,t)=>t.text.length-e.text.length);i.length&&a.push({code:`task-entry-length`,path:s(d),message:`${i.length} open task entr${i.length===1?`y exceeds`:`ies exceed`} ${r.taskEntryChars} characters; keep evidence in worklogs.`,items:i.map(e=>`${e.id} (${e.text.length})`)})}let p=c(o,x),m=X(p);if(m!==void 0){let e=G(m).filter(e=>K(e.status)).map(e=>e.id);e.length&&a.push({code:`closed-issues-in-current`,path:s(p),message:`${e.length} closed issue(s) still in the current registry; run \`autonomos close <ID>\`.`,items:e});let t=Buffer.byteLength(m);t>r.issuesBytes&&a.push({code:`issues-size`,path:s(p),message:`${Y(t)} exceeds the ${Y(r.issuesBytes)} budget.`})}for(let t of Z(e)){let n=t===c(e,v),i=n?r.rootAgentBytes:r.localAgentBytes,o=J(t);o>i&&a.push({code:n?`root-agent-size`:`local-agent-size`,path:s(t),message:`${Y(o)} exceeds the ${Y(i)} budget; move scoped or incidental knowledge to a narrower AGENT.md or project documentation.`})}let g=c(o,y);if(t(g)){let e=[];for(let t of i(g,{withFileTypes:!0})){if(!t.isFile()||!t.name.endsWith(`.md`))continue;let n=J(c(g,t.name));n>r.worklogBytes&&e.push({name:t.name,bytes:n})}e.length&&(e.sort((e,t)=>t.bytes-e.bytes),a.push({code:`worklog-size`,path:s(g),message:`${e.length} worklog(s) exceed ${Y(r.worklogBytes)}; keep only outcome, decisions, validation and open items.`,items:e.map(e=>`${e.name} (${Y(e.bytes)})`)}))}return a}function Ge(e,t){return n=>n===e?t:n.startsWith(e+f)?t+n.slice(e.length):n}function Q(...e){return t=>e.reduce((e,t)=>t(e),t)}const Ke=/\]\((<[^>\n]+>|[^)\s]+)((?:\s+"[^"\n]*")?)\)/g,qe=/^(\s{0,3}\[[^\]\n]+\]:\s*)(<[^>\n]+>|\S+)/gm;function Je(e){return!!e&&!e.startsWith(`#`)&&!s(e)&&!/^[a-z][\w+.-]*:/i.test(e)}function $(e){return e.split(f).join(l.sep)}function Ye(e,t,n,r=e=>e){let i=e=>{let i=e.startsWith(`<`)&&e.endsWith(`>`),a=i?e.slice(1,-1):e;if(!Je(a))return e;let o=a.search(/[#?]/),s=o===-1?a:a.slice(0,o),c=o===-1?``:a.slice(o);if(!s)return e;let l=s;try{l=decodeURI(s)}catch{}let f=d(t,l),p=r(f);if(p===f&&t===n)return e;let m=$(u(n,p))||`.`;if(s.startsWith(`./`)&&!m.startsWith(`.`)&&(m=`./${m}`),m===$(l))return e;let h=i?m:m.replace(/ /g,`%20`);return i?`<${h}${c}>`:`${h}${c}`};return e.replace(Ke,(e,t,n)=>`](${i(t)}${n})`).replace(qe,(e,t,n)=>`${t}${i(n)}`)}function Xe(e,t,n,r){if(!e.includes(t+`/`))return e;let i=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=RegExp(`(?<![\\w./-])${i}/([^\\s)\\]>'"\`,;|]+)`,`g`);return e.replace(a,(e,t)=>{let i=t;for(;i&&!r.has(i)&&/[._*~]$/.test(i);)i=i.slice(0,-1);return r.has(i)?`${n}/${i}${t.slice(i.length)}`:e})}export{v as AGENT_FILE,le as AGENT_TEMPLATE,b as ARCHIVE_DIR,oe as ARCHIVE_INDEX_FILE,re as ARTIFACT_FORMAT,h as AUTONOMOS_DIR,Se as AgentParser,ie as CLOSED_DIR,B as CLOSED_ISSUE_STATUSES,ce as COMPLEXITIES,S as CONTEXT_BUDGETS,ne as DECISIONS_DIR,T as HarnessCodesSchema,w as HarnessSchema,x as ISSUES_FILE,C as InstallerSchema,ae as LEGACY_WORKLOGS_DIR,ue as LOCAL_AGENT_TEMPLATE,g as MANIFEST_FILE,E as ManifestSchema,se as PRIORITIES,ee as PROTOCOL_FILE,k as PROTOCOL_TEMPLATE,he as PROTOCOL_TEMPLATE_V2026_1,m as PROTOCOL_VERSION,te as SPECS_DIR,_ as TASKS_FILE,ge as TASKS_TEMPLATE,N as TaskParser,y as WORKLOGS_DIR,He as appendToClosedRegistry,We as checkContextBudgets,Q as composeMappers,de as createManifest,ze as dedentEntry,Ee as displayRelative,Re as extractIssues,Le as extractTasks,Z as findAgentFilePaths,ye as findAncestorAgents,we as findProjectRoot,D as generateAgentTemplate,O as generateLocalAgentTemplate,fe as generateManifestContent,_e as generateWorklogContent,F as getHarness,je as getRawHarnessCodes,K as isClosedIssueStatus,Te as isSamePath,I as listHarnesses,Oe as listPreferredHarnesses,me as manifestArtifactFormat,ve as mapTaskStatusToWorklogStatus,G as parseIssueEntries,pe as parseManifest,W as parseTaskEntries,Ge as prefixMapper,De as readTaskRegistry,Ye as relocateLinks,Xe as relocateRootMentions,ke as resolveTargets,Ve as stampAbandoned,Be as stampCompleted};
232
227
  //# sourceMappingURL=index.mjs.map