@useanvil/claude-code 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/claude-hook-core.js +64 -64
- package/dist/claude-hook.js +17 -17
- package/dist/claude-sync.js +1 -1
- package/dist/cli/claude-main.js +18 -10
- package/package.json +1 -1
package/dist/claude-sync.js
CHANGED
|
@@ -11,7 +11,7 @@ import{existsSync as Bi,linkSync as Ki,readFileSync as zi,renameSync as Ji,statS
|
|
|
11
11
|
`,o);try{let s=JSON.parse(e.slice(o,l<0?void 0:l));if(s.type!==void 0&&s.type!=="user")continue;let a=Array.isArray(s.message?.content)?s.message.content:[],c=s.toolDenialKind;for(let u of i){let f=a.find(g=>g&&g.type==="tool_result"&&g.tool_use_id===u);if(!f)continue;(n.get(u)??n.set(u,[]).get(u)).push({refused:f.is_error===!0&&(typeof c=="string"?As.has(c):s.toolUseResult==="User rejected tool use")})}}catch{for(let s of i)(n.get(s)??n.set(s,[]).get(s)).push({refused:!1})}}return n}function mr(e,t){return!e||!t?null:Rs(j(e,4*1024*1024),t)}function Rs(e,t){let n=e.indexOf(`"tool_use_id":"${t}"`);if(n<0)return null;let r=e.slice(e.lastIndexOf(`
|
|
12
12
|
`,n)+1,e.indexOf(`
|
|
13
13
|
`,n)<0?void 0:e.indexOf(`
|
|
14
|
-
`,n));try{let o=JSON.parse(r),l=(Array.isArray(o.message?.content)?o.message.content:[]).find(c=>c.type==="tool_result"&&c.tool_use_id===t);if(!l)return null;let s=typeof l.content=="string"?l.content:JSON.stringify(l.content??"");return Cs(r,t)[0]?.refused===!0||l.is_error===!0&&/doesn't want to proceed with this tool use|The tool use was rejected/.test(s)?"no":"yes"}catch{return null}}import{createHash as pe}from"crypto";import{closeSync as ve,constants as _r,fstatSync as zs,mkdirSync as Js,openSync as Lr,readdirSync as qs,readSync as Lt,statSync as Vs,unlinkSync as $r}from"fs";import{join as W}from"path";var Os="https://api.anvilcontrol.ai";function Ot(e=process.env){let t=e.ANVIL_HOSTED_API_URL?.trim();return(t&&t.length>0?t:Os).replace(/\/+$/,"")}import{chmodSync as Ju,mkdirSync as qu,readFileSync as Es,writeFileSync as Vu}from"fs";import{homedir as Ns}from"os";import{dirname as Zu,join as Ps}from"path";function Ls(){return process.env.ANVIL_WORKSPACE_KEYS_PATH?.trim()||Ps(Ns(),".anvil","workspace-keys.json")}function js(e=Ls()){let t;try{t=JSON.parse(Es(e,"utf8"))}catch{return{}}if(!t||typeof t!="object")return{};let n={};for(let[r,o]of Object.entries(t))typeof o=="string"?o&&(n[r]={apiKey:o}):o&&typeof o=="object"&&typeof o.apiKey=="string"&&o.apiKey&&(n[r]=o);return n}var Is=new Set(["gmail","googlemail","outlook","hotmail","live","msn","yahoo","ymail","rocketmail","icloud","me","mac","proton","protonmail","pm","aol","gmx","mail","zoho","fastmail","hey","qq","foxmail","163","126","yandex"]);function Et(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ts(e){let t=e.lastIndexOf("@");if(t<=0||t===e.length-1)return Et(e)||"workspace";let n=e.slice(0,t),o=e.slice(t+1).split(".")[0]??"",i=Is.has(o.toLowerCase())?n:o;return Et(i)||Et(n)||"workspace"}function Ds(e){if(!e)return null;let t=Date.parse(e);return Number.isNaN(t)?null:Math.max(0,Math.floor((Date.now()-t)/864e5))}function yr(e){let n=Object.entries(js(e)).find(([,i])=>i.active===!0);if(!n)return null;let[r,o]=n;return{email:r,workspace:Ts(r),apiKey:o.apiKey,...o.apiBaseUrl?{apiBaseUrl:o.apiBaseUrl}:{},keyAgeDays:Ds(o.rememberedAt),...o.rememberedAt?{rememberedAt:o.rememberedAt}:{},...o.keyPrefix?{keyPrefix:o.keyPrefix}:{},...o.label?{label:o.label}:{},...o.workspaceId?{workspaceId:o.workspaceId}:{}}}import{accessSync as Ms,constants as Fs}from"fs";import{join as wr}from"path";var Ws=["hook-removed","hooks-disabled","settings-unreadable","no-node","classifier-missing","rules-missing","modes-changed","rules-changed","install-record-changed","key-missing","node-fallback","spool-unwritable","other"],Hs=/^claude\.[a-z0-9_]+(?:\.[a-z0-9_]+)*$/,Us=new Set(["hook-removed","hooks-disabled","settings-unreadable","no-node","classifier-missing","rules-missing"]),Bs=[[/^Anvil's seal key \(.*\) is missing/,"key-missing"],[/^modes\.json /,"modes-changed"],[/^compiled\.json /,"rules-changed"],[/^install\.json /,"install-record-changed"],[/\("disableAllHooks"\)/,"hooks-disabled"],[/^Anvil's hook was taken out of /,"hook-removed"],[/cannot be read, so Anvil cannot tell whether new sessions are checked/,"settings-unreadable"],[/^the Node Anvil was set up with is gone/,"node-fallback"],[/no Node 20 or later was found/,"no-node"],[/classifier (file is missing|did not load|answered a known call wrongly)/,"classifier-missing"],[/^no rules (are )?compiled/,"rules-missing"],[/cannot be written, so stops are not recorded/,"spool-unwritable"]];function br(e){for(let[t,n]of Bs)if(t.test(e))return n;return"other"}var Ks=1440*60*1e3;function kr(e){let t=Date.parse(e.trim());return Number.isFinite(t)?t:null}function vr(e){let{paths:t,now:n}=e,r=new Set,o=p=>{p&&r.add(br(p))},i=null;try{i=C(t)}catch{i=null}let l={};try{let p=Y(t,i);o(p.problem);for(let g of e.kinds.slice(0,64))g.length<=200&&Hs.test(g)&&(l[g]=ye.has(g)?"enforce":oe(p.value,g))}catch{}try{let p=Z(t,e.fallbackTable,i);o(p.problem),p.value||r.add("rules-missing")}catch{r.add("rules-missing")}let s=y(t.install,4*1024*1024)===!0;if(s)try{for(let p of He(t,i,e.home))o(p)}catch{}let a=e.hookBin??(s?t.bin:void 0);a&&y(wr(a,"claude-hook-core.js"),64*1024*1024)!==!0&&r.add("classifier-missing");try{Ms(y(t.decisions,Number.MAX_SAFE_INTEGER)===null?t.dir:t.decisions,Fs.W_OK)}catch{(y(t.dir,Number.MAX_SAFE_INTEGER)!==null||s)&&r.add("spool-unwritable")}let c=null;try{let p=Ue(t),g=p?kr(p.at):null;if(p&&g!==null&&(c=g,n-g<Ks))for(let d of p.problems)br(d)==="node-fallback"&&r.add("node-fallback")}catch{}let u=kr(j(wr(t.state,"no-node"),64));u!==null&&(c===null||u>c)&&(r.add("no-node"),c=u);let f=Ws.filter(p=>r.has(p));return{modes:l,ok:!f.some(p=>Us.has(p)),problems:f,hook_checked_at:c===null?null:new Date(c).toISOString()}}function xr(){try{return/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]{1,20})?$/.test("0.9.
|
|
14
|
+
`,n));try{let o=JSON.parse(r),l=(Array.isArray(o.message?.content)?o.message.content:[]).find(c=>c.type==="tool_result"&&c.tool_use_id===t);if(!l)return null;let s=typeof l.content=="string"?l.content:JSON.stringify(l.content??"");return Cs(r,t)[0]?.refused===!0||l.is_error===!0&&/doesn't want to proceed with this tool use|The tool use was rejected/.test(s)?"no":"yes"}catch{return null}}import{createHash as pe}from"crypto";import{closeSync as ve,constants as _r,fstatSync as zs,mkdirSync as Js,openSync as Lr,readdirSync as qs,readSync as Lt,statSync as Vs,unlinkSync as $r}from"fs";import{join as W}from"path";var Os="https://api.anvilcontrol.ai";function Ot(e=process.env){let t=e.ANVIL_HOSTED_API_URL?.trim();return(t&&t.length>0?t:Os).replace(/\/+$/,"")}import{chmodSync as Ju,mkdirSync as qu,readFileSync as Es,writeFileSync as Vu}from"fs";import{homedir as Ns}from"os";import{dirname as Zu,join as Ps}from"path";function Ls(){return process.env.ANVIL_WORKSPACE_KEYS_PATH?.trim()||Ps(Ns(),".anvil","workspace-keys.json")}function js(e=Ls()){let t;try{t=JSON.parse(Es(e,"utf8"))}catch{return{}}if(!t||typeof t!="object")return{};let n={};for(let[r,o]of Object.entries(t))typeof o=="string"?o&&(n[r]={apiKey:o}):o&&typeof o=="object"&&typeof o.apiKey=="string"&&o.apiKey&&(n[r]=o);return n}var Is=new Set(["gmail","googlemail","outlook","hotmail","live","msn","yahoo","ymail","rocketmail","icloud","me","mac","proton","protonmail","pm","aol","gmx","mail","zoho","fastmail","hey","qq","foxmail","163","126","yandex"]);function Et(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ts(e){let t=e.lastIndexOf("@");if(t<=0||t===e.length-1)return Et(e)||"workspace";let n=e.slice(0,t),o=e.slice(t+1).split(".")[0]??"",i=Is.has(o.toLowerCase())?n:o;return Et(i)||Et(n)||"workspace"}function Ds(e){if(!e)return null;let t=Date.parse(e);return Number.isNaN(t)?null:Math.max(0,Math.floor((Date.now()-t)/864e5))}function yr(e){let n=Object.entries(js(e)).find(([,i])=>i.active===!0);if(!n)return null;let[r,o]=n;return{email:r,workspace:Ts(r),apiKey:o.apiKey,...o.apiBaseUrl?{apiBaseUrl:o.apiBaseUrl}:{},keyAgeDays:Ds(o.rememberedAt),...o.rememberedAt?{rememberedAt:o.rememberedAt}:{},...o.keyPrefix?{keyPrefix:o.keyPrefix}:{},...o.label?{label:o.label}:{},...o.workspaceId?{workspaceId:o.workspaceId}:{}}}import{accessSync as Ms,constants as Fs}from"fs";import{join as wr}from"path";var Ws=["hook-removed","hooks-disabled","settings-unreadable","no-node","classifier-missing","rules-missing","modes-changed","rules-changed","install-record-changed","key-missing","node-fallback","spool-unwritable","other"],Hs=/^claude\.[a-z0-9_]+(?:\.[a-z0-9_]+)*$/,Us=new Set(["hook-removed","hooks-disabled","settings-unreadable","no-node","classifier-missing","rules-missing"]),Bs=[[/^Anvil's seal key \(.*\) is missing/,"key-missing"],[/^modes\.json /,"modes-changed"],[/^compiled\.json /,"rules-changed"],[/^install\.json /,"install-record-changed"],[/\("disableAllHooks"\)/,"hooks-disabled"],[/^Anvil's hook was taken out of /,"hook-removed"],[/cannot be read, so Anvil cannot tell whether new sessions are checked/,"settings-unreadable"],[/^the Node Anvil was set up with is gone/,"node-fallback"],[/no Node 20 or later was found/,"no-node"],[/classifier (file is missing|did not load|answered a known call wrongly)/,"classifier-missing"],[/^no rules (are )?compiled/,"rules-missing"],[/cannot be written, so stops are not recorded/,"spool-unwritable"]];function br(e){for(let[t,n]of Bs)if(t.test(e))return n;return"other"}var Ks=1440*60*1e3;function kr(e){let t=Date.parse(e.trim());return Number.isFinite(t)?t:null}function vr(e){let{paths:t,now:n}=e,r=new Set,o=p=>{p&&r.add(br(p))},i=null;try{i=C(t)}catch{i=null}let l={};try{let p=Y(t,i);o(p.problem);for(let g of e.kinds.slice(0,64))g.length<=200&&Hs.test(g)&&(l[g]=ye.has(g)?"enforce":oe(p.value,g))}catch{}try{let p=Z(t,e.fallbackTable,i);o(p.problem),p.value||r.add("rules-missing")}catch{r.add("rules-missing")}let s=y(t.install,4*1024*1024)===!0;if(s)try{for(let p of He(t,i,e.home))o(p)}catch{}let a=e.hookBin??(s?t.bin:void 0);a&&y(wr(a,"claude-hook-core.js"),64*1024*1024)!==!0&&r.add("classifier-missing");try{Ms(y(t.decisions,Number.MAX_SAFE_INTEGER)===null?t.dir:t.decisions,Fs.W_OK)}catch{(y(t.dir,Number.MAX_SAFE_INTEGER)!==null||s)&&r.add("spool-unwritable")}let c=null;try{let p=Ue(t),g=p?kr(p.at):null;if(p&&g!==null&&(c=g,n-g<Ks))for(let d of p.problems)br(d)==="node-fallback"&&r.add("node-fallback")}catch{}let u=kr(j(wr(t.state,"no-node"),64));u!==null&&(c===null||u>c)&&(r.add("no-node"),c=u);let f=Ws.filter(p=>r.has(p));return{modes:l,ok:!f.some(p=>Us.has(p)),problems:f,hook_checked_at:c===null?null:new Date(c).toISOString()}}function xr(){try{return/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]{1,20})?$/.test("0.9.1")?"0.9.1":null}catch{return null}}var Gs=50,Ys=50,Zs=1e4,xe=512*1024,Pt=30*6e4,Xs="/v1/claude-code/machine",jr=360*6e4,Qs=_({confirmation_required:"confirmation_required",service_in_blocklist:"service_in_blocklist",resource_mutation_rate_exceeded:"resource_mutation_rate_exceeded",allowlist:"allowlist",spend_per_user:"spend_per_user",time_limit:"anvil_unavailable"});function Je(e,t){let n=null;try{let i=ar(e,t);y(i,1024*1024)===!0&&(n=yr(i))}catch{n=null}if(n?.apiKey){let i=n.workspaceId?`ws:${pe("sha256").update(n.workspaceId).digest("hex").slice(0,12)}`:Ar(n.apiKey);return{apiKey:n.apiKey,baseUrl:Sr(n.apiBaseUrl||Ot(e)),id:i,linkedAt:n.rememberedAt??null,source:"login"}}let r=e.ANVIL_API_KEY?.trim(),o=e.ANVIL_API_BASE_URL?.trim();return r?{apiKey:r,baseUrl:Sr(o||Ot(e)),id:Ar(r),linkedAt:null,source:"env"}:null}function Sr(e){return e.replace(/\/+$/,"")}function Ar(e){return`sha256:${pe("sha256").update(e).digest("hex").slice(0,12)}`}function Cr(e){return e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/\.(local|lan|home|localdomain)$/,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"")||"machine"}function ei(e){return W(e.dir,"machine.json")}function jt(e,t){let n=b(ei(e))?.label;return Cr(typeof n=="string"&&n?n:t)}var de=e=>typeof e=="string"&&e.length>0?e:null;function ti(e,t){return e===null||e==="hold-risky-actions"||Oe[e]?Ee(e,t):"your-rule"}function ni(e){if(!e)return"none";let t=e.replace(/-/g,"").toLowerCase();return/^[a-f0-9]{8,}$/.test(t)?t.slice(0,8):pe("sha256").update(e).digest("hex").slice(0,8)}function Ir(e,t){let n;try{n=JSON.parse(e)}catch{return null}if(!n||typeof n!="object"||n.v!==1)return null;let r=de(n.action),o=n.verdict,i=n.mode,l=de(n.ts);if(!r||!r.startsWith("claude.")||r.length>200||o!=="hold"&&o!=="block"||i!=="ghost"&&i!=="enforce"||n.delivered==="approved"||!l||!Number.isFinite(Date.parse(l)))return null;let s=Qs[de(n.blocked_by)??""];if(!s)return null;let a=i==="ghost"?"would_block":o==="hold"?"held":"blocked",u=de(n.blocked_by)==="time_limit"?i==="ghost"?"Not checked in time":"Held: could not be checked in time":a==="held"?"Held for your OK":a==="blocked"?"Blocked":o==="hold"?"Would have held":"Would have blocked",f=typeof n.ms=="number"&&Number.isFinite(n.ms)&&n.ms>=0?Math.round(n.ms):0;return{key:`cc/${t}/${ni(de(n.session))}/${pe("sha256").update(e).digest("hex").slice(0,12)}`,action:r,decided_by:"claude_code_hook",outcome:a,mode:i,blocked_by:s,reason:`${u} \xB7 ${Ne(r)}`,rule_id:ti(de(n.rule),r),decided_at:new Date(Date.parse(l)).toISOString(),duration_ms:Math.min(f,6e5)}}function Rr(e,t=null){return{v:2,identity:e,since:t,offset:0,ino:0,last_hash:null,registered:!1,registered_kinds:[],sent:0,rejected:0,last_push_ok:null,last_pull_ok:null,last_error:null,last_note:null,failures:0,next_try_at:0,report_next_at:0,last_report_ok:null,window_start:0,window_sent:0,skip:[],source:null,linked_at:null,last_pass_at:null}}function Tr(e,t){return W(e.state,"sync",`${pe("sha256").update(t).digest("hex").slice(0,16)}.json`)}function Dr(e){return W(e.state,"signed-out.json")}function ze(e){let t=b(Dr(e)),n=o=>typeof o=="string"&&Number.isFinite(Date.parse(o))?o:null,r=Array.isArray(t?.windows)?t.windows.filter(o=>Array.isArray(o)&&o.length===2&&n(o[0])!==null&&n(o[1])!==null):[];return{open:n(t?.open)??n(t?.at),windows:r}}function Mr(e,t,n,r){A(e.state);let o=n.filter(i=>r-Date.parse(i[1])<400*864e5).slice(-500);O(Dr(e),`${JSON.stringify(t!==null?{open:t,windows:o}:{windows:o})}
|
|
15
15
|
`)}function Fr(e,t){try{let n=ze(e);n.open===null&&Mr(e,new Date(t).toISOString(),n.windows,t)}catch{}}function ri(e,t){try{let n=ze(e);n.open!==null&&Date.parse(n.open)<=t&&Mr(e,null,[...n.windows,[n.open,new Date(t).toISOString()]],t)}catch{}}function Wr(e){let t=[];try{t=qs(W(e.state,"sync")).filter(n=>n.endsWith(".json"))}catch{return null}for(let n of t){let r=b(W(e.state,"sync",n)),o=typeof r?.last_pull_ok=="string"?Date.parse(r.last_pull_ok):NaN;if(typeof r?.identity=="string"&&r.source==="env"&&Number.isFinite(o))return r.identity}return null}function $e(e,t,n=Date.now()){let r=b(Tr(e,t));if(!r||r.v!==2||r.identity!==t)return Rr(t);let o={...Rr(t),...r,v:2,identity:t},i=Number.isFinite(o.next_try_at)?Math.min(o.next_try_at,n+Pt):0,l=typeof o.report_next_at=="number"&&Number.isFinite(o.report_next_at)?Math.min(o.report_next_at,n+jr):0,s=Number.isFinite(o.window_start)&&o.window_start<=n?o.window_start:0,a=Array.isArray(o.skip)?o.skip.filter(f=>Array.isArray(f)&&f.length===2&&f.every(p=>typeof p=="string"&&Number.isFinite(Date.parse(p)))).slice(-500):[],c=f=>typeof f=="string"&&Number.isFinite(Date.parse(f))?f:null,u=Array.isArray(o.registered_kinds)?o.registered_kinds.filter(f=>typeof f=="string").slice(0,256):[];return{...o,next_try_at:i,report_next_at:l,last_report_ok:c(o.last_report_ok),window_start:s,window_sent:s===0?0:o.window_sent,skip:a,linked_at:c(o.linked_at),last_pass_at:c(o.last_pass_at),registered_kinds:u}}function oi(e,t){let n=Tr(e,t.identity);Js(W(e.state,"sync"),{recursive:!0,mode:448}),O(n,`${JSON.stringify(t,null,2)}
|
|
16
16
|
`)}function It(e){return W(e.state,"mode-pending.json")}function si(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.action=="string"&&t.action.startsWith("claude.")&&(t.mode==="ghost"||t.mode==="enforce")&&typeof t.at=="string"&&typeof t.identity=="string"&&(t.from===null||t.from==="ghost"||t.from==="enforce")&&(t.origin===void 0||t.origin==="link")}function fe(e){let t=b(It(e));return{v:2,changes:Array.isArray(t?.changes)?t.changes.filter(si):[]}}var Q=e=>`${e.identity}|${e.action}|${e.at}`;function Hr(e,t){A(e.state);let n=W(e.state,"mode-pending.lock"),r=!1;for(let o=0;o<40&&!r;o++)try{ve(Lr(n,"wx",384)),r=!0}catch{try{Date.now()-Vs(n).mtimeMs>1e4&&$r(n)}catch{}let i=Date.now()+25;for(;Date.now()<i;);}try{return t()}finally{if(r)try{$r(n)}catch{}}}function ii(e,t){t.length!==0&&Hr(e,()=>{let n=fe(e).changes,r=(l,s)=>l.identity===s.identity&&l.action===s.action,o=t.map(l=>{let s=n.find(a=>r(a,l));return s?{...l,from:s.from}:l}),i=n.filter(l=>!t.some(s=>r(l,s)));O(It(e),`${JSON.stringify({v:2,changes:[...i,...o]},null,2)}
|
|
17
17
|
`)})}function li(e,t){t.size!==0&&Hr(e,()=>{let n=fe(e).changes.filter(r=>!t.has(Q(r)));O(It(e),`${JSON.stringify({v:2,changes:n},null,2)}
|
package/dist/cli/claude-main.js
CHANGED
|
@@ -11976,7 +11976,7 @@ function machineHealth(input) {
|
|
|
11976
11976
|
}
|
|
11977
11977
|
function anvilVersion() {
|
|
11978
11978
|
try {
|
|
11979
|
-
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]{1,20})?$/.test("0.9.
|
|
11979
|
+
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]{1,20})?$/.test("0.9.1") ? "0.9.1" : null;
|
|
11980
11980
|
} catch {
|
|
11981
11981
|
return null;
|
|
11982
11982
|
}
|
|
@@ -13707,12 +13707,12 @@ function readWindowsProcesses() {
|
|
|
13707
13707
|
function readProcesses(platform = process.platform) {
|
|
13708
13708
|
if (platform === "win32") return process.platform === "win32" ? readWindowsProcesses() : null;
|
|
13709
13709
|
if (platform === "linux") return null;
|
|
13710
|
-
const r = spawnSync5("/bin/ps", ["-axww", "-o", "pid=,ppid=,comm="], { encoding: "utf8", timeout: 3e3, maxBuffer: 16 * 1024 * 1024 });
|
|
13710
|
+
const r = spawnSync5("/bin/ps", ["-axww", "-o", "pid=,ppid=,tty=,comm="], { encoding: "utf8", timeout: 3e3, maxBuffer: 16 * 1024 * 1024 });
|
|
13711
13711
|
if (r.status !== 0 || typeof r.stdout !== "string") return null;
|
|
13712
13712
|
const rows = [];
|
|
13713
13713
|
for (const line of r.stdout.split("\n")) {
|
|
13714
|
-
const m = /^\s*(\d+)\s+(\d+)\s+(.+?)\s*$/.exec(line);
|
|
13715
|
-
if (m) rows.push({ pid: Number(m[1]), ppid: Number(m[2]), program: m[3] });
|
|
13714
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.+?)\s*$/.exec(line);
|
|
13715
|
+
if (m) rows.push({ pid: Number(m[1]), ppid: Number(m[2]), program: m[4], tty: m[3] === "??" || m[3] === "-" ? null : m[3] });
|
|
13716
13716
|
}
|
|
13717
13717
|
return rows.length > 0 ? rows : null;
|
|
13718
13718
|
}
|
|
@@ -13720,7 +13720,9 @@ function procParent(pid) {
|
|
|
13720
13720
|
try {
|
|
13721
13721
|
const stat2 = readFileSync14(`/proc/${pid}/stat`, "utf8");
|
|
13722
13722
|
const close = stat2.lastIndexOf(")");
|
|
13723
|
-
const
|
|
13723
|
+
const fields = stat2.slice(close + 2).split(" ");
|
|
13724
|
+
const ppid = Number(fields[1]);
|
|
13725
|
+
const ttyNr = Number(fields[4]);
|
|
13724
13726
|
const name = stat2.slice(stat2.indexOf("(") + 1, close);
|
|
13725
13727
|
let program2 = name;
|
|
13726
13728
|
try {
|
|
@@ -13728,7 +13730,7 @@ function procParent(pid) {
|
|
|
13728
13730
|
} catch {
|
|
13729
13731
|
}
|
|
13730
13732
|
if (posix4.basename(program2) !== name && name === "claude") program2 = name;
|
|
13731
|
-
return Number.isFinite(ppid) ? { pid, ppid, program: program2 } : null;
|
|
13733
|
+
return Number.isFinite(ppid) ? { pid, ppid, program: program2, ...Number.isFinite(ttyNr) ? { tty: ttyNr === 0 ? null : String(ttyNr) } : {} } : null;
|
|
13732
13734
|
} catch {
|
|
13733
13735
|
return null;
|
|
13734
13736
|
}
|
|
@@ -13756,6 +13758,8 @@ function claudeCodeParent(deps = {}) {
|
|
|
13756
13758
|
const seen = /* @__PURE__ */ new Set();
|
|
13757
13759
|
let top = null;
|
|
13758
13760
|
let reachedInit = false;
|
|
13761
|
+
let terminal = false;
|
|
13762
|
+
let terminalRead = false;
|
|
13759
13763
|
for (let steps = 0; steps < 128 && pid >= 1 && !seen.has(pid); steps++) {
|
|
13760
13764
|
seen.add(pid);
|
|
13761
13765
|
const row2 = rowOf2(pid);
|
|
@@ -13771,11 +13775,14 @@ function claudeCodeParent(deps = {}) {
|
|
|
13771
13775
|
break;
|
|
13772
13776
|
}
|
|
13773
13777
|
if (row2.pid === 1) break;
|
|
13778
|
+
if (row2.tty !== void 0) terminalRead = true;
|
|
13779
|
+
if (row2.tty) terminal = true;
|
|
13774
13780
|
top = row2;
|
|
13775
13781
|
pid = row2.ppid;
|
|
13776
13782
|
}
|
|
13777
|
-
const
|
|
13778
|
-
|
|
13783
|
+
const opened = reachedInit && top !== null && terminalRead && !terminal && OPENED.test(top.program);
|
|
13784
|
+
const detached = reachedInit && (top === null || LOOSE.has(plainName(top.program))) || opened;
|
|
13785
|
+
return { found: null, unknown: false, detached, ...detached && top !== null && MAKES_A_TERMINAL.has(plainName(top.program)) ? { madeTerminal: true } : {}, ...opened ? { opened: true } : {} };
|
|
13779
13786
|
}
|
|
13780
13787
|
function insideClaudeCode(env, deps = {}) {
|
|
13781
13788
|
if (sessionMarker(env) !== null) return { inside: true, how: "marker", parent: null, parentsUnknown: false };
|
|
@@ -13783,11 +13790,11 @@ function insideClaudeCode(env, deps = {}) {
|
|
|
13783
13790
|
const parents = claudeCodeParent(deps);
|
|
13784
13791
|
const { found, unknown, detached } = parents;
|
|
13785
13792
|
if (found) return { inside: true, how: "parent", parent: found, parentsUnknown: false };
|
|
13786
|
-
if (detached && (deps.stdinTTY !== true || parents.madeTerminal === true)) return { inside: true, how: "detached", parent: null, parentsUnknown: false };
|
|
13793
|
+
if (detached && (deps.stdinTTY !== true || parents.madeTerminal === true || parents.opened === true)) return { inside: true, how: "detached", parent: null, parentsUnknown: false };
|
|
13787
13794
|
if (unknown && (deps.platform ?? process.platform) === "win32" && deps.stdinTTY !== true) return { inside: true, how: "detached", parent: null, parentsUnknown: true };
|
|
13788
13795
|
return { inside: false, how: null, parent: null, parentsUnknown: unknown };
|
|
13789
13796
|
}
|
|
13790
|
-
var SESSION_MARKERS, SCRIPT_RUNNERS, lastName, windowsLines, FIRST, LOOSE, MAKES_A_TERMINAL, WINDOWS_HOSTS, plainName;
|
|
13797
|
+
var SESSION_MARKERS, SCRIPT_RUNNERS, lastName, windowsLines, FIRST, LOOSE, OPENED, MAKES_A_TERMINAL, WINDOWS_HOSTS, plainName;
|
|
13791
13798
|
var init_inside_claude = __esm({
|
|
13792
13799
|
"src/coding-agents/claude-code/inside-claude.ts"() {
|
|
13793
13800
|
"use strict";
|
|
@@ -13849,6 +13856,7 @@ var init_inside_claude = __esm({
|
|
|
13849
13856
|
"tclsh",
|
|
13850
13857
|
"lua"
|
|
13851
13858
|
]);
|
|
13859
|
+
OPENED = /\.app\/Contents\/MacOS\/|^\/(?:private\/)?(?:tmp|var\/folders)\//;
|
|
13852
13860
|
MAKES_A_TERMINAL = /* @__PURE__ */ new Set(["script", "expect", "unbuffer", "empty", "pty", "socat"]);
|
|
13853
13861
|
WINDOWS_HOSTS = /* @__PURE__ */ new Set(["svchost", "services", "wininit", "wmiprvse", "taskhostw", "taskhost", "taskeng", "smss", "csrss", "winlogon", "lsass", "system", "wsmprovhost"]);
|
|
13854
13862
|
plainName = (program2) => lastName(program2).replace(/\.exe$/i, "").replace(/^-/, "").replace(/[\d.]+$/, "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useanvil/claude-code",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Anvil for Claude Code on its own: it checks every action Claude Code takes and stops the risky few before they run. Its own command, `anvil-claude`, so it installs beside @useanvil/sdk (`anvil`) and never takes the SDK's.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|