auto-mode 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/{classify-edit-D8GC6b91.js → classify-edit-LpoeenGt.js} +4 -1
- package/dist/cli.js +139 -121
- package/dist/index.d.ts +210 -15
- package/dist/index.js +7 -2
- package/dist/{render-verdict-QLyj-g7d.js → render-verdict-u3_ftSEp.js} +534 -450
- package/mods/auto-mode/hooks/testing.d.ts +76 -24
- package/mods/auto-mode/hooks/types.ts +15 -1
- package/package.json +25 -12
- package/policy/classifier.md +33 -22
- package/policy/decision.md +11 -5
- package/policy/rules.md +131 -137
- package/mods/auto-mode/hooks/build-prompt-context.claude-check.ts +0 -93
- package/mods/auto-mode/hooks/register.claude-check.ts +0 -1226
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
//#region src/budget/types.d.ts
|
|
2
|
-
interface DenialBudget {
|
|
3
|
-
readonly consecutive: number;
|
|
4
|
-
readonly perSession: number;
|
|
5
|
-
}
|
|
6
|
-
//#endregion
|
|
7
1
|
//#region src/request/types.d.ts
|
|
8
2
|
interface UserTask {
|
|
9
3
|
readonly text: string;
|
|
@@ -45,6 +39,51 @@ interface DecisionRule {
|
|
|
45
39
|
readonly source: 'shipped' | 'replacement' | 'configured';
|
|
46
40
|
readonly text: string;
|
|
47
41
|
}
|
|
42
|
+
type DecisionChoice = 'allow' | 'block';
|
|
43
|
+
type RecordedDecisionChoice = DecisionChoice | 'ask';
|
|
44
|
+
interface DecisionQuestion<Choice extends string = DecisionChoice> {
|
|
45
|
+
readonly type: 'choice';
|
|
46
|
+
readonly instructions: string;
|
|
47
|
+
readonly criteria: Readonly<Record<Choice, string>>;
|
|
48
|
+
}
|
|
49
|
+
interface DecisionInput<Choice extends string = DecisionChoice> {
|
|
50
|
+
readonly state: {
|
|
51
|
+
readonly policy: string;
|
|
52
|
+
readonly answerGuidance: string;
|
|
53
|
+
readonly rulesSource: 'shipped' | 'replacement';
|
|
54
|
+
readonly configuredRules: ClaudeRules;
|
|
55
|
+
readonly lastUserMessage: string | null;
|
|
56
|
+
readonly repositoryContext?: RepositoryContext;
|
|
57
|
+
readonly mcpServers?: readonly MCPServerFact[];
|
|
58
|
+
readonly taskContext?: DecisionContext;
|
|
59
|
+
readonly action: {
|
|
60
|
+
readonly tool: string;
|
|
61
|
+
readonly cwd: string;
|
|
62
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
readonly questions: Readonly<Record<string, DecisionQuestion<Choice>>>;
|
|
66
|
+
}
|
|
67
|
+
interface DecisionRequest extends DecisionInput {
|
|
68
|
+
readonly rules: Readonly<Record<string, DecisionRule>>;
|
|
69
|
+
}
|
|
70
|
+
interface RepositoryContext {
|
|
71
|
+
readonly cwd: string;
|
|
72
|
+
readonly branch: string | null;
|
|
73
|
+
readonly defaultBranch: string | null;
|
|
74
|
+
readonly remotes?: readonly RepositoryRemote[] | undefined;
|
|
75
|
+
readonly taskScope?: TaskScopeSummary | undefined;
|
|
76
|
+
}
|
|
77
|
+
interface MCPServerFact {
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly scope: 'user' | 'local' | 'project';
|
|
80
|
+
readonly transport: 'stdio' | 'http' | 'sse' | 'ws';
|
|
81
|
+
readonly host: string | null;
|
|
82
|
+
}
|
|
83
|
+
interface RepositoryRemote {
|
|
84
|
+
readonly name: string;
|
|
85
|
+
readonly url: string;
|
|
86
|
+
}
|
|
48
87
|
interface TaskScopeSummary {
|
|
49
88
|
readonly worktrees: readonly string[];
|
|
50
89
|
readonly branches: readonly string[];
|
|
@@ -53,12 +92,18 @@ interface TaskScopeSummary {
|
|
|
53
92
|
readonly number: number;
|
|
54
93
|
}[];
|
|
55
94
|
}
|
|
56
|
-
interface DecisionAnswer {
|
|
95
|
+
interface DecisionAnswer<Choice extends string = DecisionChoice> {
|
|
57
96
|
readonly type: 'choice';
|
|
58
|
-
readonly choice:
|
|
59
|
-
readonly probabilities: Readonly<Record<
|
|
97
|
+
readonly choice: Choice;
|
|
98
|
+
readonly probabilities: Readonly<Record<Choice, number>>;
|
|
60
99
|
readonly confidence: number;
|
|
61
100
|
}
|
|
101
|
+
interface DecisionResult<Choice extends string = DecisionChoice> {
|
|
102
|
+
readonly model: string;
|
|
103
|
+
readonly answers: Readonly<Record<string, DecisionAnswer<Choice>>>;
|
|
104
|
+
readonly inputTokens: number;
|
|
105
|
+
readonly requestBytes: number;
|
|
106
|
+
}
|
|
62
107
|
type DecisionFailureReason = 'request-too-large' | 'aborted' | 'network' | 'http-status' | 'invalid-response';
|
|
63
108
|
interface DecisionDiagnostics {
|
|
64
109
|
readonly status: 'allow' | 'deny' | 'failure' | 'timeout' | 'cancelled';
|
|
@@ -68,22 +113,96 @@ interface DecisionDiagnostics {
|
|
|
68
113
|
readonly failureReason: DecisionFailureReason | null;
|
|
69
114
|
readonly requestBytes: number | null;
|
|
70
115
|
readonly elapsedMs: number;
|
|
71
|
-
readonly
|
|
116
|
+
readonly blockThreshold: number;
|
|
72
117
|
readonly contributors: readonly {
|
|
73
118
|
readonly rule: string;
|
|
74
119
|
readonly source: DecisionRule['source'];
|
|
75
120
|
readonly tier: DecisionRule['tier'];
|
|
76
121
|
readonly choice: DecisionAnswer['choice'];
|
|
77
122
|
readonly confidence: number;
|
|
78
|
-
readonly
|
|
123
|
+
readonly blockProbability: number;
|
|
79
124
|
}[];
|
|
80
125
|
}
|
|
81
126
|
//#endregion
|
|
82
127
|
//#region src/config/types.d.ts
|
|
128
|
+
interface OutputStream {
|
|
129
|
+
readonly write: (text: string) => unknown;
|
|
130
|
+
}
|
|
131
|
+
interface HostEnvironment {
|
|
132
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
133
|
+
readonly home: string;
|
|
134
|
+
readonly scratchPaths?: readonly string[] | undefined;
|
|
135
|
+
}
|
|
136
|
+
interface ClaudeRules {
|
|
137
|
+
readonly environment: readonly string[];
|
|
138
|
+
readonly allow: readonly string[];
|
|
139
|
+
readonly soft_deny: readonly string[];
|
|
140
|
+
readonly hard_deny: readonly string[];
|
|
141
|
+
}
|
|
142
|
+
interface ClaudeSettings {
|
|
143
|
+
readonly rules: ClaudeRules;
|
|
144
|
+
readonly userSettings: unknown;
|
|
145
|
+
}
|
|
83
146
|
interface EvaluationOptions {
|
|
147
|
+
readonly claudeSettings?: ClaudeSettings | undefined;
|
|
84
148
|
readonly deadlineAt?: number | undefined;
|
|
85
149
|
readonly signal?: Readonly<AbortSignal> | undefined;
|
|
86
150
|
readonly taskScope?: TaskScopeSummary | undefined;
|
|
151
|
+
readonly host?: Readonly<HostEnvironment> | undefined;
|
|
152
|
+
readonly now?: (() => number) | undefined;
|
|
153
|
+
readonly timeout?: ((ms: number) => AbortSignal) | undefined;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/containment/collect-scope-findings.d.ts
|
|
157
|
+
interface ScopeRemote {
|
|
158
|
+
readonly name: string;
|
|
159
|
+
readonly url: string;
|
|
160
|
+
}
|
|
161
|
+
interface OwnedPullRequest {
|
|
162
|
+
readonly number: number;
|
|
163
|
+
readonly repository: string;
|
|
164
|
+
}
|
|
165
|
+
interface OwnedScope {
|
|
166
|
+
readonly home: string;
|
|
167
|
+
readonly worktrees: readonly string[];
|
|
168
|
+
readonly branches: readonly string[];
|
|
169
|
+
readonly currentBranch: string | null;
|
|
170
|
+
readonly remotes: readonly ScopeRemote[];
|
|
171
|
+
readonly pullRequests: readonly OwnedPullRequest[];
|
|
172
|
+
readonly pathGlobs: readonly string[];
|
|
173
|
+
}
|
|
174
|
+
interface ScopeFinding {
|
|
175
|
+
readonly kind: 'path' | 'branch' | 'remote-write' | 'credential' | 'prune';
|
|
176
|
+
readonly target: string;
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/scope/find-checkout.d.ts
|
|
180
|
+
interface Checkout {
|
|
181
|
+
readonly worktree: string;
|
|
182
|
+
readonly commonDir: string;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/bypass/classify-edit.d.ts
|
|
186
|
+
type EditClassification = {
|
|
187
|
+
readonly kind: 'bypass';
|
|
188
|
+
readonly target: string;
|
|
189
|
+
} | {
|
|
190
|
+
readonly kind: 'jev';
|
|
191
|
+
readonly reason: string;
|
|
192
|
+
};
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/bypass/try-classify-edit.d.ts
|
|
195
|
+
interface EditFileReader {
|
|
196
|
+
readonly resolveEditTarget: (path: string) => Promise<string | null>;
|
|
197
|
+
readonly findCheckout: (directory: string, env: HostEnvironment['env']) => Promise<Checkout | null>;
|
|
198
|
+
readonly readFile: (path: string) => Promise<string>;
|
|
199
|
+
}
|
|
200
|
+
export declare function tryClassifyEdit(request: Readonly<ActionRequest>, scope: Readonly<OwnedScope>, host: Readonly<HostEnvironment>, files?: Readonly<EditFileReader>): Promise<EditClassification | null>;
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/budget/types.d.ts
|
|
203
|
+
interface DenialBudget {
|
|
204
|
+
readonly consecutive: number;
|
|
205
|
+
readonly perSession: number;
|
|
87
206
|
}
|
|
88
207
|
//#endregion
|
|
89
208
|
//#region src/config/presets.d.ts
|
|
@@ -114,13 +233,13 @@ interface Config {
|
|
|
114
233
|
readonly rulesPath?: string | undefined;
|
|
115
234
|
readonly onFailure: 'defer' | 'deny';
|
|
116
235
|
readonly claudeSettingsPath?: string | null | undefined;
|
|
117
|
-
readonly
|
|
236
|
+
readonly blockThreshold?: number | undefined;
|
|
118
237
|
readonly denialBudget?: DenialBudget;
|
|
119
238
|
readonly warnings?: readonly string[];
|
|
120
239
|
}
|
|
121
240
|
export declare const DEFAULT_CONFIG: Config;
|
|
122
|
-
export declare function resolveConfigPath(): string;
|
|
123
|
-
export declare function loadConfig(
|
|
241
|
+
export declare function resolveConfigPath(host?: Readonly<HostEnvironment>): string;
|
|
242
|
+
export declare function loadConfig(configPath?: string, host?: Readonly<HostEnvironment>): Promise<Config>;
|
|
124
243
|
export declare function resolveApiKey(provider: ProviderConfig, options?: EvaluationOptions): Promise<string | null>;
|
|
125
244
|
//#endregion
|
|
126
245
|
//#region src/classify-action.d.ts
|
|
@@ -135,9 +254,24 @@ interface ActionOutcome {
|
|
|
135
254
|
}
|
|
136
255
|
interface ClassifyOptions extends EvaluationOptions {
|
|
137
256
|
readonly localOnly?: boolean;
|
|
257
|
+
readonly stderr?: Readonly<OutputStream> | undefined;
|
|
138
258
|
}
|
|
139
259
|
export declare function classifyAction(request: ActionRequest, config: Config, options?: ClassifyOptions): Promise<ActionOutcome>;
|
|
140
260
|
//#endregion
|
|
261
|
+
//#region src/config/load-claude-rules.d.ts
|
|
262
|
+
export declare function loadClaudeRules(path: string | null | undefined, host: Readonly<HostEnvironment>): Promise<ClaudeRules>;
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/containment/check-containment.d.ts
|
|
265
|
+
interface ContainmentDeny {
|
|
266
|
+
readonly rule: string;
|
|
267
|
+
readonly reason: string;
|
|
268
|
+
readonly findings: readonly ScopeFinding[];
|
|
269
|
+
}
|
|
270
|
+
export declare function checkContainment(request: Readonly<ActionRequest>, scope: Readonly<OwnedScope>, scratchPaths?: readonly string[]): ContainmentDeny | null;
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/model/build-decision-request.d.ts
|
|
273
|
+
export declare function buildDecisionRequest(payload: ActionRequest, policy: string, configuredRules: ClaudeRules, lastUserMessage: string | null, rulesSource?: 'shipped' | 'replacement', repositoryContext?: RepositoryContext | null, mcpServers?: readonly MCPServerFact[]): DecisionRequest;
|
|
274
|
+
//#endregion
|
|
141
275
|
//#region src/model/classify-with-model.d.ts
|
|
142
276
|
interface ModelOutcome {
|
|
143
277
|
readonly verdict: Verdict | null;
|
|
@@ -147,9 +281,26 @@ interface ModelOutcome {
|
|
|
147
281
|
}
|
|
148
282
|
export declare function classifyWithModel(payload: ActionRequest, config: Config, options?: EvaluationOptions): Promise<ModelOutcome>;
|
|
149
283
|
//#endregion
|
|
284
|
+
//#region src/model/decision-request-error.d.ts
|
|
285
|
+
export declare class DecisionRequestError extends Error {
|
|
286
|
+
readonly reason: DecisionFailureReason;
|
|
287
|
+
readonly requestBytes: number;
|
|
288
|
+
constructor(reason: DecisionFailureReason, requestBytes: number, message: string, options?: Readonly<ErrorOptions>);
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
150
291
|
//#region src/model/parse-verdict.d.ts
|
|
151
292
|
export declare function parseModelVerdict(text: string): Verdict;
|
|
152
293
|
//#endregion
|
|
294
|
+
//#region src/model/send-decision.d.ts
|
|
295
|
+
interface SendOptions {
|
|
296
|
+
readonly fetch?: (url: string, init: Readonly<RequestInit>) => Promise<Response>;
|
|
297
|
+
}
|
|
298
|
+
interface SendDecisionOptions<Choice extends string> extends SendOptions {
|
|
299
|
+
readonly choices: readonly [Choice, ...Choice[]];
|
|
300
|
+
}
|
|
301
|
+
export declare function sendDecision(provider: ProviderConfig, apiKey: string, request: DecisionInput, signal: Readonly<AbortSignal>, options?: SendOptions): Promise<DecisionResult>;
|
|
302
|
+
export declare function sendDecision<Choice extends string>(provider: ProviderConfig, apiKey: string, request: DecisionInput<Choice>, signal: Readonly<AbortSignal>, options: SendDecisionOptions<Choice>): Promise<DecisionResult<Choice>>;
|
|
303
|
+
//#endregion
|
|
153
304
|
//#region src/policy/load-policy.d.ts
|
|
154
305
|
interface PolicyPaths {
|
|
155
306
|
readonly classifierPath?: string | undefined;
|
|
@@ -172,4 +323,48 @@ type LocalVerdict = {
|
|
|
172
323
|
};
|
|
173
324
|
export declare function classifyLocally(payload: ActionRequest): LocalVerdict;
|
|
174
325
|
//#endregion
|
|
175
|
-
|
|
326
|
+
//#region src/scope/types.d.ts
|
|
327
|
+
interface ScopePullRequest {
|
|
328
|
+
readonly number: number;
|
|
329
|
+
readonly head: string;
|
|
330
|
+
readonly repository: string;
|
|
331
|
+
}
|
|
332
|
+
interface ScopeFacts {
|
|
333
|
+
readonly worktrees: readonly string[];
|
|
334
|
+
readonly branches: readonly string[];
|
|
335
|
+
readonly pullRequests: readonly ScopePullRequest[];
|
|
336
|
+
readonly pathGlobs: readonly string[];
|
|
337
|
+
}
|
|
338
|
+
type ScopeEvent = {
|
|
339
|
+
readonly kind: 'worktree';
|
|
340
|
+
readonly path: string;
|
|
341
|
+
} | {
|
|
342
|
+
readonly kind: 'branch';
|
|
343
|
+
readonly name: string;
|
|
344
|
+
readonly directory: string;
|
|
345
|
+
} | {
|
|
346
|
+
readonly kind: 'pull-request';
|
|
347
|
+
readonly directory: string;
|
|
348
|
+
readonly head: string | null;
|
|
349
|
+
};
|
|
350
|
+
interface SessionBranch {
|
|
351
|
+
readonly name: string;
|
|
352
|
+
readonly commonDir: string;
|
|
353
|
+
}
|
|
354
|
+
interface SessionScope {
|
|
355
|
+
readonly worktrees: readonly string[];
|
|
356
|
+
readonly branches: readonly SessionBranch[];
|
|
357
|
+
readonly pullRequests: readonly ScopePullRequest[];
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/scope/build-task-scope.d.ts
|
|
361
|
+
interface TaskScopeInput {
|
|
362
|
+
readonly home: string;
|
|
363
|
+
readonly currentBranch: string | null;
|
|
364
|
+
readonly defaultBranch: string | null;
|
|
365
|
+
readonly remotes: readonly ScopeRemote[];
|
|
366
|
+
readonly facts: readonly ScopeFacts[];
|
|
367
|
+
}
|
|
368
|
+
export declare function buildTaskScope(input: Readonly<TaskScopeInput>): OwnedScope;
|
|
369
|
+
//#endregion
|
|
370
|
+
export type { ActionOutcome, ActionRequest, ClassifyOptions, ClaudeRules, Config, ContainmentDeny, DecisionContext, DecisionRequest, DecisionResult, DecisionRule, EditClassification, LocalVerdict, ModelOutcome, OwnedScope, PolicyPaths, ProviderConfig, RecordedDecisionChoice, RepositoryContext, ScopeEvent, ScopeSource, SessionScope, Verdict };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { A as resolveConfigPath, M as PRESETS, O as loadConfig, S as tryClassifyEdit, T as DEFAULT_CONFIG, _ as checkContainment, c as classifyLocally, d as sendDecision, g as loadPolicy, h as buildDecisionRequest, k as resolveApiKey, l as classifyWithModel, m as DecisionRequestError, n as parseActionRequest, r as classifyAction, s as buildTaskScope, t as renderVerdict, u as parseModelVerdict, x as loadClaudeSettings } from "./render-verdict-u3_ftSEp.js";
|
|
2
|
+
//#region src/config/load-claude-rules.ts
|
|
3
|
+
async function loadClaudeRules(path, host) {
|
|
4
|
+
return (await loadClaudeSettings(path, host)).rules;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { DEFAULT_CONFIG, DecisionRequestError, PRESETS, buildDecisionRequest, buildTaskScope, checkContainment, classifyAction, classifyLocally, classifyWithModel, loadClaudeRules, loadConfig, loadPolicy, parseActionRequest, parseModelVerdict, renderVerdict, resolveApiKey, resolveConfigPath, sendDecision, tryClassifyEdit };
|