workspai 0.61.0 → 0.62.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.
Files changed (52) hide show
  1. package/README.md +7 -5
  2. package/contracts/workspace-intelligence/agent-bootstrap-receipt.v1.json +31 -3
  3. package/contracts/workspace-intelligence/agent-customization-pack-report.v1.json +5 -1
  4. package/contracts/workspace-intelligence/agent-reports-index.v1.json +5 -1
  5. package/contracts/workspace-intelligence/project-agent-entry.v1.json +32 -4
  6. package/contracts/workspace-intelligence/project-context-agent.v1.json +34 -2
  7. package/contracts/workspace-intelligence/workspace-context.v1.json +4 -1
  8. package/contracts/workspace-intelligence-chain.v1.json +4 -5
  9. package/dist/autopilot-release-GNTOXKIL.js +1 -0
  10. package/dist/{chunk-YGONW6VG.js → chunk-3VU7ROHY.js} +1 -1
  11. package/dist/chunk-46USUSIK.js +49 -0
  12. package/dist/{chunk-NJ6WJ7VU.js → chunk-JNPXLZA6.js} +1 -1
  13. package/dist/{chunk-WQX3JYEP.js → chunk-LNXIMF3O.js} +1 -1
  14. package/dist/{chunk-2FPANIX3.js → chunk-MWCKJOOU.js} +14 -12
  15. package/dist/{chunk-4KNDIFJ5.js → chunk-PKKP5H3T.js} +1 -1
  16. package/dist/{chunk-2JVRDBJC.js → chunk-PPQL5UTI.js} +1 -1
  17. package/dist/{chunk-GWMC6SSY.js → chunk-SS7NJMFL.js} +1 -1
  18. package/dist/{chunk-5YNZR74I.js → chunk-TR6OFSJM.js} +1 -1
  19. package/dist/{chunk-JRIEP4BY.js → chunk-TVCJKE2U.js} +1 -1
  20. package/dist/chunk-UZNACYV7.js +2 -0
  21. package/dist/{chunk-JEGG4EEZ.js → chunk-VDEFHP6I.js} +1 -1
  22. package/dist/chunk-YUGKQ44M.js +1 -0
  23. package/dist/{create-TPUFKW6B.js → create-CKUQRSJF.js} +1 -1
  24. package/dist/{goal-lifecycle-BNLXDHED.js → goal-lifecycle-7L5JFYOI.js} +1 -1
  25. package/dist/{goal-pack-2PF775AU.js → goal-pack-SGHXUPMU.js} +1 -1
  26. package/dist/index.js +19 -19
  27. package/dist/{pipeline-BY2YL7C6.js → pipeline-W2CKUZBS.js} +1 -1
  28. package/dist/{project-agent-entry-VXCOXRJB.js → project-agent-entry-66GTQQPX.js} +1 -1
  29. package/dist/{project-intelligence-lens-BA6JLXQH.js → project-intelligence-lens-NWNWLJMB.js} +1 -1
  30. package/dist/{verified-goal-5OV4BALK.js → verified-goal-AY5VU6LG.js} +1 -1
  31. package/dist/{workspace-J4OGSSNO.js → workspace-FSOLFNAJ.js} +1 -1
  32. package/dist/{workspace-agent-sync-MU7W3C4S.js → workspace-agent-sync-ZURWHL3H.js} +1 -1
  33. package/dist/{workspace-context-MDACPLHD.js → workspace-context-DPDGFTWJ.js} +1 -1
  34. package/dist/workspace-explain-OU2PEVYO.js +1 -0
  35. package/dist/{workspace-explain-contract-JWFM22L4.js → workspace-explain-contract-V2IVSROX.js} +1 -1
  36. package/dist/{workspace-foundation-3X5OBEMM.js → workspace-foundation-PPZKC36U.js} +1 -1
  37. package/dist/{workspace-intelligence-runner-DEW3CZKA.js → workspace-intelligence-runner-7RIOUCCM.js} +1 -1
  38. package/dist/{workspace-mcp-serve-S5IXSJJL.js → workspace-mcp-serve-PYKYJIE6.js} +1 -1
  39. package/dist/{workspace-onboarding-LK5IK6LE.js → workspace-onboarding-RP3RZ3CC.js} +1 -1
  40. package/dist/{workspace-readme-56YZ4EAZ.js → workspace-readme-G7TZ3V5T.js} +1 -1
  41. package/dist/{workspace-repair-engine-3OLRNXD6.js → workspace-repair-engine-L47XZXYZ.js} +1 -1
  42. package/dist/workspace-run-QV5ER2VW.js +1 -0
  43. package/docs/agent-entry.md +32 -2
  44. package/docs/ci-workflows.md +1 -1
  45. package/package.json +1 -1
  46. package/dist/autopilot-release-7Q5JT7YN.js +0 -1
  47. package/dist/chunk-ASOFWN6J.js +0 -1
  48. package/dist/chunk-RALI2ESF.js +0 -49
  49. package/dist/chunk-ZJ62F4U3.js +0 -2
  50. package/dist/workspace-explain-NWP3JTFR.js +0 -1
  51. package/dist/workspace-run-JTEIX4WA.js +0 -1
  52. /package/dist/{chunk-JMFCMPWI.js → chunk-GGOQHTZV.js} +0 -0
@@ -0,0 +1 @@
1
+ import {i,e}from'./chunk-NZ3WZYD5.js';var _=".workspai/skills";var a=e.skillsIndex,c=e.explain,P=i.workspaceWhy,O=i.workspaceTrace,I=".workspai/AGENT-GROUNDING.md",A=".rapidkit/AGENT-GROUNDING.md",R=".cursor/rules/workspai-grounding.mdc",E=".cursor/rules/workspai-evidence.mdc",T=".cursor/rules/workspai-diagnose.mdc",L=".cursor/rules/workspai-repair.mdc",S=".cursor/rules/workspai-release.mdc",d=".cursor/rules/rapidkit-grounding.mdc",k=".windsurfrules",C=".windsurf/rules/workspai-grounding.md",u=".windsurf/rules/workspai-evidence.md",N=".grok/rules/workspai-grounding.md",l=".grok/rules/workspai-evidence.md",K=".claude/rules/workspai-evidence.md",m=".claude/rules/workspai-workspace.md",g=".claude/rules/rapidkit-evidence.md",G=".amazonq/rules/workspai-workspace.md",x=".github/instructions/workspai-workspace.instructions.md",w=".github/instructions/rapidkit-workspace.instructions.md",H=".github/instructions/workspai-evidence.instructions.md",D=".github/instructions/rapidkit-evidence.instructions.md",U=".github/prompts/workspai-diagnose.prompt.md",W=".github/prompts/rapidkit-diagnose.prompt.md",h=".github/prompts/workspai-repair.prompt.md",b=".github/prompts/rapidkit-repair.prompt.md",M=".github/prompts/workspai-release-readiness.prompt.md",Y=".github/prompts/rapidkit-release-readiness.prompt.md",f=".github/prompts/workspai-project-onboard.prompt.md",v=".github/prompts/rapidkit-project-onboard.prompt.md",B=".github/prompts/workspai-adopt-project.prompt.md",V=".github/prompts/rapidkit-adopt-project.prompt.md",y=".github/skills/workspai-grounding/SKILL.md",F=".github/skills/rapidkit-grounding/SKILL.md",j=".github/skills/workspai-workspace-intelligence/SKILL.md",J=".github/skills/rapidkit-workspace-intelligence/SKILL.md",X=".cursor/skills/workspai-grounding/SKILL.md",$=".claude/skills/workspai-grounding/SKILL.md",z=".agents/skills/workspai-grounding/SKILL.md",q=".grok/skills/workspai-grounding/SKILL.md",Q=i.workspaiMcpDesign,Z=i.legacyMcpDesign,ss=i.agentHooks,os=".vscode/rapidkit-agent-hooks.json";var n=["workspai-diagnose-api-failure","workspai-release-readiness","workspai-safe-schema-migration","workspai-dependency-upgrade","workspai-rename-contract"];function ts(o){let t=o.trim();if(!t||t.includes("..")||t.includes("/"))throw new Error(`Invalid operational skill id: ${o}`);return `${_}/${t}.md`}function rs(o){return n.includes(o)}var _s={"workspai-diagnose-api-failure":"workspai-diagnose","workspai-release-readiness":"workspai-release-readiness","workspai-safe-schema-migration":"workspai-safe-schema-migration","workspai-dependency-upgrade":"workspai-dependency-upgrade","workspai-rename-contract":"workspai-rename-contract"};export{U as A,W as B,h as C,b as D,M as E,Y as F,f as G,v as H,B as I,V as J,y as K,F as L,j as M,J as N,X as O,$ as P,z as Q,q as R,Q as S,Z as T,ss as U,os as V,ts as W,rs as X,_s as Y,_ as a,a as b,c,P as d,O as e,I as f,A as g,R as h,E as i,T as j,L as k,S as l,d as m,k as n,C as o,u as p,N as q,l as r,K as s,m as t,g as u,G as v,x as w,w as x,H as y,D as z};
@@ -1 +1 @@
1
- export{c as PYTHON_FREE_WORKSPACE_PROFILES,a as buildWorkspaceManifest,f as createProject,g as registerWorkspaceAtPath,d as resolvePythonFreeFallbackProfile,b as syncWorkspaceFoundationFiles,e as writeWorkspaceLauncher}from'./chunk-5YNZR74I.js';
1
+ export{c as PYTHON_FREE_WORKSPACE_PROFILES,a as buildWorkspaceManifest,f as createProject,g as registerWorkspaceAtPath,d as resolvePythonFreeFallbackProfile,b as syncWorkspaceFoundationFiles,e as writeWorkspaceLauncher}from'./chunk-TR6OFSJM.js';
@@ -1 +1 @@
1
- export{f as GOAL_INDEX_PATH,e as GOAL_INDEX_SCHEMA_VERSION,k as buildGoalLifecycleResult,l as inspectGoalLifecycle,p as linkGoalRepairTransaction,n as prepareGoalVerification,m as transitionGoalLifecycle,o as verifyGoalLifecycle}from'./chunk-YGONW6VG.js';
1
+ export{f as GOAL_INDEX_PATH,e as GOAL_INDEX_SCHEMA_VERSION,k as buildGoalLifecycleResult,l as inspectGoalLifecycle,p as linkGoalRepairTransaction,n as prepareGoalVerification,m as transitionGoalLifecycle,o as verifyGoalLifecycle}from'./chunk-3VU7ROHY.js';
@@ -1 +1 @@
1
- import {c as c$5}from'./chunk-DIJGQUEV.js';import {c}from'./chunk-GWMC6SSY.js';import {j,i,d as d$1,f as f$2,c as c$3,e as e$1,h}from'./chunk-YGONW6VG.js';export{b as GOAL_AGENT_HANDOFF_SCHEMA_VERSION,f as GOAL_INDEX_PATH,e as GOAL_INDEX_SCHEMA_VERSION,g as GOAL_LIFECYCLE_RESULT_SCHEMA_VERSION,d as GOAL_PACK_LAST_RUN_PATH,a as GOAL_PACK_SCHEMA_VERSION,c as GOAL_PLAN_RESULT_SCHEMA_VERSION}from'./chunk-YGONW6VG.js';import {f as f$3}from'./chunk-4PUJVYRM.js';import {b}from'./chunk-GPOZILMY.js';import {a as a$1}from'./chunk-A4BK7C7M.js';import {c as c$4}from'./chunk-TFOOSYGO.js';import {d,c as c$1}from'./chunk-EWZZUQBR.js';import {c as c$2,f as f$1}from'./chunk-CCDGHPEJ.js';import {a}from'./chunk-AFIFZTOY.js';import {f,e}from'./chunk-NZ3WZYD5.js';import v from'path';import S from'fs-extra';var he=/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/,fe=/(?:^|\s)(?:\/(?:home|Users|private|var|tmp|mnt|opt|srv|root|workspace|workspaces|data|Volumes|etc|usr|run|dev|proc|sys)\/[^\s]+|[A-Za-z]:[\\/][^\s]+|\\\\[^\\\s]+\\[^\s]+)/,be=/(?:-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\b(?:github_pat_|gh[pousr]_|glpat-|npm_|xox[baprs]-|sk-(?:proj-)?)[A-Za-z0-9_-]{12,}|\b(?:AKIA|ASIA)[A-Z0-9]{16}\b|\bAIza[A-Za-z0-9_-]{20,}|\bBearer\s+[A-Za-z0-9._~+/-]{16,}|[a-z][a-z0-9+.-]*:\/\/[^\s:/]+:[^\s@/]+@|\b(?:password|passwd|secret|token|api[_-]?key)\s*[:=]\s*[^\s]{6,})/i,we=[{category:"test-coverage",patterns:[/\b(?:test\s+)?coverage\b/i,/\bcoverage\s+(?:to|above|at least)\b/i]},{category:"dependency-security",patterns:[/\b(?:dependency|dependencies|package|packages)\b.*\b(?:security|vulnerab|audit)\b/i,/\b(?:security|vulnerab|audit)\b.*\b(?:dependency|dependencies|package|packages)\b/i]},{category:"release-readiness",patterns:[/\brelease[ -]readiness\b/i,/\bready (?:this |the )?(?:workspace|project) for release\b/i,/\bprepare (?:this |the )?(?:workspace|project) for release\b/i,/\bprepare\b[^\n]{0,80}\bfor release\b/i]},{category:"defect-repair",patterns:[/\b(?:fix|repair|resolve|debug)\b.*\b(?:bug|error|failure|issue|regression)\b/i]},{category:"performance",patterns:[/\b(?:performance|latency|throughput|memory|cpu|optimi[sz]e|faster|slower)\b/i]},{category:"refactor",patterns:[/\b(?:refactor|restructure|decouple|extract|simplify|cleanup|clean up)\b/i]},{category:"documentation",patterns:[/\b(?:document|documentation|readme|guide|tutorial|docs)\b/i]},{category:"feature-change",patterns:[/\b(?:add|build|create|implement|introduce|support)\b/i]},{category:"system-understanding",patterns:[/\b(?:understand|explain|map|find|where|how|architecture|analy[sz]e|search)\b/i]}];function ke(e){if(typeof e!="string")throw new Error("Goal intent must be text.");let t=e.trim().replace(/\s+/g," ");if(!t)throw new Error("Goal intent cannot be empty.");if(t.length>2e3)throw new Error("Goal intent exceeds the 2000 character safety limit.");if(he.test(t))throw new Error("Goal intent contains unsupported control characters.");if(fe.test(t))throw new Error("Goal intent contains a machine-local absolute path. Use a workspace-relative path or project scope.");if(be.test(t))throw new Error("Goal intent appears to contain secret material and was not persisted.");return t}function ve(e){let t=e.match(/\b(?:coverage\D{0,24})?(100|\d{1,2})(?:\.\d+)?\s*%/i);if(!t||!/coverage/i.test(e))return null;let o=Number(t[1]);return Number.isFinite(o)&&o>=0&&o<=100?o:null}var te=[{runtime:"cpp",patterns:[/\bc\+\+/i,/\bcpp\b/i]},{runtime:"dotnet",patterns:[/\.net\b/i,/\bdotnet\b/i,/\bc#/i,/\bcsharp\b/i]},{runtime:"node",patterns:[/\bnode(?:\.js)?\b/i,/\btypescript\b/i,/\bjavascript\b/i,/\b(?:js|ts)\b/i]},{runtime:"python",patterns:[/\bpython\b/i,/\bpytest\b/i]},{runtime:"go",patterns:[/\bgolang\b/i,/\bgo(?:\s+(?:test|coverage|tests))\b/i]},{runtime:"java",patterns:[/\bjava\b/i,/\bjunit\b/i,/\bjacoco\b/i]},{runtime:"rust",patterns:[/\brust\b/i,/\bcargo\b/i]},{runtime:"php",patterns:[/\bphp\b/i,/\bphpunit\b/i]},{runtime:"ruby",patterns:[/\bruby\b/i,/\brspec\b/i]},{runtime:"kotlin",patterns:[/\bkotlin\b/i]},{runtime:"scala",patterns:[/\bscala\b/i]},{runtime:"clojure",patterns:[/\bclojure\b/i]},{runtime:"elixir",patterns:[/\belixir\b/i]},{runtime:"deno",patterns:[/\bdeno\b/i]},{runtime:"bun",patterns:[/\bbun\b/i]},{runtime:"c",patterns:[/\bc(?:\s+(?:test|coverage|tests|code))\b/i]}];function ye(e){return te.filter(t=>t.patterns.some(o=>o.test(e))).map(t=>t.runtime)}function $(e,t={}){let o=ke(e),r=we.filter(y=>y.patterns.some(k=>k.test(o))).map(y=>y.category),i=r[0]??"feature-change",l=ve(o),c=ye(o),p=c.length===0&&t.selectedCoverageRuntime?[t.selectedCoverageRuntime]:c,u=[...new Set((t.availableCoverageRuntimes??[]).filter(y=>te.some(k=>k.runtime===y)))].sort(),b=[];return r.length>1&&r[0]!=="test-coverage"&&b.push(`The intent also contains signals for: ${r.slice(1).join(", ")}.`),i==="test-coverage"&&l===null&&b.push("A numeric test coverage target is required for machine verification."),i==="test-coverage"&&p.length>1&&b.push(`The Goal names multiple coverage runtimes: ${p.join(", ")}. Select one runtime per Goal.`),i==="test-coverage"&&p.length===0&&u.length>1&&b.push(`Coverage scope is ambiguous across detected runtimes: ${u.join(", ")}. Name one runtime or language in the Goal.`),i==="test-coverage"&&p.length===1&&u.length>0&&!u.includes(p[0])&&b.push(`The requested ${p[0]} coverage runtime is not present in the selected scope. Detected runtimes: ${u.join(", ")}.`),{original:o,normalized:o.toLocaleLowerCase("en-US"),statement:o.replace(/[.!?]+$/,""),category:i,confidence:r.length===1?"high":r.length>1?"medium":"low",ambiguities:b,...l===null?{}:{requestedTarget:{metric:"test-coverage-percent",operator:"at-least",value:l,...p.length===1?{runtime:p[0]}:{}}}}}function re(e){let t={"test-coverage":["test suite coverage configuration instrumentation","CI tests LCOV Cobertura JaCoCo LLVM coverage"],"dependency-security":["dependency manifest lockfile security audit vulnerability"],"release-readiness":["release pipeline readiness gates build test deploy"],"defect-repair":["failure error test implementation call path"],"feature-change":["API implementation module dependency tests"],refactor:["module dependency ownership implementation tests"],performance:["performance benchmark latency throughput runtime"],documentation:["documentation README guide architecture decision"],"system-understanding":["architecture service API dependency ownership"]};return [...new Set([e.statement,...t[e.category]])].slice(0,3)}var oe="contracts/workspace-intelligence/goal-pack.v1.json",ne="contracts/workspace-intelligence/goal-agent-handoff.v1.json",Pe="contracts/workspace-intelligence/goal-plan-result.v1.json",ce="contracts/workspace-intelligence/goal-index.v1.json",le=new Set(["node","bun","deno","python","go","java","dotnet","rust","php","ruby","elixir","clojure","scala","kotlin","c","cpp"]);function ae(e){return e.split(v.sep).join("/")}function V(e,t){return v.resolve(t.absolutePath??v.join(e,t.path))}function se(e){let t=e.requested.trim().replace(/^project:/,"");if(!t)throw new Error("Project goal scope must name a project.");let o=v.isAbsolute(t)?v.resolve(t):null,r=e.model.projects.filter(i=>i.name===t||ae(i.path)===ae(t)||o!==null&&V(e.workspacePath,i)===o);if(r.length!==1)throw new Error(r.length===0?`Project goal scope was not found in the canonical model: ${t}`:`Project goal scope is ambiguous in the canonical model: ${t}`);return r[0]}async function je(e){let t=await a$1(e);if(t.status==="miss")throw new Error(`Canonical model and live graph evidence are required (${t.reason}). Run \`workspai workspace intelligence run --for-agent generic --strict --json\` or retry with --refresh.`);let{model:o,graph:r}=t;return a(o,"contracts/workspace-intelligence/workspace-model.v1.json","Goal source model"),a(r,"contracts/workspace-intelligence/workspace-knowledge-graph.v1.json","Goal source graph"),c$4(r,o),{model:o,graph:r}}function ie(e){let t=e.scope.trim();if(t==="workspace")return {kind:"workspace",projects:e.model.projects.map(r=>r.name).sort(),selectionSource:e.selectionSource,resolution:"selected"};let o=t.startsWith("projects:")?"projects:":t.startsWith("project:")&&t.slice(8).includes(",")?"project:":null;if(o){let r=t.slice(o.length).split(",").map(c=>c.trim()).filter(Boolean);if(r.length<2)throw new Error("A project-set Goal scope must name at least two projects.");let i=r.map(c=>se({workspacePath:e.workspacePath,model:e.model,requested:c})),l=[...new Set(i.map(c=>c.name))].sort();if(l.length!==r.length)throw new Error("A project-set Goal scope must not contain duplicate projects.");return {kind:"project-set",projects:l,selectionSource:e.selectionSource,resolution:"selected"}}if(t)return {kind:"project",projects:[se({workspacePath:e.workspacePath,model:e.model,requested:t}).name],selectionSource:e.selectionSource,resolution:"selected"};throw new Error("Goal scope cannot be empty.")}async function Ge(e){if(e.explicitScope?.trim())return {scope:ie({workspacePath:e.workspacePath,model:e.model,scope:e.explicitScope,selectionSource:"explicit"}),selectionRequired:false};if(e.invocationProjectPath){let t=v.resolve(e.invocationProjectPath),o=e.model.projects.filter(r=>V(e.workspacePath,r)===t);if(o.length!==1)throw new Error("The invocation project is not represented uniquely in the canonical workspace model. Refresh intelligence or pass --scope explicitly.");return {scope:{kind:"project",projects:[o[0].name],selectionSource:"invocation-project",resolution:"selected"},selectionRequired:false}}if(e.model.projects.length===1)return {scope:{kind:"project",projects:[e.model.projects[0].name],selectionSource:"single-project-workspace",resolution:"selected"},selectionRequired:false};if(e.selectScope){let t=await e.selectScope({workspaceName:e.model.workspace.name,projects:e.model.projects.map(r=>({name:r.name,runtime:r.runtime,runtimeCandidates:[...r.runtimeCandidates].sort(),framework:r.framework})).sort((r,i)=>r.name.localeCompare(i.name))}),o=t.kind==="workspace"?"workspace":t.projects.length===1?`project:${t.projects[0]}`:`projects:${t.projects.join(",")}`;return {scope:ie({workspacePath:e.workspacePath,model:e.model,scope:o,selectionSource:"interactive"}),selectionRequired:false}}return {scope:{kind:"workspace",projects:e.model.projects.map(t=>t.name).sort(),selectionSource:"workspace",resolution:"selection-required"},selectionRequired:true}}function Ae(e,t){if(t.kind==="workspace")return {entities:e.quality.entityCount,relationships:e.quality.relationCount,proofs:e.quality.proofCount,unresolved:e.quality.unknownCount,proofCoveragePercent:Number((e.quality.relationProofCoverageRatio*100).toFixed(2))};let o=new Set(t.projects),r=e.entities.filter(u=>u.projectId!==void 0&&o.has(u.projectId)),i=new Set(r.map(u=>u.id)),l=e.relations.filter(u=>i.has(u.from)||i.has(u.to)),c=new Set([...r.flatMap(u=>u.proofIds),...l.flatMap(u=>u.proofIds)]),p=l.filter(u=>u.proofIds.length>0).length;return {entities:r.length,relationships:l.length,proofs:c.size,unresolved:l.length-p,proofCoveragePercent:l.length===0?100:Number((p/l.length*100).toFixed(2))}}async function Ce(e$1){let t=v.join(e$1.workspacePath,e.intelligenceRun),o=await S.readJson(t).catch(()=>null),i=(Array.isArray(o?.stages)?o.stages:[]).filter(n=>n.status==="blocked"||n.status==="failed").map(n=>String(n.id??"unknown")).sort(),l=o?.status,c={status:l==="passed"?"passed":l==="blocked"||l==="failed"?"blocked":"unknown",artifact:e.intelligenceRun,blockedStages:i},p={status:"not-applicable",runtime:null,runtimeChoices:[],runner:null,existingEvidence:[],prerequisites:[]};if(e$1.intent.category==="test-coverage"){let n=e$1.intent.requestedTarget?.runtime;if(e$1.intent.ambiguities.some(P=>P.startsWith("Coverage scope is ambiguous")||P.startsWith("The Goal names multiple coverage runtimes")||P.startsWith("The selected projects do not share a common canonical coverage runtime")||P.startsWith("The requested ")))p={status:"requires-setup",runtime:n??null,runtimeChoices:e$1.coverageRuntimeChoices,runner:null,existingEvidence:[],prerequisites:["Select exactly one detected runtime or language for this coverage Goal."]};else {let P=n?e$1.projects.filter(a=>a.runtimeCandidates.includes(n)):e$1.projects,f=await Promise.all(P.map(async a=>({project:a,capability:await c$5(V(e$1.workspacePath,a),n??(le.has(a.runtime)?a.runtime:"unknown"))}))),s=f.map(a=>a.capability.status);p={status:s.includes("unsupported")?"unsupported":s.includes("requires-setup")?"requires-setup":"available",runtime:f.length===1?f[0].capability.runtime:[...new Set(f.map(a=>a.capability.runtime))].join(","),runtimeChoices:e$1.coverageRuntimeChoices,runner:f.length===1?f[0].capability.runner:[...new Set(f.flatMap(a=>a.capability.runner?[a.capability.runner]:[]))].join(",")||null,existingEvidence:f.flatMap(a=>a.capability.existingEvidence.map(g=>({project:a.project.name,...g}))).filter((a,g,L)=>L.findIndex(j=>j.project===a.project&&j.path===a.path&&j.sha256===a.sha256)===g).sort((a,g)=>a.project.localeCompare(g.project)||a.path.localeCompare(g.path)),prerequisites:[...new Set(f.flatMap(a=>a.capability.prerequisites))].sort()};}}let u=re(e$1.intent),b=u.map(n=>{let w=e$1.projects.map(s=>f$3(e$1.graph,{query:n,projectId:s.name,limit:20,relationsPerEntity:0,minimumTermMatches:2}).entities),P=[],f=new Set;for(let s=0;w.some(a=>s<a.length);s+=1)for(let a of w){let g=a[s];!g||f.has(g.id)||(f.add(g.id),P.push(g));}return P}),y={"test-coverage":["test-suite"],"dependency-security":["package","module"],"release-readiness":["pipeline","deployment","lifecycle-stage"],"defect-repair":["test-suite","lifecycle-stage"],"feature-change":["project","runtime-unit","api","package","module","test-suite"],refactor:["package","module","api","test-suite"],performance:["lifecycle-stage","test-suite","pipeline"],documentation:["document","decision"],"system-understanding":["project","service","api","package","protocol"]},k=new Set(e$1.projects.map(n=>n.name)),N=e$1.graph.entities.filter(n=>n.proofIds.length>0&&(!n.projectId||k.has(n.projectId))&&y[e$1.intent.category].includes(n.kind)).sort((n,w)=>y[e$1.intent.category].indexOf(n.kind)-y[e$1.intent.category].indexOf(w.kind)||n.label.localeCompare(w.label)),h=[],m=new Set,A=n=>{!n||h.length>=20||m.has(n.id)||(m.add(n.id),h.push(n));},C=(e$1.intent.statement.match(/[A-Za-z][A-Za-z0-9+#.-]{1,}/g)??[]).length>=2,x=C?b[0]??[]:[];for(let n of x.slice(0,12))A(n);if(!C)for(let n of N)A(n);for(let n=0;h.length<20&&b.slice(1).some(w=>n<w.length);n+=1)for(let w of b.slice(1))A(w[n]);if(C)for(let n of N)A(n);for(let n of x.slice(12))A(n);let d=h.map(n=>({entityId:n.id,kind:n.kind,label:n.label,proofIds:n.proofIds.slice(0,12)})),E=b[0]?.length??0;return {workspaceIntelligence:c,measurement:p,retrieval:{status:C&&E>=3?"grounded":d.length>0?"partial":"empty",strategy:"deterministic-category-v1",queries:u,anchors:d}}}async function Re(e){let t=v.join(e,f$2);if(!await S.pathExists(t))return {schemaVersion:e$1,generatedAt:new Date(0).toISOString(),activeGoalId:null,goals:[]};let o=await S.readJson(t);a(o,ce,"Goal index");try{i(o);}catch(r){let i=h(o);if(!(i!==null&&r instanceof Error&&r.message==="Goal index is inconsistent: activeGoalId must identify the only selected actionable lifecycle entry.")||!i)throw r;return i}return o}function Se(e,t,o){let r=e.goals.find(c=>c.id===t.id),i=t.state==="ready-to-plan",l={id:t.id,fingerprint:t.fingerprint,objective:t.intent.statement,category:t.intent.category,state:t.state,lifecycle:r?.lifecycle==="cancelled"?"cancelled":i?"active":"planned",scope:t.scope,createdAt:r?.createdAt??t.generatedAt,updatedAt:o,goalPack:t.artifacts.goalPack,agentHandoff:t.artifacts.agentHandoff,...r?.verifiedGoalId?{verifiedGoalId:r.verifiedGoalId}:{},...r?.repairTransactionId?{repairTransactionId:r.repairTransactionId}:{},...r?.repairTransactionIds?{repairTransactionIds:r.repairTransactionIds}:{},...r?.verificationReceipt?{verificationReceipt:r.verificationReceipt}:{}};return {schemaVersion:e$1,generatedAt:o,activeGoalId:l.lifecycle==="active"?t.id:e.activeGoalId===t.id?null:e.activeGoalId,goals:[...e.goals.filter(c=>c.id!==t.id).map(c=>l.lifecycle==="active"&&c.lifecycle==="active"?{...c,lifecycle:"planned",updatedAt:o}:c),l].sort((c,p)=>c.id.localeCompare(p.id))}}async function De(e$1){let t=b({startPath:v.resolve(e$1.startPath),explicitWorkspacePath:e$1.workspacePath,strict:true,requireProjectMembership:true});if(!t)throw new Error("No canonical Workspai workspace could be resolved.");let o=v.resolve(t.workspacePath);e$1.refresh&&await c({workspacePath:o,strict:false,agent:"generic"});let{model:r,graph:i$1}=await je(o),l=await Ge({workspacePath:o,invocationProjectPath:t.projectPath,model:r,explicitScope:e$1.scope,selectScope:e$1.selectScope}),c$4=l.scope,p=r.projects.filter(s=>c$4.projects.includes(s.name));if(p.length===0)throw new Error("A Goal Pack requires at least one registered project in its selected scope.");let u=e$1.maxAttempts??5;if(!Number.isInteger(u)||u<1||u>25)throw new Error("--max-attempts must be an integer from 1 to 25.");let b$1=new Date().toISOString(),y=d(r),k=p.map(s=>({name:s.name,runtimes:[...new Set(s.runtimeCandidates.filter(a=>le.has(a)))].sort()})),N=[...new Set(k.flatMap(s=>s.runtimes))].sort(),h=k.length<=1?N:k[0].runtimes.filter(s=>k.every(a=>a.runtimes.includes(s))),m=$(e$1.intent,{availableCoverageRuntimes:h,...e$1.runtime?{selectedCoverageRuntime:e$1.runtime}:h.length===1?{selectedCoverageRuntime:h[0]}:{}});if(e$1.runtime&&!h.includes(e$1.runtime)){let s=e$1.runtime,a=k.filter(g=>!g.runtimes.includes(s)).map(g=>g.name);throw new Error(p.length>1&&a.length>0?`--runtime ${e$1.runtime} is not canonical for every project in the selected Goal scope. Missing from: ${a.join(", ")}. Split the projects into runtime-compatible Goal scopes.`:`--runtime ${e$1.runtime} is not present in the canonical Workspace Model for the selected Goal scope. Available runtimes: ${h.join(", ")||"none"}.`)}if(e$1.runtime&&m.category!=="test-coverage")throw new Error("--runtime is valid only for a test-coverage Goal.");if(e$1.runtime&&m.requestedTarget?.runtime&&m.requestedTarget.runtime!==e$1.runtime)throw new Error(`--runtime ${e$1.runtime} conflicts with the ${m.requestedTarget.runtime} runtime named in the Goal intent.`);if(!l.selectionRequired&&m.category==="test-coverage"&&m.requestedTarget&&!m.requestedTarget.runtime&&h.length>1&&!e$1.runtime&&e$1.selectCoverageRuntime){let s=await e$1.selectCoverageRuntime({workspaceName:r.workspace.name,scope:c$4,projects:p.map(a=>({name:a.name,runtime:a.runtime,runtimeCandidates:[...a.runtimeCandidates].sort()})),runtimes:h});if(!h.includes(s))throw new Error("The selected coverage runtime is outside the canonical Goal scope.");m=$(e$1.intent,{availableCoverageRuntimes:h,selectedCoverageRuntime:s});}!l.selectionRequired&&m.category==="test-coverage"&&p.length>1&&h.length===0&&(m={...m,ambiguities:[`The selected projects do not share a common canonical coverage runtime: ${k.map(s=>`${s.name} (${s.runtimes.join(", ")||"none"})`).join("; ")}. Split them into runtime-compatible Goal scopes so every selected project is verified.`,...m.ambiguities]}),l.selectionRequired&&(m={...m,ambiguities:[`Goal scope is unresolved across ${c$4.projects.length} registered projects: ${c$4.projects.join(", ")}. Select one project, multiple projects, or the entire workspace.`,...m.ambiguities]});let A=await Ce({workspacePath:o,projects:p,graph:i$1,intent:m,coverageRuntimeChoices:h}),C={generatedAt:b$1,intent:m,workspaceName:r.workspace.name,scope:c$4,sourceBinding:{model:{artifact:e.model,schemaVersion:f.model,hashAlgorithm:"sha256",hashSemantics:"workspace-model-structural-v1",hash:y,generatedAt:r.generatedAt},graph:{artifact:e.knowledgeGraph,schemaVersion:f.knowledgeGraph,hashAlgorithm:"sha256",hashSemantics:"canonical-json-v1",hash:c$1(i$1),generatedAt:i$1.generatedAt,modelHash:i$1.source.hash,...i$1.source.inputs?.hash?{inputHash:i$1.source.inputs.hash}:{}}},preflight:A,baseline:{projectCount:p.length,runtimes:[...new Set(p.flatMap(s=>s.runtimeCandidates))].sort(),frameworks:[...new Set(p.map(s=>s.framework))].sort(),graph:Ae(i$1,c$4)},maxAttempts:u,consumer:e$1.consumer??"generic"},x={digestCanonical:c$1},{goalPack:d$2,handoff:E}=j(C,x);a(d$2,oe,"Goal Pack"),a(E,ne,"Goal agent handoff");let n=false,w=async()=>{let s=v.join(o,d$2.artifacts.goalPack),a$1=v.join(o,d$2.artifacts.agentHandoff),[g,L]=await Promise.all([S.pathExists(s),S.pathExists(a$1)]);if(g!==L)throw new Error(`Goal Pack instance is incomplete and cannot be resumed: ${d$2.id}`);if(!g)return;let[j$1,q]=await Promise.all([S.readJson(s),S.readJson(a$1)]);a(j$1,oe,"Persisted Goal Pack"),a(q,ne,"Persisted goal agent handoff");let z=j({...C,generatedAt:j$1.generatedAt,sourceBinding:j$1.sourceBinding},x);if(j$1.id!==d$2.id||q.goalId!==d$2.id||c$1(j$1)!==c$1(z.goalPack)||c$1(q)!==c$1(z.handoff))throw new Error(`Goal Pack instance failed immutable integrity validation: ${d$2.id}`);d$2=j$1,E=q,n=true;};if(e$1.dryRun)await w();else {let s=`.workspai/goals/${d$2.id}/publication`;await c$2(o,s,async()=>{await w();let a$1=Se(await Re(o),d$2,new Date().toISOString());a(a$1,ce,"Goal index"),i(a$1),await f$1(o,d$1,n?[{relativePath:d$1,payload:d$2},{relativePath:f$2,payload:a$1}]:[{relativePath:d$2.artifacts.goalPack,payload:d$2},{relativePath:d$2.artifacts.agentHandoff,payload:E},{relativePath:d$1,payload:d$2},{relativePath:f$2,payload:a$1}]);});}let P=[d$2.artifacts.goalPack,d$2.artifacts.agentHandoff,d$1,f$2],f$3={schemaVersion:c$3,result:d$2.state==="needs-confirmation"?"needs-confirmation":d$2.state==="blocked"?"blocked":d$2.state==="needs-evidence"?"needs-evidence":"planned",resolution:{source:t.source,invocationScope:t.projectPath?"project":"workspace"},goalPack:d$2,agentHandoff:E,writtenArtifacts:e$1.dryRun?[]:n?[d$1,f$2]:P,dryRun:e$1.dryRun===true,resumed:n};return a(f$3,Pe,"Goal plan result"),f$3}export{De as planGoalPack};
1
+ import {c as c$5}from'./chunk-DIJGQUEV.js';import {c}from'./chunk-SS7NJMFL.js';import {j,i,d as d$1,f as f$2,c as c$3,e as e$1,h}from'./chunk-3VU7ROHY.js';export{b as GOAL_AGENT_HANDOFF_SCHEMA_VERSION,f as GOAL_INDEX_PATH,e as GOAL_INDEX_SCHEMA_VERSION,g as GOAL_LIFECYCLE_RESULT_SCHEMA_VERSION,d as GOAL_PACK_LAST_RUN_PATH,a as GOAL_PACK_SCHEMA_VERSION,c as GOAL_PLAN_RESULT_SCHEMA_VERSION}from'./chunk-3VU7ROHY.js';import {f as f$3}from'./chunk-4PUJVYRM.js';import {b}from'./chunk-GPOZILMY.js';import {a as a$1}from'./chunk-A4BK7C7M.js';import {c as c$4}from'./chunk-TFOOSYGO.js';import {d,c as c$1}from'./chunk-EWZZUQBR.js';import {c as c$2,f as f$1}from'./chunk-CCDGHPEJ.js';import {a}from'./chunk-AFIFZTOY.js';import {f,e}from'./chunk-NZ3WZYD5.js';import v from'path';import S from'fs-extra';var he=/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/,fe=/(?:^|\s)(?:\/(?:home|Users|private|var|tmp|mnt|opt|srv|root|workspace|workspaces|data|Volumes|etc|usr|run|dev|proc|sys)\/[^\s]+|[A-Za-z]:[\\/][^\s]+|\\\\[^\\\s]+\\[^\s]+)/,be=/(?:-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\b(?:github_pat_|gh[pousr]_|glpat-|npm_|xox[baprs]-|sk-(?:proj-)?)[A-Za-z0-9_-]{12,}|\b(?:AKIA|ASIA)[A-Z0-9]{16}\b|\bAIza[A-Za-z0-9_-]{20,}|\bBearer\s+[A-Za-z0-9._~+/-]{16,}|[a-z][a-z0-9+.-]*:\/\/[^\s:/]+:[^\s@/]+@|\b(?:password|passwd|secret|token|api[_-]?key)\s*[:=]\s*[^\s]{6,})/i,we=[{category:"test-coverage",patterns:[/\b(?:test\s+)?coverage\b/i,/\bcoverage\s+(?:to|above|at least)\b/i]},{category:"dependency-security",patterns:[/\b(?:dependency|dependencies|package|packages)\b.*\b(?:security|vulnerab|audit)\b/i,/\b(?:security|vulnerab|audit)\b.*\b(?:dependency|dependencies|package|packages)\b/i]},{category:"release-readiness",patterns:[/\brelease[ -]readiness\b/i,/\bready (?:this |the )?(?:workspace|project) for release\b/i,/\bprepare (?:this |the )?(?:workspace|project) for release\b/i,/\bprepare\b[^\n]{0,80}\bfor release\b/i]},{category:"defect-repair",patterns:[/\b(?:fix|repair|resolve|debug)\b.*\b(?:bug|error|failure|issue|regression)\b/i]},{category:"performance",patterns:[/\b(?:performance|latency|throughput|memory|cpu|optimi[sz]e|faster|slower)\b/i]},{category:"refactor",patterns:[/\b(?:refactor|restructure|decouple|extract|simplify|cleanup|clean up)\b/i]},{category:"documentation",patterns:[/\b(?:document|documentation|readme|guide|tutorial|docs)\b/i]},{category:"feature-change",patterns:[/\b(?:add|build|create|implement|introduce|support)\b/i]},{category:"system-understanding",patterns:[/\b(?:understand|explain|map|find|where|how|architecture|analy[sz]e|search)\b/i]}];function ke(e){if(typeof e!="string")throw new Error("Goal intent must be text.");let t=e.trim().replace(/\s+/g," ");if(!t)throw new Error("Goal intent cannot be empty.");if(t.length>2e3)throw new Error("Goal intent exceeds the 2000 character safety limit.");if(he.test(t))throw new Error("Goal intent contains unsupported control characters.");if(fe.test(t))throw new Error("Goal intent contains a machine-local absolute path. Use a workspace-relative path or project scope.");if(be.test(t))throw new Error("Goal intent appears to contain secret material and was not persisted.");return t}function ve(e){let t=e.match(/\b(?:coverage\D{0,24})?(100|\d{1,2})(?:\.\d+)?\s*%/i);if(!t||!/coverage/i.test(e))return null;let o=Number(t[1]);return Number.isFinite(o)&&o>=0&&o<=100?o:null}var te=[{runtime:"cpp",patterns:[/\bc\+\+/i,/\bcpp\b/i]},{runtime:"dotnet",patterns:[/\.net\b/i,/\bdotnet\b/i,/\bc#/i,/\bcsharp\b/i]},{runtime:"node",patterns:[/\bnode(?:\.js)?\b/i,/\btypescript\b/i,/\bjavascript\b/i,/\b(?:js|ts)\b/i]},{runtime:"python",patterns:[/\bpython\b/i,/\bpytest\b/i]},{runtime:"go",patterns:[/\bgolang\b/i,/\bgo(?:\s+(?:test|coverage|tests))\b/i]},{runtime:"java",patterns:[/\bjava\b/i,/\bjunit\b/i,/\bjacoco\b/i]},{runtime:"rust",patterns:[/\brust\b/i,/\bcargo\b/i]},{runtime:"php",patterns:[/\bphp\b/i,/\bphpunit\b/i]},{runtime:"ruby",patterns:[/\bruby\b/i,/\brspec\b/i]},{runtime:"kotlin",patterns:[/\bkotlin\b/i]},{runtime:"scala",patterns:[/\bscala\b/i]},{runtime:"clojure",patterns:[/\bclojure\b/i]},{runtime:"elixir",patterns:[/\belixir\b/i]},{runtime:"deno",patterns:[/\bdeno\b/i]},{runtime:"bun",patterns:[/\bbun\b/i]},{runtime:"c",patterns:[/\bc(?:\s+(?:test|coverage|tests|code))\b/i]}];function ye(e){return te.filter(t=>t.patterns.some(o=>o.test(e))).map(t=>t.runtime)}function $(e,t={}){let o=ke(e),r=we.filter(y=>y.patterns.some(k=>k.test(o))).map(y=>y.category),i=r[0]??"feature-change",l=ve(o),c=ye(o),p=c.length===0&&t.selectedCoverageRuntime?[t.selectedCoverageRuntime]:c,u=[...new Set((t.availableCoverageRuntimes??[]).filter(y=>te.some(k=>k.runtime===y)))].sort(),b=[];return r.length>1&&r[0]!=="test-coverage"&&b.push(`The intent also contains signals for: ${r.slice(1).join(", ")}.`),i==="test-coverage"&&l===null&&b.push("A numeric test coverage target is required for machine verification."),i==="test-coverage"&&p.length>1&&b.push(`The Goal names multiple coverage runtimes: ${p.join(", ")}. Select one runtime per Goal.`),i==="test-coverage"&&p.length===0&&u.length>1&&b.push(`Coverage scope is ambiguous across detected runtimes: ${u.join(", ")}. Name one runtime or language in the Goal.`),i==="test-coverage"&&p.length===1&&u.length>0&&!u.includes(p[0])&&b.push(`The requested ${p[0]} coverage runtime is not present in the selected scope. Detected runtimes: ${u.join(", ")}.`),{original:o,normalized:o.toLocaleLowerCase("en-US"),statement:o.replace(/[.!?]+$/,""),category:i,confidence:r.length===1?"high":r.length>1?"medium":"low",ambiguities:b,...l===null?{}:{requestedTarget:{metric:"test-coverage-percent",operator:"at-least",value:l,...p.length===1?{runtime:p[0]}:{}}}}}function re(e){let t={"test-coverage":["test suite coverage configuration instrumentation","CI tests LCOV Cobertura JaCoCo LLVM coverage"],"dependency-security":["dependency manifest lockfile security audit vulnerability"],"release-readiness":["release pipeline readiness gates build test deploy"],"defect-repair":["failure error test implementation call path"],"feature-change":["API implementation module dependency tests"],refactor:["module dependency ownership implementation tests"],performance:["performance benchmark latency throughput runtime"],documentation:["documentation README guide architecture decision"],"system-understanding":["architecture service API dependency ownership"]};return [...new Set([e.statement,...t[e.category]])].slice(0,3)}var oe="contracts/workspace-intelligence/goal-pack.v1.json",ne="contracts/workspace-intelligence/goal-agent-handoff.v1.json",Pe="contracts/workspace-intelligence/goal-plan-result.v1.json",ce="contracts/workspace-intelligence/goal-index.v1.json",le=new Set(["node","bun","deno","python","go","java","dotnet","rust","php","ruby","elixir","clojure","scala","kotlin","c","cpp"]);function ae(e){return e.split(v.sep).join("/")}function V(e,t){return v.resolve(t.absolutePath??v.join(e,t.path))}function se(e){let t=e.requested.trim().replace(/^project:/,"");if(!t)throw new Error("Project goal scope must name a project.");let o=v.isAbsolute(t)?v.resolve(t):null,r=e.model.projects.filter(i=>i.name===t||ae(i.path)===ae(t)||o!==null&&V(e.workspacePath,i)===o);if(r.length!==1)throw new Error(r.length===0?`Project goal scope was not found in the canonical model: ${t}`:`Project goal scope is ambiguous in the canonical model: ${t}`);return r[0]}async function je(e){let t=await a$1(e);if(t.status==="miss")throw new Error(`Canonical model and live graph evidence are required (${t.reason}). Run \`workspai workspace intelligence run --for-agent generic --strict --json\` or retry with --refresh.`);let{model:o,graph:r}=t;return a(o,"contracts/workspace-intelligence/workspace-model.v1.json","Goal source model"),a(r,"contracts/workspace-intelligence/workspace-knowledge-graph.v1.json","Goal source graph"),c$4(r,o),{model:o,graph:r}}function ie(e){let t=e.scope.trim();if(t==="workspace")return {kind:"workspace",projects:e.model.projects.map(r=>r.name).sort(),selectionSource:e.selectionSource,resolution:"selected"};let o=t.startsWith("projects:")?"projects:":t.startsWith("project:")&&t.slice(8).includes(",")?"project:":null;if(o){let r=t.slice(o.length).split(",").map(c=>c.trim()).filter(Boolean);if(r.length<2)throw new Error("A project-set Goal scope must name at least two projects.");let i=r.map(c=>se({workspacePath:e.workspacePath,model:e.model,requested:c})),l=[...new Set(i.map(c=>c.name))].sort();if(l.length!==r.length)throw new Error("A project-set Goal scope must not contain duplicate projects.");return {kind:"project-set",projects:l,selectionSource:e.selectionSource,resolution:"selected"}}if(t)return {kind:"project",projects:[se({workspacePath:e.workspacePath,model:e.model,requested:t}).name],selectionSource:e.selectionSource,resolution:"selected"};throw new Error("Goal scope cannot be empty.")}async function Ge(e){if(e.explicitScope?.trim())return {scope:ie({workspacePath:e.workspacePath,model:e.model,scope:e.explicitScope,selectionSource:"explicit"}),selectionRequired:false};if(e.invocationProjectPath){let t=v.resolve(e.invocationProjectPath),o=e.model.projects.filter(r=>V(e.workspacePath,r)===t);if(o.length!==1)throw new Error("The invocation project is not represented uniquely in the canonical workspace model. Refresh intelligence or pass --scope explicitly.");return {scope:{kind:"project",projects:[o[0].name],selectionSource:"invocation-project",resolution:"selected"},selectionRequired:false}}if(e.model.projects.length===1)return {scope:{kind:"project",projects:[e.model.projects[0].name],selectionSource:"single-project-workspace",resolution:"selected"},selectionRequired:false};if(e.selectScope){let t=await e.selectScope({workspaceName:e.model.workspace.name,projects:e.model.projects.map(r=>({name:r.name,runtime:r.runtime,runtimeCandidates:[...r.runtimeCandidates].sort(),framework:r.framework})).sort((r,i)=>r.name.localeCompare(i.name))}),o=t.kind==="workspace"?"workspace":t.projects.length===1?`project:${t.projects[0]}`:`projects:${t.projects.join(",")}`;return {scope:ie({workspacePath:e.workspacePath,model:e.model,scope:o,selectionSource:"interactive"}),selectionRequired:false}}return {scope:{kind:"workspace",projects:e.model.projects.map(t=>t.name).sort(),selectionSource:"workspace",resolution:"selection-required"},selectionRequired:true}}function Ae(e,t){if(t.kind==="workspace")return {entities:e.quality.entityCount,relationships:e.quality.relationCount,proofs:e.quality.proofCount,unresolved:e.quality.unknownCount,proofCoveragePercent:Number((e.quality.relationProofCoverageRatio*100).toFixed(2))};let o=new Set(t.projects),r=e.entities.filter(u=>u.projectId!==void 0&&o.has(u.projectId)),i=new Set(r.map(u=>u.id)),l=e.relations.filter(u=>i.has(u.from)||i.has(u.to)),c=new Set([...r.flatMap(u=>u.proofIds),...l.flatMap(u=>u.proofIds)]),p=l.filter(u=>u.proofIds.length>0).length;return {entities:r.length,relationships:l.length,proofs:c.size,unresolved:l.length-p,proofCoveragePercent:l.length===0?100:Number((p/l.length*100).toFixed(2))}}async function Ce(e$1){let t=v.join(e$1.workspacePath,e.intelligenceRun),o=await S.readJson(t).catch(()=>null),i=(Array.isArray(o?.stages)?o.stages:[]).filter(n=>n.status==="blocked"||n.status==="failed").map(n=>String(n.id??"unknown")).sort(),l=o?.status,c={status:l==="passed"?"passed":l==="blocked"||l==="failed"?"blocked":"unknown",artifact:e.intelligenceRun,blockedStages:i},p={status:"not-applicable",runtime:null,runtimeChoices:[],runner:null,existingEvidence:[],prerequisites:[]};if(e$1.intent.category==="test-coverage"){let n=e$1.intent.requestedTarget?.runtime;if(e$1.intent.ambiguities.some(P=>P.startsWith("Coverage scope is ambiguous")||P.startsWith("The Goal names multiple coverage runtimes")||P.startsWith("The selected projects do not share a common canonical coverage runtime")||P.startsWith("The requested ")))p={status:"requires-setup",runtime:n??null,runtimeChoices:e$1.coverageRuntimeChoices,runner:null,existingEvidence:[],prerequisites:["Select exactly one detected runtime or language for this coverage Goal."]};else {let P=n?e$1.projects.filter(a=>a.runtimeCandidates.includes(n)):e$1.projects,f=await Promise.all(P.map(async a=>({project:a,capability:await c$5(V(e$1.workspacePath,a),n??(le.has(a.runtime)?a.runtime:"unknown"))}))),s=f.map(a=>a.capability.status);p={status:s.includes("unsupported")?"unsupported":s.includes("requires-setup")?"requires-setup":"available",runtime:f.length===1?f[0].capability.runtime:[...new Set(f.map(a=>a.capability.runtime))].join(","),runtimeChoices:e$1.coverageRuntimeChoices,runner:f.length===1?f[0].capability.runner:[...new Set(f.flatMap(a=>a.capability.runner?[a.capability.runner]:[]))].join(",")||null,existingEvidence:f.flatMap(a=>a.capability.existingEvidence.map(g=>({project:a.project.name,...g}))).filter((a,g,L)=>L.findIndex(j=>j.project===a.project&&j.path===a.path&&j.sha256===a.sha256)===g).sort((a,g)=>a.project.localeCompare(g.project)||a.path.localeCompare(g.path)),prerequisites:[...new Set(f.flatMap(a=>a.capability.prerequisites))].sort()};}}let u=re(e$1.intent),b=u.map(n=>{let w=e$1.projects.map(s=>f$3(e$1.graph,{query:n,projectId:s.name,limit:20,relationsPerEntity:0,minimumTermMatches:2}).entities),P=[],f=new Set;for(let s=0;w.some(a=>s<a.length);s+=1)for(let a of w){let g=a[s];!g||f.has(g.id)||(f.add(g.id),P.push(g));}return P}),y={"test-coverage":["test-suite"],"dependency-security":["package","module"],"release-readiness":["pipeline","deployment","lifecycle-stage"],"defect-repair":["test-suite","lifecycle-stage"],"feature-change":["project","runtime-unit","api","package","module","test-suite"],refactor:["package","module","api","test-suite"],performance:["lifecycle-stage","test-suite","pipeline"],documentation:["document","decision"],"system-understanding":["project","service","api","package","protocol"]},k=new Set(e$1.projects.map(n=>n.name)),N=e$1.graph.entities.filter(n=>n.proofIds.length>0&&(!n.projectId||k.has(n.projectId))&&y[e$1.intent.category].includes(n.kind)).sort((n,w)=>y[e$1.intent.category].indexOf(n.kind)-y[e$1.intent.category].indexOf(w.kind)||n.label.localeCompare(w.label)),h=[],m=new Set,A=n=>{!n||h.length>=20||m.has(n.id)||(m.add(n.id),h.push(n));},C=(e$1.intent.statement.match(/[A-Za-z][A-Za-z0-9+#.-]{1,}/g)??[]).length>=2,x=C?b[0]??[]:[];for(let n of x.slice(0,12))A(n);if(!C)for(let n of N)A(n);for(let n=0;h.length<20&&b.slice(1).some(w=>n<w.length);n+=1)for(let w of b.slice(1))A(w[n]);if(C)for(let n of N)A(n);for(let n of x.slice(12))A(n);let d=h.map(n=>({entityId:n.id,kind:n.kind,label:n.label,proofIds:n.proofIds.slice(0,12)})),E=b[0]?.length??0;return {workspaceIntelligence:c,measurement:p,retrieval:{status:C&&E>=3?"grounded":d.length>0?"partial":"empty",strategy:"deterministic-category-v1",queries:u,anchors:d}}}async function Re(e){let t=v.join(e,f$2);if(!await S.pathExists(t))return {schemaVersion:e$1,generatedAt:new Date(0).toISOString(),activeGoalId:null,goals:[]};let o=await S.readJson(t);a(o,ce,"Goal index");try{i(o);}catch(r){let i=h(o);if(!(i!==null&&r instanceof Error&&r.message==="Goal index is inconsistent: activeGoalId must identify the only selected actionable lifecycle entry.")||!i)throw r;return i}return o}function Se(e,t,o){let r=e.goals.find(c=>c.id===t.id),i=t.state==="ready-to-plan",l={id:t.id,fingerprint:t.fingerprint,objective:t.intent.statement,category:t.intent.category,state:t.state,lifecycle:r?.lifecycle==="cancelled"?"cancelled":i?"active":"planned",scope:t.scope,createdAt:r?.createdAt??t.generatedAt,updatedAt:o,goalPack:t.artifacts.goalPack,agentHandoff:t.artifacts.agentHandoff,...r?.verifiedGoalId?{verifiedGoalId:r.verifiedGoalId}:{},...r?.repairTransactionId?{repairTransactionId:r.repairTransactionId}:{},...r?.repairTransactionIds?{repairTransactionIds:r.repairTransactionIds}:{},...r?.verificationReceipt?{verificationReceipt:r.verificationReceipt}:{}};return {schemaVersion:e$1,generatedAt:o,activeGoalId:l.lifecycle==="active"?t.id:e.activeGoalId===t.id?null:e.activeGoalId,goals:[...e.goals.filter(c=>c.id!==t.id).map(c=>l.lifecycle==="active"&&c.lifecycle==="active"?{...c,lifecycle:"planned",updatedAt:o}:c),l].sort((c,p)=>c.id.localeCompare(p.id))}}async function De(e$1){let t=b({startPath:v.resolve(e$1.startPath),explicitWorkspacePath:e$1.workspacePath,strict:true,requireProjectMembership:true});if(!t)throw new Error("No canonical Workspai workspace could be resolved.");let o=v.resolve(t.workspacePath);e$1.refresh&&await c({workspacePath:o,strict:false,agent:"generic"});let{model:r,graph:i$1}=await je(o),l=await Ge({workspacePath:o,invocationProjectPath:t.projectPath,model:r,explicitScope:e$1.scope,selectScope:e$1.selectScope}),c$4=l.scope,p=r.projects.filter(s=>c$4.projects.includes(s.name));if(p.length===0)throw new Error("A Goal Pack requires at least one registered project in its selected scope.");let u=e$1.maxAttempts??5;if(!Number.isInteger(u)||u<1||u>25)throw new Error("--max-attempts must be an integer from 1 to 25.");let b$1=new Date().toISOString(),y=d(r),k=p.map(s=>({name:s.name,runtimes:[...new Set(s.runtimeCandidates.filter(a=>le.has(a)))].sort()})),N=[...new Set(k.flatMap(s=>s.runtimes))].sort(),h=k.length<=1?N:k[0].runtimes.filter(s=>k.every(a=>a.runtimes.includes(s))),m=$(e$1.intent,{availableCoverageRuntimes:h,...e$1.runtime?{selectedCoverageRuntime:e$1.runtime}:h.length===1?{selectedCoverageRuntime:h[0]}:{}});if(e$1.runtime&&!h.includes(e$1.runtime)){let s=e$1.runtime,a=k.filter(g=>!g.runtimes.includes(s)).map(g=>g.name);throw new Error(p.length>1&&a.length>0?`--runtime ${e$1.runtime} is not canonical for every project in the selected Goal scope. Missing from: ${a.join(", ")}. Split the projects into runtime-compatible Goal scopes.`:`--runtime ${e$1.runtime} is not present in the canonical Workspace Model for the selected Goal scope. Available runtimes: ${h.join(", ")||"none"}.`)}if(e$1.runtime&&m.category!=="test-coverage")throw new Error("--runtime is valid only for a test-coverage Goal.");if(e$1.runtime&&m.requestedTarget?.runtime&&m.requestedTarget.runtime!==e$1.runtime)throw new Error(`--runtime ${e$1.runtime} conflicts with the ${m.requestedTarget.runtime} runtime named in the Goal intent.`);if(!l.selectionRequired&&m.category==="test-coverage"&&m.requestedTarget&&!m.requestedTarget.runtime&&h.length>1&&!e$1.runtime&&e$1.selectCoverageRuntime){let s=await e$1.selectCoverageRuntime({workspaceName:r.workspace.name,scope:c$4,projects:p.map(a=>({name:a.name,runtime:a.runtime,runtimeCandidates:[...a.runtimeCandidates].sort()})),runtimes:h});if(!h.includes(s))throw new Error("The selected coverage runtime is outside the canonical Goal scope.");m=$(e$1.intent,{availableCoverageRuntimes:h,selectedCoverageRuntime:s});}!l.selectionRequired&&m.category==="test-coverage"&&p.length>1&&h.length===0&&(m={...m,ambiguities:[`The selected projects do not share a common canonical coverage runtime: ${k.map(s=>`${s.name} (${s.runtimes.join(", ")||"none"})`).join("; ")}. Split them into runtime-compatible Goal scopes so every selected project is verified.`,...m.ambiguities]}),l.selectionRequired&&(m={...m,ambiguities:[`Goal scope is unresolved across ${c$4.projects.length} registered projects: ${c$4.projects.join(", ")}. Select one project, multiple projects, or the entire workspace.`,...m.ambiguities]});let A=await Ce({workspacePath:o,projects:p,graph:i$1,intent:m,coverageRuntimeChoices:h}),C={generatedAt:b$1,intent:m,workspaceName:r.workspace.name,scope:c$4,sourceBinding:{model:{artifact:e.model,schemaVersion:f.model,hashAlgorithm:"sha256",hashSemantics:"workspace-model-structural-v1",hash:y,generatedAt:r.generatedAt},graph:{artifact:e.knowledgeGraph,schemaVersion:f.knowledgeGraph,hashAlgorithm:"sha256",hashSemantics:"canonical-json-v1",hash:c$1(i$1),generatedAt:i$1.generatedAt,modelHash:i$1.source.hash,...i$1.source.inputs?.hash?{inputHash:i$1.source.inputs.hash}:{}}},preflight:A,baseline:{projectCount:p.length,runtimes:[...new Set(p.flatMap(s=>s.runtimeCandidates))].sort(),frameworks:[...new Set(p.map(s=>s.framework))].sort(),graph:Ae(i$1,c$4)},maxAttempts:u,consumer:e$1.consumer??"generic"},x={digestCanonical:c$1},{goalPack:d$2,handoff:E}=j(C,x);a(d$2,oe,"Goal Pack"),a(E,ne,"Goal agent handoff");let n=false,w=async()=>{let s=v.join(o,d$2.artifacts.goalPack),a$1=v.join(o,d$2.artifacts.agentHandoff),[g,L]=await Promise.all([S.pathExists(s),S.pathExists(a$1)]);if(g!==L)throw new Error(`Goal Pack instance is incomplete and cannot be resumed: ${d$2.id}`);if(!g)return;let[j$1,q]=await Promise.all([S.readJson(s),S.readJson(a$1)]);a(j$1,oe,"Persisted Goal Pack"),a(q,ne,"Persisted goal agent handoff");let z=j({...C,generatedAt:j$1.generatedAt,sourceBinding:j$1.sourceBinding},x);if(j$1.id!==d$2.id||q.goalId!==d$2.id||c$1(j$1)!==c$1(z.goalPack)||c$1(q)!==c$1(z.handoff))throw new Error(`Goal Pack instance failed immutable integrity validation: ${d$2.id}`);d$2=j$1,E=q,n=true;};if(e$1.dryRun)await w();else {let s=`.workspai/goals/${d$2.id}/publication`;await c$2(o,s,async()=>{await w();let a$1=Se(await Re(o),d$2,new Date().toISOString());a(a$1,ce,"Goal index"),i(a$1),await f$1(o,d$1,n?[{relativePath:d$1,payload:d$2},{relativePath:f$2,payload:a$1}]:[{relativePath:d$2.artifacts.goalPack,payload:d$2},{relativePath:d$2.artifacts.agentHandoff,payload:E},{relativePath:d$1,payload:d$2},{relativePath:f$2,payload:a$1}]);});}let P=[d$2.artifacts.goalPack,d$2.artifacts.agentHandoff,d$1,f$2],f$3={schemaVersion:c$3,result:d$2.state==="needs-confirmation"?"needs-confirmation":d$2.state==="blocked"?"blocked":d$2.state==="needs-evidence"?"needs-evidence":"planned",resolution:{source:t.source,invocationScope:t.projectPath?"project":"workspace"},goalPack:d$2,agentHandoff:E,writtenArtifacts:e$1.dryRun?[]:n?[d$1,f$2]:P,dryRun:e$1.dryRun===true,resumed:n};return a(f$3,Pe,"Goal plan result"),f$3}export{De as planGoalPack};