scip-query 0.19.4 → 0.19.5
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/CHANGELOG.md +27 -0
- package/README.md +1 -1
- package/dist/{chunk-SVLTAG5O.js → chunk-7UY7SD7D.js} +119 -119
- package/dist/{chunk-VMNZB6WI.js → chunk-TW4OG5FC.js} +2 -2
- package/dist/chunk-XAGAZSFE.js +6 -0
- package/dist/cli.js +3 -3
- package/dist/command-descriptors-N2TL4XM2.js +613 -0
- package/dist/direct-navigation-DUCZCTOE.js +3 -0
- package/docs/AI_FAILURE_MODES.md +1 -1
- package/docs/COMMAND_REFERENCE.md +5 -5
- package/docs/DETECTOR_GUIDE.md +1 -1
- package/package.json +1 -1
- package/skills/_shared/SKILL.md +6 -16
- package/skills/scip-api-impact/SKILL.md +22 -21
- package/skills/scip-claim-audit/SKILL.md +18 -17
- package/skills/scip-cleanup-audit/SKILL.md +24 -20
- package/skills/scip-cleanup-improve/SKILL.md +19 -18
- package/skills/scip-concrete-plan/HIGH_ASSURANCE.md +317 -0
- package/skills/scip-concrete-plan/SKILL.md +70 -227
- package/skills/scip-conductor/SKILL.md +14 -14
- package/skills/scip-debug/SKILL.md +21 -21
- package/skills/scip-diagram/SKILL.md +27 -27
- package/skills/scip-directory-architecture/SKILL.md +44 -32
- package/skills/scip-doc-reconcile/SKILL.md +17 -17
- package/skills/scip-explore/SKILL.md +23 -23
- package/skills/scip-hyper-optimization/SKILL.md +23 -23
- package/skills/scip-language-playbook/SKILL.md +34 -34
- package/skills/scip-maintainability/SKILL.md +21 -21
- package/skills/scip-probe-reachability/SKILL.md +10 -9
- package/skills/scip-query/SKILL.md +39 -39
- package/skills/scip-react-maintainability/SKILL.md +21 -21
- package/skills/scip-root-cause/SKILL.md +21 -20
- package/skills/scip-setup/SKILL.md +25 -24
- package/skills/scip-tla-model-system/SKILL.md +7 -7
- package/skills/scip-triage-issue/SKILL.md +27 -20
- package/skills/scip-twin-drift/SKILL.md +18 -16
- package/skills/scip-verify/SKILL.md +25 -9
- package/skills/scip-vue-maintainability/SKILL.md +21 -21
- package/dist/chunk-ZAIILQNP.js +0 -5
- package/dist/command-descriptors-MFU4BCJ7.js +0 -612
- package/dist/direct-navigation-MRMQFIRB.js +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import{Cc as Y,Dc as Q,Qc as X,Rc as Z,V as y,W as k,Xc as ee,b as B,ca as F,da as H,fa as w,ga as T,ha as b,ja as _,jc as C,ka as U,kc as J,la as z,lc as K,oa as L}from"./chunk-7UY7SD7D.js";import{spawn as ke}from"child_process";import{closeSync as we,existsSync as Ie,mkdirSync as We,openSync as Re,readFileSync as ie,rmSync as I,writeFileSync as be}from"fs";import{dirname as Ce,resolve as E}from"path";import{fileURLToPath as Ae}from"url";var te=5e3,Pe=2e3,oe=10,Ee=new Set(["bench","config-validate","hook-context","hook-stop","init","reindex","setup","setup-agent","setup-ci","setup-hooks","uninstall","watch","work-audit"]);function Je(e){let t=e.classification;if(t.kind!=="live")return;let{state:r}=t;return r.watcher.state==="idle"&&r.lastError===void 0?r.indexGeneration:void 0}function xe(e,t=process.env){return t.SCIP_QUERY_SKIP_WATCH_SERVICE!=="1"&&!e.startsWith("__")&&!Ee.has(e)}function Ke(e){let t=e.env??process.env;if(t.SCIP_QUERY_SKIP_WATCH_SERVICE==="1")return{kind:"skipped",reason:"environment"};if(!xe(e.commandName,t))return{kind:"skipped",reason:"excluded-command"};if(e.config.watch?.enabled!==!0)return{kind:"skipped",reason:"disabled"};try{let r=Te({projectRoot:e.projectRoot,cacheDir:e.cacheDir,cliVersion:e.cliVersion,gitContext:e.gitContext,runtime:e.runtime});return{kind:r.disposition,state:r.state}}catch(r){return{kind:"failed",message:r instanceof Error?r.message:String(r)}}}function se(e,t,r){let n=L(E(e));if(r&&L(r.projectRoot)===n)return{projectRoot:n,worktreeKind:"git",worktreeId:r.worktreeId,cliVersion:t};let i=U(n);if(i.kind==="error")throw new Error(`Could not establish Git worktree identity for ${n}: ${i.message}`);return i.kind==="non-git"?{projectRoot:n,worktreeKind:"non-git",cliVersion:t}:{projectRoot:n,worktreeKind:"git",worktreeId:i.identity.worktreeId,cliVersion:t}}function Ye(e){return P(e,se(e.projectRoot,e.cliVersion,e.gitContext))}function P(e,t){let r=e.runtime??O,n=w(e.cacheDir),i=T(n.statePath),s=m(n.lockPath);return{identity:t,classification:De(i,t,r.now(),r.isProcessAlive),lock:s,lockIsLive:s!==null&&r.isProcessAlive(s.pid),paths:n}}function Te(e){let t=e.runtime??O,r=se(e.projectRoot,e.cliVersion,e.gitContext),n=P(e,r),i=G("ensure",n.classification);if(i.kind==="reuse")return A(n.paths.activityPath,t),{disposition:"reused",state:i.state};if(i.kind==="replace")M(i.state.pid,e,t),W(n.paths,i.state.pid,t);else if(i.kind==="start"){if(n.lockIsLive){let o=re(e,r,t,Math.min(e.startupTimeoutMs??1e3,1e3));if(o)return A(n.paths.activityPath,t),{disposition:"reused",state:o};throw new Error(`scip-query watch is already running for ${E(e.projectRoot)} (pid ${n.lock?.pid}; lock: ${n.paths.lockPath}) without compatible daemon state. Stop the foreground watcher before starting the service.`)}n.classification.kind==="stale"&&W(n.paths,n.classification.state.pid,t)}else throw new Error(`Unexpected ensure action: ${i.kind}`);if(n=P(e,r),i=G("ensure",n.classification),i.kind==="reuse")return A(n.paths.activityPath,t),{disposition:"reused",state:i.state};let s=e.serverPath??Ae(new URL("./watch-server.js",import.meta.url));t.spawnServer(s,r.projectRoot,e.cliVersion,e.watchOverrides??{});let a=re(e,r,t,e.startupTimeoutMs??te);if(!a)throw new Error(`scip-query watch service did not become ready within ${e.startupTimeoutMs??te}ms.`);return A(n.paths.activityPath,t),{disposition:"started",state:a}}function ae(e){let t=e.runtime??O,r=w(e.cacheDir),n=T(r.statePath),i=n?t.isProcessAlive(n.pid)?{kind:"live",state:n}:{kind:"stale",state:n,reason:"dead-process"}:{kind:"stopped"},s=G("stop",i);if(s.kind==="signal-stop")return M(s.state.pid,e,t),W(r,s.state.pid,t),{disposition:"stopped",pid:s.state.pid};if(s.kind==="clean-stale")return W(r,s.state.pid,t),{disposition:"stopped",pid:s.state.pid};let a=m(r.lockPath);return s.kind==="already-stopped"&&a&&t.isProcessAlive(a.pid)?(M(a.pid,e,t),W(r,a.pid,t),{disposition:"stopped",pid:a.pid}):{disposition:"already-stopped"}}function _e(e,t=Date.now()){let r=Le(e);k(e,{version:1,at:new Date(t).toISOString(),...r?.refreshRequestedAtMs===void 0?{}:{refreshRequestedAt:new Date(r.refreshRequestedAtMs).toISOString(),...r.refreshDetail?{refreshDetail:r.refreshDetail}:{}}})}function Qe(e,t,r=Date.now()){k(e,{version:1,at:new Date(r).toISOString(),refreshRequestedAt:new Date(r).toISOString(),refreshDetail:t})}function Le(e){try{let t=JSON.parse(ie(e,"utf8"));return t.version!==1||!b(t.at)||t.refreshRequestedAt!==void 0&&!b(t.refreshRequestedAt)||t.refreshDetail!==void 0&&typeof t.refreshDetail!="string"?null:{atMs:Date.parse(t.at),...t.refreshRequestedAt===void 0?{}:{refreshRequestedAtMs:Date.parse(t.refreshRequestedAt)},...t.refreshDetail===void 0?{}:{refreshDetail:t.refreshDetail}}}catch{return null}}function Xe(e,t,r={}){let n=r.pid??process.pid,i=r.isProcessAlive??y,s=()=>{},a=m(e);if(a&&i(a.pid))return{acquired:!1,lockPath:e,message:ne(e,t,a),release:s};a&&I(e,{force:!0}),We(Ce(e),{recursive:!0});let o;try{o=Re(e,"wx")}catch(d){if(ce(d)==="EEXIST")return{acquired:!1,lockPath:e,message:ne(e,t,m(e)),release:s};throw d}let l={version:1,pid:n,projectRoot:E(t),startedAt:(r.now??(()=>new Date))().toISOString()};be(o,`${JSON.stringify(l)}
|
|
3
3
|
`);let c=!1;return{acquired:!0,lockPath:e,message:"",release:()=>{if(c)return;c=!0,we(o);let d=m(e);d?.pid===l.pid&&d.startedAt===l.startedAt&&I(e,{force:!0})}}}function m(e){try{let t=JSON.parse(ie(e,"utf-8"));return t.version!==1||typeof t.pid!="number"||!Number.isInteger(t.pid)||t.pid<=0||typeof t.projectRoot!="string"||!b(t.startedAt)?null:t}catch{return null}}function De(e,t,r,n){if(!e)return{kind:"stopped"};if(e.protocolVersion!==F)return{kind:"incompatible",state:e,reason:"protocol"};if(e.projectRoot!==t.projectRoot)return{kind:"incompatible",state:e,reason:"project"};let i=t.worktreeKind==="git"?t.worktreeId:void 0;if(e.worktreeId!==i)return{kind:"incompatible",state:e,reason:"worktree"};if(e.cliVersion!==t.cliVersion)return{kind:"incompatible",state:e,reason:"cli-version"};if(!n(e.pid))return{kind:"stale",state:e,reason:"dead-process"};let s=Date.parse(e.heartbeatAt);return r-s>H?{kind:"stale",state:e,reason:"old-heartbeat"}:{kind:"live",state:e}}function G(e,t){switch(e){case"status":return{kind:"report",classification:t};case"ensure":switch(t.kind){case"stopped":return{kind:"start"};case"stale":return t.reason==="old-heartbeat"?{kind:"replace",state:t.state}:{kind:"start"};case"live":return{kind:"reuse",state:t.state};case"incompatible":return{kind:"replace",state:t.state};default:return D(t)}case"stop":switch(t.kind){case"stopped":return{kind:"already-stopped"};case"stale":return t.reason==="old-heartbeat"?{kind:"signal-stop",state:t.state}:{kind:"clean-stale",state:t.state};case"live":case"incompatible":return{kind:"signal-stop",state:t.state};default:return D(t)}default:return D(e)}}function re(e,t,r,n){let i=r.now()+n;for(;r.now()<=i;){let s=P(e,t).classification;if(s.kind==="live")return s.state;r.sleep(oe)}return null}function M(e,t,r){if(!r.isProcessAlive(e))return;r.signalProcess(e);let n=t.stopTimeoutMs??Pe,i=r.now()+n;for(;r.now()<=i;){if(!r.isProcessAlive(e))return;r.sleep(oe)}throw new Error(`scip-query watch service pid ${e} did not stop within ${n}ms.`)}function W(e,t,r){I(e.statePath,{force:!0}),I(e.activityPath,{force:!0}),m(e.lockPath)?.pid===t&&!r.isProcessAlive(t)&&I(e.lockPath,{force:!0})}function ne(e,t,r){return`error: scip-query watch is already running for ${E(t)}${r?` (pid ${r.pid}, started ${r.startedAt}; lock: ${e})`:` (lock: ${e})`}. Stop that watcher before starting another.`}function ce(e){return typeof e=="object"&&e&&"code"in e?e.code:void 0}function A(e,t){try{(t.recordActivity??_e)(e,t.now())}catch(r){let n=ce(r);if(n!=="EPERM"&&n!=="EACCES"&&n!=="EROFS")throw r}}var O={now:Date.now,isProcessAlive:y,spawnServer(e,t,r,n){if(!Ie(e))throw new Error(`Watch service helper was not found at ${e}. Run npm run build first.`);ke(process.execPath,[e,t,r,JSON.stringify(n)],{detached:!0,stdio:"ignore",env:{...process.env,SCIP_QUERY_SKIP_WATCH_SERVICE:"1"}}).unref()},signalProcess(e){process.kill(e,"SIGTERM")},sleep(e){let t=new Int32Array(new SharedArrayBuffer(4));Atomics.wait(t,0,0,e)}};function D(e){throw new Error(`Unhandled watch service value: ${JSON.stringify(e)}`)}import{existsSync as pe,lstatSync as x,readFileSync as N,readdirSync as he,realpathSync as de,rmSync as R,statSync as fe}from"fs";import{join as h,resolve as g,sep as le}from"path";var Ge=3600*1e3,Me=2*1024*1024*1024,Oe=300*1e3;function je(e){let t=e.leases.filter(o=>o.managed&&!o.live&&!o.busy),r=Se(e.leases,e.locks),n={};for(let o of e.generations)r.has(o.generationId)||(n[o.generationId]=o.unreferencedAt??e.nowMs);let i=e.generations.filter(o=>!r.has(o.generationId)).sort((o,l)=>n[o.generationId]-n[l.generationId]||o.generationId.localeCompare(l.generationId)),s=new Set;for(let o of i)e.nowMs-n[o.generationId]>=e.policy.generationTtlMs&&s.add(o.generationId);let a=e.generations.filter(o=>!s.has(o.generationId)).reduce((o,l)=>o+l.size,0);for(let o of i){if(a<=e.policy.budgetBytes)break;s.has(o.generationId)||(s.add(o.generationId),a-=o.size)}for(let o of s)delete n[o];return{deleteWorktrees:t,deleteGenerations:e.generations.filter(o=>s.has(o.generationId)),deleteLocks:e.locks.filter(o=>!o.live),deleteTemporaries:e.temporaries.filter(o=>!o.live),protectedGenerationIds:[...r].sort(),unreferencedSince:n}}function Se(e,t){let r=new Set(e.filter(n=>n.managed&&(n.live||n.busy)).flatMap(n=>[n.lease.baseGenerationId,n.lease.activeGenerationId]).filter(n=>n!==void 0));for(let n of t)n.live&&r.add(n.generationId);return r}function ut(e,t,r={}){if(!K())return{kind:"disabled"};let n=_(e);if(!n)return{kind:"unavailable"};let i=h(C(),"repositories",n.repositoryId);if(!pe(i))return{kind:"unavailable"};let s=(r.now??Date.now)(),a=h(i,"gc-state.json"),o=me(a);if(!r.force&&o&&s-Date.parse(o.lastSweepAt)<Oe)return{kind:"throttled",sweptAt:o.lastSweepAt};let l=Y(i,{now:()=>s});if(!l)return{kind:"busy"};try{let c=ve(e,i,n.repositoryId,o?.unreferencedSince??{}),d=je({nowMs:s,...c,policy:{generationTtlMs:r.policy?.generationTtlMs??Ge,budgetBytes:r.policy?.budgetBytes??Me}}),u=0,f=0;for(let p of d.deleteWorktrees){if(!ye(p.lease))continue;let q=Q(h(p.lease.localCacheDir,"cache-lifecycle.lock"));if(q)try{if(V(p.lease,!0))continue;try{ae({projectRoot:p.lease.projectRoot,cacheDir:p.lease.localCacheDir,cliVersion:t})}catch{continue}if(V(p.lease,!0))continue;R(p.lease.localCacheDir,{recursive:!0,force:!0}),R(p.leasePath,{force:!0}),f+=1}finally{q.release()}}for(let p of d.deleteLocks)R(p.path,{force:!0});for(let p of d.deleteTemporaries)R(p.path,{recursive:!0,force:!0});for(let p of d.deleteGenerations)R(p.path,{recursive:!0,force:!0}),u+=p.size;B(h(i,"evidence.db"));let v={kind:"swept",sweptAt:new Date(s).toISOString(),deletedWorktrees:f,deletedGenerations:d.deleteGenerations.length,deletedBytes:u,protectedGenerations:d.protectedGenerationIds.length},S={version:1,lastSweepAt:v.sweptAt,unreferencedSince:d.unreferencedSince,lastResult:v};return k(a,S,{spacing:2,trailingNewline:!0}),v}catch(c){return{kind:"failed",error:c instanceof Error?c.message:String(c)}}finally{l.release()}}function pt(e,t,r){let n=X(e,r.dbPath,t);if(n)return{state:"bypassed",reason:n,localCacheDir:r.cacheDir,generations:0,generationBytes:0,protectedGenerations:0,unreferencedGenerations:0,unreferencedBytes:0,temporaryGenerations:0,sharedEvidence:{exists:!1,bytes:0}};let i=_(e);if(!i)return{state:"unavailable",reason:"Git worktree identity is unavailable",localCacheDir:r.cacheDir,generations:0,generationBytes:0,protectedGenerations:0,unreferencedGenerations:0,unreferencedBytes:0,temporaryGenerations:0,sharedEvidence:{exists:!1,bytes:0}};let s=h(C(),"repositories",i.repositoryId),a=ge(h(s,"worktrees",`${i.worktreeId}.json`)),o=me(h(s,"gc-state.json")),l=ve(e,s,i.repositoryId,o?.unreferencedSince??{}),c=Se(l.leases,l.locks),d=l.generations.filter(S=>!c.has(S.generationId)),u=l.generations.reduce((S,p)=>S+p.size,0),f=Z(e,t),v=0;return f&&(v=Ve(f)),{state:"managed",repositoryId:i.repositoryId,worktreeId:i.worktreeId,localCacheDir:r.cacheDir,...a?{baseGenerationId:a.baseGenerationId,activeGenerationId:a.activeGenerationId,lastAction:a.lastAction,reason:a.lastReason,lastSeenAt:a.lastSeenAt}:{},generations:l.generations.length,generationBytes:u,protectedGenerations:l.generations.filter(S=>c.has(S.generationId)).length,unreferencedGenerations:d.length,unreferencedBytes:d.reduce((S,p)=>S+p.size,0),temporaryGenerations:l.temporaries.length,sharedEvidence:{path:f,exists:v>0,bytes:v},cleanup:o?.lastResult}}function Ve(e){return[e,`${e}-wal`,`${e}-shm`].reduce((t,r)=>{try{return t+fe(r).size}catch{return t}},0)}function ve(e,t,r,n){let i=new Set(z(e).map(c=>g(c.path))),s=[];for(let c of j(h(t,"worktrees"))){if(!c.endsWith(".json"))continue;let d=h(t,"worktrees",c),u=ge(d);if(!u)continue;let f=g(u.projectRoot);s.push({leasePath:d,lease:u,managed:u.repositoryId===r&&ye(u),live:i.has(f)||pe(f),busy:V(u)})}let a=[];for(let c of j(h(t,"locks"))){let d=/^([a-f0-9]{64})\.lock$/.exec(c);if(!d)continue;let u=h(t,"locks",c),f=$(u),v=f!==void 0&&y(f),S=d[1];a.push({generationId:S,path:u,live:v})}let o=[],l=[];for(let c of j(h(t,"generations"))){let d=/^\.tmp-(\d+)-/.exec(c);if(d){let v=h(t,"generations",c),S=Number(d[1]);try{l.push({path:v,size:ue(v),live:Number.isSafeInteger(S)&&y(S)})}catch{}continue}if(!/^[a-f0-9]{64}$/.test(c))continue;let u=h(t,"generations",c),f;try{f=x(u)}catch{continue}!f.isDirectory()||f.isSymbolicLink()||o.push({generationId:c,path:u,size:ue(u),...n[c]===void 0?{}:{unreferencedAt:n[c]}})}return{leases:s,generations:o,locks:a,temporaries:l}}function ye(e){if(e.ownershipChecksum!==ee(e)||g(e.localCacheDir)!==g(J(e.projectRoot)))return!1;let t=g(C()),r=g(h(t,"projects")),n=g(e.localCacheDir);if(!n.startsWith(`${r}${le}`))return!1;try{let i=x(t),s=x(r),a=x(n);if(!i.isDirectory()||i.isSymbolicLink()||!s.isDirectory()||s.isSymbolicLink()||!a.isDirectory()||a.isSymbolicLink())return!1;let o=de(r);return de(n).startsWith(`${o}${le}`)}catch{return!1}}function V(e,t=!1){for(let n of t?["index.lock"]:["index.lock","cache-lifecycle.lock"]){let i=$(h(e.localCacheDir,n));if(i!==void 0&&y(i))return!0}let r=$(w(e.localCacheDir).lockPath);return r!==void 0&&y(r)}function ge(e){try{let t=JSON.parse(N(e,"utf8"));return t.version!==1||typeof t.repositoryId!="string"||typeof t.worktreeId!="string"||typeof t.projectRoot!="string"||t.treeOid!==void 0&&typeof t.treeOid!="string"||typeof t.localCacheDir!="string"||t.baseGenerationId!==void 0&&typeof t.baseGenerationId!="string"||t.activeGenerationId!==void 0&&typeof t.activeGenerationId!="string"||typeof t.ownershipChecksum!="string"||!/^[a-f0-9]{64}$/.test(t.ownershipChecksum)||typeof t.lastAction!="string"||t.lastReason!==void 0&&typeof t.lastReason!="string"||typeof t.lastSeenAt!="string"?null:t}catch{return null}}function $(e){try{let t=JSON.parse(N(e,"utf8"));return typeof t.pid=="number"&&Number.isSafeInteger(t.pid)&&t.pid>0?t.pid:void 0}catch{return}}function me(e){try{let t=JSON.parse(N(e,"utf8"));return t.version!==1||typeof t.lastSweepAt!="string"||!Number.isFinite(Date.parse(t.lastSweepAt))||!t.unreferencedSince||typeof t.unreferencedSince!="object"||!t.lastResult?null:t}catch{return null}}function j(e){try{return he(e)}catch{return[]}}function ue(e){let t=0,r=[e];for(;r.length>0;){let n=r.pop();for(let i of he(n,{withFileTypes:!0})){let s=h(n,i.name);i.isDirectory()?r.push(s):i.isFile()&&(t+=fe(s).size)}}return t}export{Je as a,xe as b,Ke as c,Ye as d,Te as e,ae as f,Qe as g,Xe as h,ut as i,pt as j};
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
4
|
+
//# sourceMappingURL=chunk-TW4OG5FC.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{Ca as E,E as y,F as v,Id as b,Kd as F,Ld as V,Md as p,Na as M,Od as W,Rd as C,dd as k,fc as G,gd as u,hd as B,id as T,kd as d,wa as j,wd as S,xd as A,z as N}from"./chunk-7UY7SD7D.js";var lt=k,q=(t=>parseInt(t,10)),z=(t=>{let e=parseInt(t,10);if(!Number.isFinite(e)||e<1)throw new Error(`Expected a positive integer, got ${t}`);return e}),ct=parseFloat,ut=parseInt;function l(t,e,o,...n){return n.length>0?{flags:t,description:e,parser:o,defaultValue:n[0]}:{flags:t,description:e,parser:o}}function X(){return l("--json","Output as JSON for programmatic consumption")}function Y(){return l("--compact","Emit minified one-line JSON (use with --json)")}function H(t=[]){let e=w(t);return e.some(o=>o.flags==="--compact")?e:[...e,Y()]}function w(t=[]){return t.some(e=>e.flags==="--json")?t:[...t,X()]}function x(t,e=[]){return{category:t,examples:e}}function R(t,e,o,n,r){return{answers:typeof t=="string"?[t]:t,returns:typeof e=="string"?[e]:e,inputs:o,coverage:n,...r?{scope:r}:{}}}import{createHash as Z}from"crypto";import{statSync as _}from"fs";function K(t){let e=j(t.config.dbPath);if(e)return e;let o=_(t.config.dbPath);return Z("sha256").update(`${o.dev}:${o.ino}:${o.size}:${o.mtimeMs}`).digest("hex")}function Q(t){return Buffer.from(JSON.stringify({version:1,...t}),"utf8").toString("base64url")}function U(t,e){let o;try{o=JSON.parse(Buffer.from(t,"base64url").toString("utf8"))}catch{throw new Error("Invalid result cursor. Run the command again without --cursor.")}if(!tt(o))throw new Error("Invalid result cursor. Run the command again without --cursor.");if(o.command!==e.command||o.target!==e.target)throw new Error("This cursor belongs to a different command or target. Run again without --cursor.");if(o.indexGeneration!==e.indexGeneration)throw new Error("The index changed after this cursor was issued. Run again without --cursor.");return o}function tt(t){if(!t||typeof t!="object")return!1;let e=t;return e.version===1&&typeof e.command=="string"&&typeof e.target=="string"&&Number.isSafeInteger(e.offset)&&(e.offset??-1)>=0&&typeof e.indexGeneration=="string"&&e.indexGeneration.length>0}function P(t,e){let o=y(t,e),n=nt(o);for(let r of n)console.log(r)}function $(t,e,o="No results found for resolved symbol."){return y(t,e).match?o:ot(e,v(t,e,5))}function O(t,e,o,n){return{...et(t,e),[n]:o}}function et(t,e){let o=y(t,e);return o.match?{matched:!0,resolved:{symbol:o.match.symbol,shortName:N(o.match.symbol),relativePath:o.match.relativePath},otherMatches:o.candidates.map(n=>({shortName:n.shortName,relativePath:n.relativePath,startLine:n.startLine})),totalMatches:o.total}:{matched:!1,suggestions:v(t,e,5)}}function ot(t,e){let o=`No definition matched '${t}'.`;return e.length>0?`${o} Suggestions: ${e.join(", ")}`:o}function nt(t){if(!t.match||t.total<=1)return[];let e=t.match,o=Math.max(0,t.total-1),n=[`Resolved: ${N(e.symbol)} (${e.relativePath}) -- ${o} other definition(s) share this name; qualify as <dir/leaf> to target another.`],r=t.candidates.slice(0,3);return r.length>0&&n.push(`Alternates: ${r.map(s=>`${s.shortName} (${s.relativePath}:${u(s.startLine)})`).join("; ")}`),n.push(""),n}var rt=S(({db:t,args:e,opts:o})=>{let n=b(e,0),r=p(o,"signatures"),s=M(t,n);if(p(o,"json")){C("outline",e,o,s);return}if(s.length===0)return d.empty(`No symbols found for "${n}".`);function i(D,f){for(let a of D){let c=" ".repeat(f),m=r&&a.signature?` - ${st(a.signature)}`:"";console.log(`${c}${B(a.startLine,a.endLine)} ${a.shortName}${m}`),i(a.children,f+1)}}i(s,0)});function st(t){return t.length>120?`${t.slice(0,117)}...`:t}var it=A("refs",({db:t,args:e,opts:o,budget:n})=>{let r=b(e,0),s=E(t,r,{semantic:n.semantic}).sort((h,J)=>h.relativePath.localeCompare(J.relativePath)||h.line-J.line),i=F(o,"cursor"),f=V(o,"limit")??(i?50:s.length),a=K(t),c=i?U(i,{command:"refs",target:r,indexGeneration:a}).offset:0;if(c>s.length)throw new Error("This cursor points past the current result set. Run again without --cursor.");let m=s.slice(c,c+f),I=c+m.length,g=I<s.length?{cursor:Q({command:"refs",target:r,offset:I,indexGeneration:a}),indexGeneration:a}:void 0,L={complete:c===0&&m.length===s.length,totalKnown:!0,returned:m.length,total:s.length,omitted:s.length-m.length,...g?{continuation:g}:{}};if(p(o,"json")){C("refs",e,o,O(t,r,m,"references"),{analysisBudget:n.analysisBudget,coverage:L});return}if(m.length===0)return d.empty($(t,r,"No references found."));P(t,r),d.groupedByFile(m,h=>` line ${u(h.line)}`),g&&console.log(`
|
|
3
|
+
${L.omitted} omitted; continue with --cursor ${g.cursor}`)}),at=S(({db:t,args:e,opts:o})=>{let n=b(e,0),r=G(t,n,{context:W(o,"context",0)});if(p(o,"json")){C("code",e,o,O(t,n,r,"code"));return}if(!r)return d.empty($(t,n,"Symbol found, but source was unreadable."));P(t,n),console.log(`${T(r.relativePath,r.startLine,r.endLine)} ${r.shortName} [${r.language??"unknown"}]
|
|
4
|
+
`);let s=r.source.split(`
|
|
5
|
+
`);for(let i=0;i<s.length;i++)console.log(` ${String(u(r.startLine+i)).padStart(4)} ${s[i]}`)}),Dt=[{id:"refs",command:"refs <symbol>",description:"Find all files referencing a symbol",options:H([l("--full","Run unbounded semantic analysis on large indexes"),l("-n, --limit <n>","Maximum reference sites to return",z),l("--cursor <cursor>","Continue a prior bounded result (implies --limit 50 when omitted)")]),budget:"semantic",agent:{answers:["Which files reference this symbol?","Is this symbol used anywhere, or only defined?"],returns:["referencing file paths","reference line numbers grouped by file"],inputs:["symbol"],coverage:"bounded",contrasts:[{command:"imported-by",distinction:"imported-by lists files importing the symbol; refs covers every reference site, imported or not."},{command:"affected",distinction:"refs is one hop out; affected is the transitive closure of what could break."}]},renderShape:"grouped-by-file",docs:x("Navigation",["scip-query refs login"]),handler:it},{id:"outline",command:"outline <file>",description:"Tree view of symbols in a file, with line ranges",agent:R("What symbols and nesting exist in this file?","symbol names, nesting, and line ranges",["file"],"complete"),options:w([l("--signatures","Show trimmed symbol signatures")]),renderShape:"custom",docs:x("Navigation"),handler:rt},{id:"code",command:"code <symbol>",description:"Read the source code for a symbol (bounded to its definition range)",agent:R("What is the compiler-resolved definition source for this symbol?","definition identity, source, and line range",["symbol"],"complete"),options:w([l("-C, --context <n>","Extra lines of context above/below",q,0)]),renderShape:"custom",docs:x("Navigation"),handler:at}];export{lt as a,q as b,z as c,ct as d,ut as e,l as f,X as g,Y as h,H as i,w as j,x as k,R as l,P as m,$ as n,O as o,et as p,Dt as q};
|
|
6
|
+
//# sourceMappingURL=chunk-XAGAZSFE.js.map
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as
|
|
3
|
-
`)}function
|
|
4
|
-
`)}catch{}}async function
|
|
2
|
+
import{a as _,b as j,c as T,d as R,i as g}from"./chunk-TW4OG5FC.js";import{Bc as a,Yc as k,Zc as f,_c as P,a as E,ad as x,bd as S,cd as V,h as v,i as D,j as w,ja as A,k as N,l as b,nd as H,ud as I,vd as U}from"./chunk-7UY7SD7D.js";import{program as m}from"commander";import{realpathSync as G}from"fs";import{fileURLToPath as pe}from"url";var B=new Set(["code","outline","refs"]);function J(e){return e!==void 0&&B.has(e)}async function M(e){if(J(e)){let{directNavigationQueryCommandDescriptors:n}=await import("./direct-navigation-DUCZCTOE.js"),o=n.find(r=>r.id===e);if(!o)throw new Error(`Direct navigation command descriptor is unavailable: ${e}`);return[o]}let{commandDescriptors:t}=await import("./command-descriptors-N2TL4XM2.js");return t}function O(e){return e.evidence?e.evidence:z.has(e.id)?"mixed":e.heuristic?"heuristic":"graph-fact"}var z=new Set(["diff-gate","health","plan-context","co-change"]);function $(e,t){return I(new Map(t.map(n=>[n.id,O(n)]))),U(new Map(t.flatMap(n=>n.agent?[[n.id,n.agent]]:[]))),t.map(n=>{let o=n.hidden?e.command(n.command,{hidden:!0}):e.command(n.command);o.description(n.description);for(let r of n.arguments??[])o.argument(r.name);for(let r of n.options??[])r.parser&&Object.hasOwn(r,"defaultValue")?o.option(r.flags,r.description,r.parser,r.defaultValue):r.parser?o.option(r.flags,r.description,r.parser):Object.hasOwn(r,"defaultValue")?o.option(r.flags,r.description,r.defaultValue):o.option(r.flags,r.description);return o.action(async(...r)=>{try{await n.handler(...r)}catch(i){K(i)}}),{descriptor:n,command:o}})}function K(e){let t=e instanceof Error?e.message:String(e);console.error(`error: ${t}`),process.exitCode=1}import{existsSync as Q,mkdirSync as X,readFileSync as Y,writeFileSync as Z}from"fs";import{homedir as ee}from"os";import{join as p}from"path";var ne=1440*60*1e3,F="update-check.json",te="https://registry.npmjs.org/scip-query/latest";async function h(e={}){let t=e.env??process.env;if(t.SCIP_QUERY_UPDATE_CHECK==="0"||t.NO_UPDATE_NOTIFIER||e.commandName&&re(e.commandName))return;let n=e.cacheDir??ae(t),o=e.now??Date.now(),r=e.currentVersion??a,i=ce(n),c=i&&o-i.checkedAt<ne?i.latestVersion:await se(n,e.fetchLatestVersion??de,o);if(!c||!ie(c,r))return;(e.writeNotice??(s=>console.error(s)))(oe(r,c))}function re(e){return e==="hook-context"||e==="hook-stop"}function oe(e,t){return[`scip-query update available: ${e} -> ${t}.`,"Agent: tell your human to update with: npm install -g scip-query@latest",""].join(`
|
|
3
|
+
`)}function ie(e,t){let n=L(e),o=L(t);if(!n||!o)return e!==t;for(let r=0;r<n.length;r++){let i=n[r]-o[r];if(i>0)return!0;if(i<0)return!1}return!1}function ae(e){let t=e.XDG_CACHE_HOME||p(ee(),".cache");return p(t,"scip-query")}function ce(e){let t=p(e,F);if(!Q(t))return null;try{let n=JSON.parse(Y(t,"utf8"));return typeof n.checkedAt=="number"&&(typeof n.latestVersion=="string"||n.latestVersion===null)?{checkedAt:n.checkedAt,latestVersion:n.latestVersion}:null}catch{return null}}async function se(e,t,n){let o;try{o=await t()}catch{o=null}return me(e,{checkedAt:n,latestVersion:o}),o}function me(e,t){try{X(e,{recursive:!0}),Z(p(e,F),`${JSON.stringify(t,null,2)}
|
|
4
|
+
`)}catch{}}async function de(){let e=await fetch(te,{signal:AbortSignal.timeout(1e3)});if(!e.ok)return null;let t=await e.json();return typeof t.version=="string"?t.version:null}function L(e){let t=/^v?(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(e);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}m.name("scip-query").description("Language-agnostic code intelligence CLI powered by SCIP indexes").version(a);var le=await M(W()?process.argv[2]:void 0);$(m,le);m.hook("preAction",async(e,t)=>{let n=t.name(),o=S(n),r=j(n);if(!o&&!r){q(),await h({commandName:n});return}let i=k(),c=A(i),l=P(i,c);f(l),q(),await h({commandName:n});let{config:s,paths:u}=l,C;if(r&&s.watch?.enabled===!0)try{C=_(R({projectRoot:i,cacheDir:u.cacheDir,cliVersion:a,gitContext:c}))}catch{}if(o){let y=x(i,s,u,{gitContext:c,watcherGeneration:C});y.kind==="failed"&&process.env.SCIP_QUERY_DEBUG&&console.error(`shared-cache: ${y.reason}`)}if(!r){g(i,a);return}let d=T({commandName:n,projectRoot:i,cacheDir:u.cacheDir,cliVersion:a,config:s,gitContext:c});d.kind==="failed"&&console.error(`warning: scip-query watch service did not start: ${d.message}`),(d.kind==="failed"||d.kind==="skipped")&&g(i,a)});m.hook("postAction",()=>f(void 0));function q(){if(w(),!v()||N())return;let e=null;try{e=V(t=>E(t))}catch{}b({command:D()??`scip-query ${process.argv.slice(2).join(" ")}`,toolVersion:a,projectFingerprint:e})}W()&&await m.parseAsync();function W(){if(!process.argv[1])return!1;let e=pe(import.meta.url);try{return G(e)===G(process.argv[1])}catch{return e===process.argv[1]}}export{m as program,H as renderHeuristicNotice};
|
|
5
5
|
//# sourceMappingURL=cli.js.map
|