@agenttrail/cli 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{$,A as N,Aa as Ne,B as _,Ba as _e,C as x,Ca as xe,D as O,Da as Oe,E as h,F as G,G as k,H as v,I as D,J as U,K as F,L as b,M as j,N as B,O as M,P as w,Q as V,R as J,S as K,T as W,U as z,V as H,W as Q,X as q,Y as X,Z as Y,_ as Z,a as e,aa as ee,b as t,ba as te,c as o,ca as oe,d as r,da as re,e as n,ea as ne,f as p,fa as pe,g as i,ga as ie,h as s,ha as se,i as l,ia as le,j as a,ja as ae,k as u,ka as ue,l as c,la as ce,m as y,ma as ye,n as f,na as fe,o as S,oa as Se,p as d,pa as de,q as T,qa as Te,r as I,ra as Ie,s as m,sa as me,t as E,ta as Ee,u as R,ua as Re,v as C,va as Ce,w as g,wa as ge,x as A,xa as Ae,y as P,ya as Pe,z as L,za as Le}from"./chunk-77RT6DZY.js";export{t as AGENTTRAIL_AGENT_NS,d as AGENTTRAIL_API_ENDPOINT,o as AGENTTRAIL_INGEST_ENDPOINT,Se as AGENTTRAIL_MARKETPLACE_NAME,Te as AGENTTRAIL_PLUGIN_ID,de as AGENTTRAIL_PLUGIN_NAME,e as AGENTTRAIL_PROJECT_NS,n as CLAUDE_CODE_VENDOR_SLUG,p as CONTENT_FLAGS,Ee as ClaudeCliNotFoundError,R as DEFAULT_LOCK_STALE_MS,Ie as MIN_CLAUDE_VERSION,P as PROJECT_CONFIG_FILE,Ce as PluginCommandError,Re as PluginUnsupportedError,oe as QuarantineError,w as REFRESH_STALE_WINDOW_MS,g as agenttrailConfigSchema,$ as backfillSpanId,Z as backfillTraceId,ue as boundedPool,l as buildEnvBlock,s as buildResourceAttributes,ee as buildSpanTree,W as checkpointPath,S as clearCredentials,b as computeAgentId,F as computeProjectId,c as credentialsPath,me as defaultClaudeRunner,pe as defaultProjectsRoot,D as deriveProjectIdentity,U as deriveProjectSlug,i as encodeResourceValue,Pe as ensureClaudeSupportsPlugins,j as ensureGitignored,re as fileLineSource,_ as findGitRoot,N as findProjectConfig,L as globalConfigPath,Y as hashContent,X as hashFile,Ne as installAgentTrailPlugin,ie as isSessionInProject,Ae as isVersionAtLeast,r as normalizeEndpoint,A as parseAgentTrailConfig,ge as parseClaudeVersion,k as parseGitRemote,ne as parseSession,I as pollDeviceToken,y as readCredentials,v as readGitRemote,z as readState,m as refreshDeviceToken,h as resolveApiKey,O as resolveConfig,Le as resolvePluginScaffoldDir,x as resolveProjectRoot,E as revokeDeviceToken,Oe as run,fe as runImport,V as runLogin,K as runLogout,J as runRefresh,ce as runScan,xe as runSetup,ye as runStatus,se as scanTranscripts,te as sessionToResourceSpans,a as settingsPath,q as shouldProcess,G as slugify,T as startDeviceAuth,le as toOtlpJson,_e as uninstallAgentTrailPlugin,ae as uploadResourceSpans,Q as upsertSession,C as withRefreshLock,B as writeAgentTrailConfig,u as writeClaudeSettings,f as writeCredentials,M as writeGlobalConfig,H as writeState};
1
+ import{$,A as N,Aa as Ne,B as _,Ba as _e,C as x,Ca as xe,D as O,Da as Oe,E as h,F as G,G as k,H as v,I as D,J as U,K as F,L as b,M as j,N as B,O as M,P as w,Q as V,R as J,S as K,T as W,U as z,V as H,W as Q,X as q,Y as X,Z as Y,_ as Z,a as e,aa as ee,b as t,ba as te,c as o,ca as oe,d as r,da as re,e as n,ea as ne,f as p,fa as pe,g as i,ga as ie,h as s,ha as se,i as l,ia as le,j as a,ja as ae,k as u,ka as ue,l as c,la as ce,m as y,ma as ye,n as f,na as fe,o as S,oa as Se,p as d,pa as de,q as T,qa as Te,r as I,ra as Ie,s as m,sa as me,t as E,ta as Ee,u as R,ua as Re,v as C,va as Ce,w as g,wa as ge,x as A,xa as Ae,y as P,ya as Pe,z as L,za as Le}from"./chunk-Q7QL7XER.js";export{t as AGENTTRAIL_AGENT_NS,d as AGENTTRAIL_API_ENDPOINT,o as AGENTTRAIL_INGEST_ENDPOINT,Se as AGENTTRAIL_MARKETPLACE_NAME,Te as AGENTTRAIL_PLUGIN_ID,de as AGENTTRAIL_PLUGIN_NAME,e as AGENTTRAIL_PROJECT_NS,n as CLAUDE_CODE_VENDOR_SLUG,p as CONTENT_FLAGS,Ee as ClaudeCliNotFoundError,R as DEFAULT_LOCK_STALE_MS,Ie as MIN_CLAUDE_VERSION,P as PROJECT_CONFIG_FILE,Ce as PluginCommandError,Re as PluginUnsupportedError,oe as QuarantineError,w as REFRESH_STALE_WINDOW_MS,g as agenttrailConfigSchema,$ as backfillSpanId,Z as backfillTraceId,ue as boundedPool,l as buildEnvBlock,s as buildResourceAttributes,ee as buildSpanTree,W as checkpointPath,S as clearCredentials,b as computeAgentId,F as computeProjectId,c as credentialsPath,me as defaultClaudeRunner,pe as defaultProjectsRoot,D as deriveProjectIdentity,U as deriveProjectSlug,i as encodeResourceValue,Pe as ensureClaudeSupportsPlugins,j as ensureGitignored,re as fileLineSource,_ as findGitRoot,N as findProjectConfig,L as globalConfigPath,Y as hashContent,X as hashFile,Ne as installAgentTrailPlugin,ie as isSessionInProject,Ae as isVersionAtLeast,r as normalizeEndpoint,A as parseAgentTrailConfig,ge as parseClaudeVersion,k as parseGitRemote,ne as parseSession,I as pollDeviceToken,y as readCredentials,v as readGitRemote,z as readState,m as refreshDeviceToken,h as resolveApiKey,O as resolveConfig,Le as resolvePluginScaffoldDir,x as resolveProjectRoot,E as revokeDeviceToken,Oe as run,fe as runImport,V as runLogin,K as runLogout,J as runRefresh,ce as runScan,xe as runSetup,ye as runStatus,se as scanTranscripts,te as sessionToResourceSpans,a as settingsPath,q as shouldProcess,G as slugify,T as startDeviceAuth,le as toOtlpJson,_e as uninstallAgentTrailPlugin,ae as uploadResourceSpans,Q as upsertSession,C as withRefreshLock,B as writeAgentTrailConfig,u as writeClaudeSettings,f as writeCredentials,M as writeGlobalConfig,H as writeState};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenttrail/cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "description": "The AgentTrail command-line tool: connects an AI coding agent's sessions to AgentTrail, with setup, sign-in, status and history import for the agent named by --agent.",
6
6
  "license": "Apache-2.0",
@@ -6,14 +6,14 @@
6
6
  },
7
7
  "metadata": {
8
8
  "description": "AgentTrail's plugin marketplace — the enforcement plugin for agent governance.",
9
- "version": "0.2.5"
9
+ "version": "0.2.6"
10
10
  },
11
11
  "plugins": [
12
12
  {
13
13
  "name": "agenttrail",
14
14
  "source": "./",
15
15
  "description": "AgentTrail enforcement plugin — PreToolUse governance hook (a fail-closed command shim).",
16
- "version": "0.2.5",
16
+ "version": "0.2.6",
17
17
  "author": {
18
18
  "name": "AgentTrail"
19
19
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agenttrail",
3
3
  "description": "AgentTrail enforcement plugin for Claude Code — carries the PreToolUse governance hook, a fail-closed command shim.",
4
- "version": "0.2.5",
4
+ "version": "0.2.6",
5
5
  "author": {
6
6
  "name": "AgentTrail",
7
7
  "url": "https://agenttrail.sh"
@@ -2855,9 +2855,9 @@ function resolveWorkspacePath(path, realpath = realpathSync2.native) {
2855
2855
  function lookupCursorWorkspace(query) {
2856
2856
  const read = readRegistry(query.home, query.io ?? nodeCaptureFileIO);
2857
2857
  if (read.kind !== "ok") return { kind: "registry-unreadable", reason: read.kind };
2858
- const resolve2 = (path) => resolveWorkspacePath(path, query.realpath);
2859
- const roots = query.workspaceRoots.filter((path) => path !== "").map(resolve2);
2860
- const projectDir = query.projectDirEnv === void 0 ? void 0 : resolve2(query.projectDirEnv);
2858
+ const resolve3 = (path) => resolveWorkspacePath(path, query.realpath);
2859
+ const roots = query.workspaceRoots.filter((path) => path !== "").map(resolve3);
2860
+ const projectDir = query.projectDirEnv === void 0 ? void 0 : resolve3(query.projectDirEnv);
2861
2861
  const record = findProjectForWorkspace2(read.registry, roots, projectDir);
2862
2862
  if (record === void 0) {
2863
2863
  const damaged = skippedRecordsForWorkspace(read.skipped, roots, projectDir);
@@ -4806,6 +4806,157 @@ function queueOfflineDecision(snapshotPath, d, opts = {}) {
4806
4806
  }
4807
4807
  }
4808
4808
 
4809
+ // src/pep/trusted-env.ts
4810
+ import { readdirSync as readdirSync3, readFileSync as readFileSync6, realpathSync as realpathSync3 } from "fs";
4811
+ import { dirname as dirname5, isAbsolute, join as join8, resolve as resolve2 } from "path";
4812
+ var PROJECT_IGNORED_PEP_KEYS = [
4813
+ ENV_PEP_URL,
4814
+ ENV_PEP_HOLD_URL,
4815
+ ENV_PEP_SNAPSHOT_URL,
4816
+ ENV_PEP_TOKEN,
4817
+ ENV_PEP_SNAPSHOT_PATH,
4818
+ ENV_PEP_TIMEOUT_MS,
4819
+ ENV_PEP_ORG_ID,
4820
+ ENV_PEP_ENFORCE
4821
+ ];
4822
+ function managedSettingsFiles(platform = process.platform, listDir = (dir) => readdirSync3(dir)) {
4823
+ const dir = platform === "darwin" ? "/Library/Application Support/ClaudeCode" : platform === "win32" ? "C:\\Program Files\\ClaudeCode" : "/etc/claude-code";
4824
+ const paths = [join8(dir, "managed-settings.json")];
4825
+ try {
4826
+ const dropIns = join8(dir, "managed-settings.d");
4827
+ for (const name of listDir(dropIns).sort()) {
4828
+ if (name.endsWith(".json")) paths.push(join8(dropIns, name));
4829
+ }
4830
+ } catch {
4831
+ }
4832
+ return paths;
4833
+ }
4834
+ function readEnv(path, read) {
4835
+ let text;
4836
+ try {
4837
+ text = read(path);
4838
+ } catch {
4839
+ return { kind: "missing" };
4840
+ }
4841
+ try {
4842
+ const parsed = JSON.parse(text);
4843
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
4844
+ return { kind: "unparseable" };
4845
+ }
4846
+ const block = parsed.env;
4847
+ if (block === void 0) return { kind: "ok", env: {} };
4848
+ if (typeof block !== "object" || block === null || Array.isArray(block)) {
4849
+ return { kind: "unparseable" };
4850
+ }
4851
+ const env = {};
4852
+ for (const [key, value] of Object.entries(block)) {
4853
+ env[key] = typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" ? String(value) : JSON.stringify(value);
4854
+ }
4855
+ return { kind: "ok", env };
4856
+ } catch {
4857
+ return { kind: "unparseable" };
4858
+ }
4859
+ }
4860
+ function safeRealpath(path, realpath) {
4861
+ try {
4862
+ return realpath(path);
4863
+ } catch {
4864
+ return resolve2(path);
4865
+ }
4866
+ }
4867
+ function committedSettingsFolders(opts) {
4868
+ return foldersFrom([opts.claudeProjectDir, ...opts.projectDirs], opts);
4869
+ }
4870
+ function foldersFrom(starts, opts) {
4871
+ const realpath = opts.realpath ?? realpathSync3.native;
4872
+ const home = safeRealpath(opts.home, realpath);
4873
+ const seen = /* @__PURE__ */ new Set();
4874
+ const folders = [];
4875
+ for (const start of starts) {
4876
+ if (start === void 0 || start.trim() === "") continue;
4877
+ let dir = safeRealpath(start, realpath);
4878
+ for (; ; ) {
4879
+ if (dir === home || seen.has(dir)) break;
4880
+ seen.add(dir);
4881
+ folders.push(dir);
4882
+ const parent = dirname5(dir);
4883
+ if (parent === dir) break;
4884
+ dir = parent;
4885
+ }
4886
+ }
4887
+ return folders;
4888
+ }
4889
+ function setByRepo(committed, key) {
4890
+ return committed.some(
4891
+ (file) => file.kind === "unparseable" || file.kind === "ok" && key in file.env
4892
+ );
4893
+ }
4894
+ function localRoot(opts, committed) {
4895
+ const realpath = opts.realpath ?? realpathSync3.native;
4896
+ const dir = opts.claudeProjectDir?.trim();
4897
+ if (dir !== void 0 && dir !== "") {
4898
+ if (!isAbsolute(dir) || setByRepo(committed, "CLAUDE_PROJECT_DIR")) return void 0;
4899
+ return safeRealpath(dir, realpath);
4900
+ }
4901
+ const first = opts.projectDirs.find((d) => d !== void 0 && d.trim() !== "");
4902
+ return first === void 0 ? void 0 : safeRealpath(first, realpath);
4903
+ }
4904
+ function userSettingsFile(opts, committed) {
4905
+ const dir = opts.claudeConfigDir?.trim();
4906
+ const trusted = dir !== void 0 && dir !== "" && isAbsolute(dir) && !setByRepo(committed, "CLAUDE_CONFIG_DIR");
4907
+ return join8(trusted ? dir : join8(opts.home, ".claude"), "settings.json");
4908
+ }
4909
+ function trustedPepEnv(env, opts) {
4910
+ const read = opts.read ?? ((p) => readFileSync6(p, "utf8"));
4911
+ const committedPaths = committedSettingsFolders(opts).map(
4912
+ (dir) => join8(dir, ".claude", "settings.json")
4913
+ );
4914
+ const committed = committedPaths.map((path) => readEnv(path, read));
4915
+ const anyUnparseable = committed.some((file) => file.kind === "unparseable");
4916
+ const committedValues = (key) => committed.flatMap((file) => file.kind === "ok" && key in file.env ? [file.env[key]] : []);
4917
+ const root = localRoot(opts, committed);
4918
+ const trustedFiles = [
4919
+ ...opts.managedPaths ?? managedSettingsFiles(),
4920
+ ...root === void 0 ? [] : [join8(root, ".claude", "settings.local.json")],
4921
+ userSettingsFile(opts, committed)
4922
+ ];
4923
+ let trusted;
4924
+ const trustedValue = (key) => {
4925
+ trusted ??= trustedFiles.map((path) => readEnv(path, read));
4926
+ for (const file of trusted) {
4927
+ if (file.kind === "ok" && key in file.env) return file.env[key];
4928
+ }
4929
+ return void 0;
4930
+ };
4931
+ const out = { ...env };
4932
+ const ignored = [];
4933
+ for (const key of PROJECT_IGNORED_PEP_KEYS) {
4934
+ const current = env[key];
4935
+ if (current === void 0) continue;
4936
+ if (!anyUnparseable && !committedValues(key).includes(current)) continue;
4937
+ const replacement = trustedValue(key);
4938
+ if (replacement === current) continue;
4939
+ if (replacement === void 0) delete out[key];
4940
+ else out[key] = replacement;
4941
+ ignored.push(key);
4942
+ }
4943
+ if (anyUnparseable && out[ENV_PEP_ENFORCE]?.trim() !== "1") {
4944
+ const wellFormed = committed.filter((file) => file.kind !== "unparseable");
4945
+ const ownRoot = localRoot(opts, wellFormed);
4946
+ const files = [
4947
+ ...opts.managedPaths ?? managedSettingsFiles(),
4948
+ ...ownRoot === void 0 ? [] : [join8(ownRoot, ".claude", "settings.local.json")],
4949
+ userSettingsFile(opts, wellFormed)
4950
+ ];
4951
+ const own = files.map((path) => readEnv(path, read)).find((file) => file.kind === "ok" && ENV_PEP_ENFORCE in file.env);
4952
+ if (own?.kind === "ok" && own.env[ENV_PEP_ENFORCE]?.trim() === "1") {
4953
+ const bad = committedPaths[committed.findIndex((file) => file.kind === "unparseable")];
4954
+ return { env: out, ignored, ...bad !== void 0 ? { unreadableCommitted: bad } : {} };
4955
+ }
4956
+ }
4957
+ return { env: out, ignored };
4958
+ }
4959
+
4809
4960
  // src/pep/hook-shim.ts
4810
4961
  var HOOK_OUTCOMES = Object.keys({
4811
4962
  deny: 0,
@@ -5116,6 +5267,23 @@ function parsePayload(input) {
5116
5267
  }
5117
5268
  return parsed;
5118
5269
  }
5270
+ function repoConfigDenyReason(ignored) {
5271
+ return `AgentTrail enforcement is on here but ignores ${ignored.join(", ")} from this repo's committed .claude/settings.json (only user, local and managed settings can configure it), so it has no PDP URL or token and fails closed. Run \`npx -y @agenttrail/cli@latest setup --agent claude\` in this repo.`;
5272
+ }
5273
+ function unreadableSettingsDenyReason(path) {
5274
+ return `AgentTrail enforcement is on here, but ${path} can't be read as settings (it isn't valid JSON, or its env isn't an object), so AgentTrail can't tell which settings are this machine's own, and fails closed. Fix or remove that file's env block.`;
5275
+ }
5276
+ function pepEnvFor(env, payload, scopes) {
5277
+ if (env.AGENTTRAIL_PEP_ENFORCE === void 0) return { env, ignored: [] };
5278
+ const { processCwd, ...rest } = scopes ?? { home: homedir2() };
5279
+ const payloadCwd = typeof payload.cwd === "string" ? payload.cwd : void 0;
5280
+ return trustedPepEnv(env, {
5281
+ ...rest,
5282
+ claudeProjectDir: env.CLAUDE_PROJECT_DIR,
5283
+ claudeConfigDir: env.CLAUDE_CONFIG_DIR,
5284
+ projectDirs: [payloadCwd, processCwd]
5285
+ });
5286
+ }
5119
5287
  var DEFAULT_AGENT = "claude";
5120
5288
  function defaultSchedule(fn, ms) {
5121
5289
  const t = setTimeout(fn, ms);
@@ -5146,7 +5314,18 @@ async function runShim(deps) {
5146
5314
  (deps.cursorEmitter ?? createRealCursorEmitter()).emitAnswer(CURSOR_NO_OPINION);
5147
5315
  return;
5148
5316
  }
5149
- const cfg = resolvePepConfig(deps.env);
5317
+ const pepEnv = pepEnvFor(deps.env, payload, deps.settingsScopes);
5318
+ if (pepEnv.unreadableCommitted !== void 0) {
5319
+ cancelWatchdog();
5320
+ deps.emitter.emitVerdict("deny", unreadableSettingsDenyReason(pepEnv.unreadableCommitted));
5321
+ return;
5322
+ }
5323
+ const cfg = resolvePepConfig(pepEnv.env);
5324
+ if (cfg.enforce && (!cfg.url || !cfg.token) && pepEnv.ignored.length > 0) {
5325
+ cancelWatchdog();
5326
+ deps.emitter.emitVerdict("deny", repoConfigDenyReason(pepEnv.ignored));
5327
+ return;
5328
+ }
5150
5329
  const decision = await decide(payload, cfg, {
5151
5330
  fetchFn: deps.fetchFn,
5152
5331
  snapshotIO: deps.snapshotIO,
@@ -5248,7 +5427,8 @@ if (isDirectRun()) {
5248
5427
  readStdin: readRealStdin,
5249
5428
  fetchFn: fetch,
5250
5429
  emitter,
5251
- argv
5430
+ argv,
5431
+ settingsScopes: { home: homedir2(), processCwd: process.cwd() }
5252
5432
  });
5253
5433
  }
5254
5434
  });
@@ -5377,12 +5557,12 @@ function outcomeOf(perCandidate, via) {
5377
5557
  via
5378
5558
  };
5379
5559
  }
5380
- function decideCursorShell(join8, cfg, deps, request) {
5381
- if (join8.kind === "handoff") {
5560
+ function decideCursorShell(join9, cfg, deps, request) {
5561
+ if (join9.kind === "handoff") {
5382
5562
  return { kind: "approval", message: "AgentTrail is waiting for approval of this command." };
5383
5563
  }
5384
- if (join8.kind === "decided") return { kind: "none" };
5385
- if (join8.liveHandoff) {
5564
+ if (join9.kind === "decided") return { kind: "none" };
5565
+ if (join9.liveHandoff) {
5386
5566
  return { kind: "approval", message: "AgentTrail is waiting for approval in this turn." };
5387
5567
  }
5388
5568
  const snapshot = readCachedSnapshot(cfg.snapshotPath, deps.snapshotIO);
@@ -5503,7 +5683,7 @@ async function answerCursor(deps, startedAtMs) {
5503
5683
  }
5504
5684
  if (event === "beforeShellExecution") {
5505
5685
  const request = normalized?.candidates[0];
5506
- const join8 = (deps.shellJoin ?? readShellJoin)(
5686
+ const join9 = (deps.shellJoin ?? readShellJoin)(
5507
5687
  joinQueryFor({
5508
5688
  home: deps.home,
5509
5689
  io: deps.io,
@@ -5517,7 +5697,7 @@ async function answerCursor(deps, startedAtMs) {
5517
5697
  })
5518
5698
  );
5519
5699
  const outcome = decideCursorShell(
5520
- join8,
5700
+ join9,
5521
5701
  cfg,
5522
5702
  deps,
5523
5703
  request === void 0 ? void 0 : { tool: request.tool, args: { ...request.args } }
@@ -5526,7 +5706,7 @@ async function answerCursor(deps, startedAtMs) {
5526
5706
  verdict: verdictOf(outcome),
5527
5707
  // This checkpoint asks no one: it answers from the queue, or from the cached rules
5528
5708
  // when the queue has nothing to say.
5529
- via: join8.kind === "miss" ? "cached-rules" : "pdp"
5709
+ via: join9.kind === "miss" ? "cached-rules" : "pdp"
5530
5710
  });
5531
5711
  }
5532
5712
  const requests = buildCursorPdpRequest(payload);
@@ -5673,7 +5853,9 @@ export {
5673
5853
  guidanceOf,
5674
5854
  handleApproval,
5675
5855
  parsePayload,
5856
+ repoConfigDenyReason,
5676
5857
  runCodexShim,
5677
5858
  runCursorShim,
5678
- runShim
5859
+ runShim,
5860
+ unreadableSettingsDenyReason
5679
5861
  };