@agenttrail/cli 0.2.0 → 0.2.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/README.md +20 -7
- package/dist/chunk-FHYZ2UTD.js +168 -0
- package/dist/cli/index.cjs +46 -41
- package/dist/cli/index.js +1 -1
- package/dist/cursor/capture-hook.mjs +2 -2
- package/dist/cursor/pep-hook.mjs +74 -20
- package/dist/index.cjs +50 -45
- package/dist/index.d.cts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/plugin/.claude-plugin/marketplace.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/scripts/pep-hook.mjs +74 -20
- package/dist/chunk-WMGYTOQC.js +0 -163
package/dist/index.d.cts
CHANGED
|
@@ -99,6 +99,7 @@ interface LoginEnv {
|
|
|
99
99
|
readonly projectSlug?: string;
|
|
100
100
|
readonly captureContent?: boolean;
|
|
101
101
|
readonly global?: boolean;
|
|
102
|
+
readonly setup?: boolean;
|
|
102
103
|
readonly host: string;
|
|
103
104
|
readonly fetchFn?: FetchFn$1;
|
|
104
105
|
readonly sleepFn?: SleepFn;
|
|
@@ -275,6 +276,7 @@ interface MapOptions {
|
|
|
275
276
|
readonly captureContent: boolean;
|
|
276
277
|
readonly scopeVersion?: string;
|
|
277
278
|
readonly resolved?: ResolvedScrubbers | null;
|
|
279
|
+
readonly provenance?: "backfill" | "live";
|
|
278
280
|
}
|
|
279
281
|
declare function sessionToResourceSpans(session: ParsedSession, opts: MapOptions): BackfillResourceSpans;
|
|
280
282
|
|
|
@@ -420,6 +422,39 @@ declare function buildSpanTree(session: ParsedSession): SpanNode[];
|
|
|
420
422
|
|
|
421
423
|
type FetchFn = typeof fetch;
|
|
422
424
|
|
|
425
|
+
interface StateIO {
|
|
426
|
+
readFile?: (p: string) => string;
|
|
427
|
+
writeFile?: (p: string, c: string, mode?: number) => void;
|
|
428
|
+
mkdir?: (p: string, mode: number) => void;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
interface CaptureLogEntry {
|
|
432
|
+
readonly event?: string;
|
|
433
|
+
readonly session?: string;
|
|
434
|
+
readonly outcome: string;
|
|
435
|
+
readonly reason?: string;
|
|
436
|
+
readonly traces?: number;
|
|
437
|
+
readonly sent?: number;
|
|
438
|
+
readonly spans?: number;
|
|
439
|
+
readonly httpStatus?: number;
|
|
440
|
+
readonly project?: string;
|
|
441
|
+
}
|
|
442
|
+
interface CaptureContext {
|
|
443
|
+
readonly env: NodeJS.ProcessEnv;
|
|
444
|
+
readonly homeDir: string;
|
|
445
|
+
readonly endpointFlag?: string;
|
|
446
|
+
readonly readStdin?: () => Promise<string>;
|
|
447
|
+
readonly spawnWorker?: (payload: string) => void;
|
|
448
|
+
readonly armDeadline?: (ms: number) => void;
|
|
449
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
450
|
+
readonly upload?: UploadDeps;
|
|
451
|
+
readonly stateIO?: StateIO;
|
|
452
|
+
readonly loginEnv?: Partial<LoginEnv>;
|
|
453
|
+
readonly managedPaths?: readonly string[];
|
|
454
|
+
readonly log?: (entry: CaptureLogEntry) => void;
|
|
455
|
+
}
|
|
456
|
+
declare function runCaptureCommand(ctx: CaptureContext): Promise<number>;
|
|
457
|
+
|
|
423
458
|
declare const AGENTTRAIL_PROJECT_NS: "18a5d968-0fa2-5c8a-88da-0b29d80105d4";
|
|
424
459
|
declare const AGENTTRAIL_AGENT_NS: "7f050af4-796e-5b05-94c2-dba78bcdc7c2";
|
|
425
460
|
declare const AGENTTRAIL_INGEST_ENDPOINT: "https://ingest.agenttrail.sh";
|
|
@@ -554,6 +589,8 @@ interface CliIO {
|
|
|
554
589
|
fetchFn?: FetchFn;
|
|
555
590
|
pluginRunner?: ClaudeRunner;
|
|
556
591
|
readStdin?: () => Promise<string>;
|
|
592
|
+
managedPaths?: readonly string[];
|
|
593
|
+
captureOverrides?: Partial<Parameters<typeof runCaptureCommand>[0]>;
|
|
557
594
|
}
|
|
558
595
|
declare function run(io: CliIO): Promise<number>;
|
|
559
596
|
|
|
@@ -656,6 +693,10 @@ interface SetupResult {
|
|
|
656
693
|
readonly global: boolean;
|
|
657
694
|
readonly captureContent: boolean;
|
|
658
695
|
readonly resolvedEndpoint: string;
|
|
696
|
+
readonly sessionUpload: {
|
|
697
|
+
readonly hooksChanged: boolean;
|
|
698
|
+
readonly removedKeys: string[];
|
|
699
|
+
} | null;
|
|
659
700
|
}
|
|
660
701
|
declare function runSetup(params: SetupParams, io?: PersistIO): SetupResult;
|
|
661
702
|
|
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ interface LoginEnv {
|
|
|
99
99
|
readonly projectSlug?: string;
|
|
100
100
|
readonly captureContent?: boolean;
|
|
101
101
|
readonly global?: boolean;
|
|
102
|
+
readonly setup?: boolean;
|
|
102
103
|
readonly host: string;
|
|
103
104
|
readonly fetchFn?: FetchFn$1;
|
|
104
105
|
readonly sleepFn?: SleepFn;
|
|
@@ -275,6 +276,7 @@ interface MapOptions {
|
|
|
275
276
|
readonly captureContent: boolean;
|
|
276
277
|
readonly scopeVersion?: string;
|
|
277
278
|
readonly resolved?: ResolvedScrubbers | null;
|
|
279
|
+
readonly provenance?: "backfill" | "live";
|
|
278
280
|
}
|
|
279
281
|
declare function sessionToResourceSpans(session: ParsedSession, opts: MapOptions): BackfillResourceSpans;
|
|
280
282
|
|
|
@@ -420,6 +422,39 @@ declare function buildSpanTree(session: ParsedSession): SpanNode[];
|
|
|
420
422
|
|
|
421
423
|
type FetchFn = typeof fetch;
|
|
422
424
|
|
|
425
|
+
interface StateIO {
|
|
426
|
+
readFile?: (p: string) => string;
|
|
427
|
+
writeFile?: (p: string, c: string, mode?: number) => void;
|
|
428
|
+
mkdir?: (p: string, mode: number) => void;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
interface CaptureLogEntry {
|
|
432
|
+
readonly event?: string;
|
|
433
|
+
readonly session?: string;
|
|
434
|
+
readonly outcome: string;
|
|
435
|
+
readonly reason?: string;
|
|
436
|
+
readonly traces?: number;
|
|
437
|
+
readonly sent?: number;
|
|
438
|
+
readonly spans?: number;
|
|
439
|
+
readonly httpStatus?: number;
|
|
440
|
+
readonly project?: string;
|
|
441
|
+
}
|
|
442
|
+
interface CaptureContext {
|
|
443
|
+
readonly env: NodeJS.ProcessEnv;
|
|
444
|
+
readonly homeDir: string;
|
|
445
|
+
readonly endpointFlag?: string;
|
|
446
|
+
readonly readStdin?: () => Promise<string>;
|
|
447
|
+
readonly spawnWorker?: (payload: string) => void;
|
|
448
|
+
readonly armDeadline?: (ms: number) => void;
|
|
449
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
450
|
+
readonly upload?: UploadDeps;
|
|
451
|
+
readonly stateIO?: StateIO;
|
|
452
|
+
readonly loginEnv?: Partial<LoginEnv>;
|
|
453
|
+
readonly managedPaths?: readonly string[];
|
|
454
|
+
readonly log?: (entry: CaptureLogEntry) => void;
|
|
455
|
+
}
|
|
456
|
+
declare function runCaptureCommand(ctx: CaptureContext): Promise<number>;
|
|
457
|
+
|
|
423
458
|
declare const AGENTTRAIL_PROJECT_NS: "18a5d968-0fa2-5c8a-88da-0b29d80105d4";
|
|
424
459
|
declare const AGENTTRAIL_AGENT_NS: "7f050af4-796e-5b05-94c2-dba78bcdc7c2";
|
|
425
460
|
declare const AGENTTRAIL_INGEST_ENDPOINT: "https://ingest.agenttrail.sh";
|
|
@@ -554,6 +589,8 @@ interface CliIO {
|
|
|
554
589
|
fetchFn?: FetchFn;
|
|
555
590
|
pluginRunner?: ClaudeRunner;
|
|
556
591
|
readStdin?: () => Promise<string>;
|
|
592
|
+
managedPaths?: readonly string[];
|
|
593
|
+
captureOverrides?: Partial<Parameters<typeof runCaptureCommand>[0]>;
|
|
557
594
|
}
|
|
558
595
|
declare function run(io: CliIO): Promise<number>;
|
|
559
596
|
|
|
@@ -656,6 +693,10 @@ interface SetupResult {
|
|
|
656
693
|
readonly global: boolean;
|
|
657
694
|
readonly captureContent: boolean;
|
|
658
695
|
readonly resolvedEndpoint: string;
|
|
696
|
+
readonly sessionUpload: {
|
|
697
|
+
readonly hooksChanged: boolean;
|
|
698
|
+
readonly removedKeys: string[];
|
|
699
|
+
} | null;
|
|
659
700
|
}
|
|
660
701
|
declare function runSetup(params: SetupParams, io?: PersistIO): SetupResult;
|
|
661
702
|
|
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-
|
|
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-FHYZ2UTD.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.
|
|
3
|
+
"version": "0.2.1",
|
|
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.
|
|
9
|
+
"version": "0.2.1"
|
|
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.
|
|
16
|
+
"version": "0.2.1",
|
|
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.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "AgentTrail",
|
|
7
7
|
"url": "https://agenttrail.sh"
|
|
@@ -2149,6 +2149,9 @@ function strongestVerdict(matches) {
|
|
|
2149
2149
|
return { verdict: "allow", policyId: null };
|
|
2150
2150
|
}
|
|
2151
2151
|
|
|
2152
|
+
// ../shared/src/agent-feedback.ts
|
|
2153
|
+
var AGENT_GUIDANCE_MAX_CHARS = 500;
|
|
2154
|
+
|
|
2152
2155
|
// src/cursor/detect.ts
|
|
2153
2156
|
var CURSOR_EVENT_NAMES = /* @__PURE__ */ new Set([
|
|
2154
2157
|
// guard's list
|
|
@@ -3032,6 +3035,13 @@ async function evaluateViaPdp(args, fetchFn) {
|
|
|
3032
3035
|
if (res.status === 401) return { kind: "unauthorized" };
|
|
3033
3036
|
throw new PdpUnreachableError(`unexpected status ${res.status}`);
|
|
3034
3037
|
}
|
|
3038
|
+
function agentDenialOf(body) {
|
|
3039
|
+
if (typeof body !== "object" || body === null) return null;
|
|
3040
|
+
const o = body;
|
|
3041
|
+
if (o.outcome !== "denied" || !("decided_by_name" in o)) return null;
|
|
3042
|
+
const reason = typeof o.reason === "string" ? o.reason.trim() : "";
|
|
3043
|
+
return reason.startsWith("Denied by ") ? reason : null;
|
|
3044
|
+
}
|
|
3035
3045
|
async function holdForApproval(args, fetchFn) {
|
|
3036
3046
|
const res = await boundedFetch(
|
|
3037
3047
|
fetchFn,
|
|
@@ -3060,9 +3070,9 @@ async function holdForApproval(args, fetchFn) {
|
|
|
3060
3070
|
} catch {
|
|
3061
3071
|
throw new PdpUnreachableError("hold 200 with unparseable body");
|
|
3062
3072
|
}
|
|
3063
|
-
const outcome = parsed
|
|
3073
|
+
const outcome = parsed?.outcome;
|
|
3064
3074
|
if (outcome === "approved" || outcome === "denied" || outcome === "unanswered") {
|
|
3065
|
-
return outcome;
|
|
3075
|
+
return { outcome, denial: agentDenialOf(parsed) };
|
|
3066
3076
|
}
|
|
3067
3077
|
throw new PdpUnreachableError("hold 200 with malformed outcome");
|
|
3068
3078
|
}
|
|
@@ -3105,7 +3115,7 @@ async function holdCursorApproval(input) {
|
|
|
3105
3115
|
const windowSeconds = holdWindowSeconds(input.elapsedMs);
|
|
3106
3116
|
input.extendDeadline?.(holdWatchdogDelayMs(input.elapsedMs));
|
|
3107
3117
|
try {
|
|
3108
|
-
const
|
|
3118
|
+
const held = await holdForApproval(
|
|
3109
3119
|
{
|
|
3110
3120
|
url: cfg.holdUrl,
|
|
3111
3121
|
token: cfg.token,
|
|
@@ -3116,10 +3126,10 @@ async function holdCursorApproval(input) {
|
|
|
3116
3126
|
},
|
|
3117
3127
|
input.fetchFn
|
|
3118
3128
|
);
|
|
3119
|
-
if (
|
|
3129
|
+
if (held === "tier-disabled") {
|
|
3120
3130
|
return { outcome: "forbidden", windowSeconds, correlationId };
|
|
3121
3131
|
}
|
|
3122
|
-
return { outcome, windowSeconds, correlationId };
|
|
3132
|
+
return { outcome: held.outcome, windowSeconds, correlationId, denial: held.denial };
|
|
3123
3133
|
} catch (err) {
|
|
3124
3134
|
if (err instanceof PdpUnreachableError) {
|
|
3125
3135
|
return { outcome: "unreachable", windowSeconds, correlationId };
|
|
@@ -4055,6 +4065,7 @@ var HOOK_OUTCOMES = Object.keys({
|
|
|
4055
4065
|
warn: 0,
|
|
4056
4066
|
none: 0
|
|
4057
4067
|
});
|
|
4068
|
+
var REVIEWER_DENIED = "Denied by an AgentTrail reviewer.";
|
|
4058
4069
|
var NO_DECISION = { decision: "none", reason: "" };
|
|
4059
4070
|
var MAX_DETAIL_LEN = 8192;
|
|
4060
4071
|
var PEP_VENDOR = "claude-code";
|
|
@@ -4088,7 +4099,7 @@ var handleApproval = async (payload, verdict, ctx) => {
|
|
|
4088
4099
|
}
|
|
4089
4100
|
ctx.extendDeadline?.(PEP_HOLD_WATCHDOG_MS);
|
|
4090
4101
|
try {
|
|
4091
|
-
const
|
|
4102
|
+
const held = await holdForApproval(
|
|
4092
4103
|
{
|
|
4093
4104
|
url: ctx.cfg.holdUrl,
|
|
4094
4105
|
token: ctx.cfg.token,
|
|
@@ -4099,14 +4110,14 @@ var handleApproval = async (payload, verdict, ctx) => {
|
|
|
4099
4110
|
},
|
|
4100
4111
|
ctx.fetchFn
|
|
4101
4112
|
);
|
|
4102
|
-
if (
|
|
4113
|
+
if (held === "tier-disabled") {
|
|
4103
4114
|
return NO_DECISION;
|
|
4104
4115
|
}
|
|
4105
|
-
if (outcome === "approved") {
|
|
4116
|
+
if (held.outcome === "approved") {
|
|
4106
4117
|
return NO_DECISION;
|
|
4107
4118
|
}
|
|
4108
|
-
if (outcome === "denied") {
|
|
4109
|
-
return { decision: "deny", reason:
|
|
4119
|
+
if (held.outcome === "denied") {
|
|
4120
|
+
return { decision: "deny", reason: held.denial ?? REVIEWER_DENIED };
|
|
4110
4121
|
}
|
|
4111
4122
|
return {
|
|
4112
4123
|
decision: "ask",
|
|
@@ -4200,7 +4211,11 @@ function failClosedViaSnapshot(_payload, request, cfg, deps) {
|
|
|
4200
4211
|
reason: "AgentTrail PDP is unreachable and no local policy snapshot is cached; failing closed."
|
|
4201
4212
|
};
|
|
4202
4213
|
}
|
|
4203
|
-
const { verdict, decidingName, decidingPolicyId } = evaluateLocally(
|
|
4214
|
+
const { verdict, decidingName, decidingPolicyId, decidingGuidance } = evaluateLocally(
|
|
4215
|
+
snapshot,
|
|
4216
|
+
request,
|
|
4217
|
+
cfg.orgId
|
|
4218
|
+
);
|
|
4204
4219
|
if ((verdict === "deny" || verdict === "require_approval") && decidingPolicyId) {
|
|
4205
4220
|
(deps.queueOffline ?? queueOfflineDecision)(cfg.snapshotPath, {
|
|
4206
4221
|
policyId: decidingPolicyId,
|
|
@@ -4211,13 +4226,19 @@ function failClosedViaSnapshot(_payload, request, cfg, deps) {
|
|
|
4211
4226
|
if (verdict === "deny") {
|
|
4212
4227
|
return {
|
|
4213
4228
|
decision: "deny",
|
|
4214
|
-
reason:
|
|
4229
|
+
reason: withGuidance(
|
|
4230
|
+
`Blocked by local AgentTrail policy${quoted(decidingName)} (PDP unreachable; evaluated against the cached snapshot).`,
|
|
4231
|
+
decidingGuidance
|
|
4232
|
+
)
|
|
4215
4233
|
};
|
|
4216
4234
|
}
|
|
4217
4235
|
if (verdict === "require_approval") {
|
|
4218
4236
|
return {
|
|
4219
4237
|
decision: "ask",
|
|
4220
|
-
reason:
|
|
4238
|
+
reason: withGuidance(
|
|
4239
|
+
`Approval required by local AgentTrail policy${quoted(decidingName)} (PDP unreachable; deferring to you).`,
|
|
4240
|
+
decidingGuidance
|
|
4241
|
+
)
|
|
4221
4242
|
};
|
|
4222
4243
|
}
|
|
4223
4244
|
return NO_DECISION;
|
|
@@ -4225,6 +4246,17 @@ function failClosedViaSnapshot(_payload, request, cfg, deps) {
|
|
|
4225
4246
|
function quoted(name) {
|
|
4226
4247
|
return name ? ` "${name}"` : "";
|
|
4227
4248
|
}
|
|
4249
|
+
function guidanceOf(entry) {
|
|
4250
|
+
const raw = entry.agent_guidance;
|
|
4251
|
+
if (typeof raw !== "string") return null;
|
|
4252
|
+
const trimmed2 = raw.trim();
|
|
4253
|
+
if (trimmed2 === "") return null;
|
|
4254
|
+
const chars = [...trimmed2];
|
|
4255
|
+
return chars.length <= AGENT_GUIDANCE_MAX_CHARS ? trimmed2 : chars.slice(0, AGENT_GUIDANCE_MAX_CHARS).join("");
|
|
4256
|
+
}
|
|
4257
|
+
function withGuidance(sentence, guidance) {
|
|
4258
|
+
return guidance ? `${sentence} ${guidance}` : sentence;
|
|
4259
|
+
}
|
|
4228
4260
|
function evaluateLocally(snapshot, request, orgId) {
|
|
4229
4261
|
const ctx = buildEvaluationContext(request, orgId ?? NIL_ORG_ID);
|
|
4230
4262
|
const matches = [];
|
|
@@ -4243,13 +4275,20 @@ function evaluateLocally(snapshot, request, orgId) {
|
|
|
4243
4275
|
}
|
|
4244
4276
|
const { verdict, policyId } = strongestVerdict(matches);
|
|
4245
4277
|
const names = {};
|
|
4246
|
-
|
|
4278
|
+
const guidance = {};
|
|
4279
|
+
for (const [id, entry] of byId) {
|
|
4280
|
+
names[id] = entry.name;
|
|
4281
|
+
const g = guidanceOf(entry);
|
|
4282
|
+
if (g !== null) guidance[id] = g;
|
|
4283
|
+
}
|
|
4247
4284
|
return {
|
|
4248
4285
|
verdict,
|
|
4249
4286
|
decidingName: policyId ? byId.get(policyId)?.name ?? null : null,
|
|
4250
4287
|
decidingPolicyId: policyId,
|
|
4288
|
+
decidingGuidance: policyId ? guidance[policyId] ?? null : null,
|
|
4251
4289
|
matches,
|
|
4252
|
-
names
|
|
4290
|
+
names,
|
|
4291
|
+
guidance
|
|
4253
4292
|
};
|
|
4254
4293
|
}
|
|
4255
4294
|
async function decide(payload, cfg, deps) {
|
|
@@ -4495,9 +4534,12 @@ function matchesOf(response) {
|
|
|
4495
4534
|
}
|
|
4496
4535
|
return { matches, names };
|
|
4497
4536
|
}
|
|
4498
|
-
function cursorReason(verdict, name) {
|
|
4537
|
+
function cursorReason(verdict, name, guidance = null) {
|
|
4499
4538
|
const named = name === null ? "" : ` "${name}"`;
|
|
4500
|
-
return
|
|
4539
|
+
return withGuidance(
|
|
4540
|
+
verdict === "deny" ? `Blocked by AgentTrail policy${named}.` : `Approval required by AgentTrail policy${named}.`,
|
|
4541
|
+
guidance
|
|
4542
|
+
);
|
|
4501
4543
|
}
|
|
4502
4544
|
async function decideCursorCandidates(requests, cfg, deps) {
|
|
4503
4545
|
const settled = await Promise.all(
|
|
@@ -4561,7 +4603,15 @@ function outcomeOf(perCandidate, via) {
|
|
|
4561
4603
|
}
|
|
4562
4604
|
const names = Object.assign({}, ...perCandidate.map((result) => result.names));
|
|
4563
4605
|
const name = combined.policyId === null ? null : names[combined.policyId] ?? null;
|
|
4564
|
-
const
|
|
4606
|
+
const guidance = Object.assign(
|
|
4607
|
+
{},
|
|
4608
|
+
...perCandidate.map((result) => result.guidance ?? {})
|
|
4609
|
+
);
|
|
4610
|
+
const message = cursorReason(
|
|
4611
|
+
combined.verdict,
|
|
4612
|
+
name,
|
|
4613
|
+
combined.policyId === null ? null : guidance[combined.policyId] ?? null
|
|
4614
|
+
);
|
|
4565
4615
|
if (combined.verdict === "deny") {
|
|
4566
4616
|
return {
|
|
4567
4617
|
outcome: { kind: "deny", message },
|
|
@@ -4593,14 +4643,17 @@ function decideCursorShell(join8, cfg, deps, request) {
|
|
|
4593
4643
|
}
|
|
4594
4644
|
const local = evaluateLocally(snapshot, request, cfg.orgId);
|
|
4595
4645
|
if (local.verdict === "allow") return { kind: "none" };
|
|
4596
|
-
return {
|
|
4646
|
+
return {
|
|
4647
|
+
kind: "approval",
|
|
4648
|
+
message: cursorReason(local.verdict, local.decidingName, local.decidingGuidance)
|
|
4649
|
+
};
|
|
4597
4650
|
}
|
|
4598
4651
|
function outcomeOfHold(result) {
|
|
4599
4652
|
switch (result.outcome) {
|
|
4600
4653
|
case "approved":
|
|
4601
4654
|
return { kind: "none" };
|
|
4602
4655
|
case "denied":
|
|
4603
|
-
return { kind: "deny", message:
|
|
4656
|
+
return { kind: "deny", message: result.denial ?? REVIEWER_DENIED };
|
|
4604
4657
|
case "forbidden":
|
|
4605
4658
|
return { kind: "none" };
|
|
4606
4659
|
case "unreachable":
|
|
@@ -4869,6 +4922,7 @@ export {
|
|
|
4869
4922
|
decide,
|
|
4870
4923
|
dispatchHookRun,
|
|
4871
4924
|
evaluateLocally,
|
|
4925
|
+
guidanceOf,
|
|
4872
4926
|
handleApproval,
|
|
4873
4927
|
parsePayload,
|
|
4874
4928
|
runCodexShim,
|