@aiwg/cli 2026.10.11 → 2026.10.14
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/agentic/code/providers/model-catalog.v1.json +62 -12
- package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
- package/dist/src/artifacts/binding-target-identity.js +51 -0
- package/dist/src/artifacts/checksum-manifest.js +12 -0
- package/dist/src/artifacts/index-builder.js +11 -13
- package/dist/src/artifacts/query-engine.js +5 -11
- package/dist/src/cli/handlers/doctor-help.js +32 -0
- package/dist/src/cli/handlers/gates.js +19 -18
- package/dist/src/cli/handlers/models-help.js +7 -1
- package/dist/src/cli/handlers/models.js +3 -3
- package/dist/src/cli/handlers/script-runner.js +8 -5
- package/dist/src/cli/handlers/sessions-intake.js +104 -0
- package/dist/src/cli/handlers/sessions-tail.js +172 -0
- package/dist/src/cli/handlers/sessions.js +90 -17
- package/dist/src/cli/handlers/skill-lint.js +10 -3
- package/dist/src/cli/handlers/steward-format.js +100 -0
- package/dist/src/cli/handlers/steward-models.js +167 -0
- package/dist/src/cli/handlers/steward.js +14 -248
- package/dist/src/cli/handlers/use-bundle-counts.js +87 -0
- package/dist/src/cli/handlers/use-skill-assets.js +207 -0
- package/dist/src/cli/handlers/use.js +35 -216
- package/dist/src/cli/handlers/utilities.js +1 -24
- package/dist/src/config/aiwg-config.js +7 -0
- package/dist/src/config/authorization-cli.js +97 -0
- package/dist/src/config/cli-help.js +1 -0
- package/dist/src/config/cli.js +10 -1
- package/dist/src/decision/context-pruning-common.js +41 -0
- package/dist/src/decision/context-pruning-evaluation.js +366 -0
- package/dist/src/decision/context-pruning-pilot.js +431 -0
- package/dist/src/decision/context-pruning-types.js +19 -0
- package/dist/src/decision/context-pruning.js +5 -846
- package/dist/src/decision/ensemble/contract.js +17 -26
- package/dist/src/decision/ensemble-study/artifacts.js +5 -0
- package/dist/src/decision/ensemble-study/score.js +4 -3
- package/dist/src/decision/feature-export.js +3 -9
- package/dist/src/decision/heldout/collector.js +2 -2
- package/dist/src/decision/issue-triage/runtime.js +3 -9
- package/dist/src/decision/qualification/gates.js +2 -1
- package/dist/src/decision/qualification/release.js +6 -64
- package/dist/src/decision/routing/report.js +2 -0
- package/dist/src/decision/sdlc-screening.js +3 -5
- package/dist/src/decision/sensitivity/comparative.js +5 -3
- package/dist/src/extensions/manifest.js +8 -1
- package/dist/src/extensions/project-local-doctor.js +78 -2
- package/dist/src/extensions/validation.js +10 -11
- package/dist/src/gates/driver.js +6 -77
- package/dist/src/gates/evaluate.js +6 -23
- package/dist/src/gates/floors.js +4 -4
- package/dist/src/gates/index.js +3 -3
- package/dist/src/gates/lattice.js +26 -0
- package/dist/src/gates/registry.js +2 -1
- package/dist/src/gates/report.js +19 -7
- package/dist/src/gates/upstream-ceiling.js +111 -0
- package/dist/src/issues/audit-cli.js +120 -0
- package/dist/src/issues/audit-contract.js +64 -0
- package/dist/src/issues/audit-local.js +82 -0
- package/dist/src/issues/audit.js +220 -0
- package/dist/src/lint/rule-activation.js +15 -1
- package/dist/src/mission-protocol/canonical-codecs.js +270 -0
- package/dist/src/mission-protocol/codecs.js +22 -550
- package/dist/src/mission-protocol/health-trace-codecs.js +281 -0
- package/dist/src/mission-protocol/health-trace-types.js +43 -0
- package/dist/src/mission-protocol/types.js +2 -42
- package/dist/src/mission-protocol/worker-contract-json.js +10 -0
- package/dist/src/mission-protocol/worker-review-gate.js +100 -0
- package/dist/src/mission-protocol/worker-review-types.js +2 -0
- package/dist/src/models/catalog-policy.js +280 -0
- package/dist/src/models/index.js +1 -1
- package/dist/src/models/model-catalog.v1.json +62 -12
- package/dist/src/models/policy-resources.js +28 -0
- package/dist/src/models/provider-models.js +5 -8
- package/dist/src/models/provider-policy.js +10 -546
- package/dist/src/models/resolver.js +26 -8
- package/dist/src/models/router.js +15 -2
- package/dist/src/models/tiers.js +13 -0
- package/dist/src/models/types.js +0 -6
- package/dist/src/models/worker-ceilings.js +59 -0
- package/dist/src/models/worker-invocation-policy.js +243 -0
- package/dist/src/models/worker-plan.js +16 -20
- package/dist/src/models/worker-review-lineage.js +55 -0
- package/dist/src/models/worker-selection-policy.js +1 -1
- package/dist/src/models/wrapper-definitions.js +14 -0
- package/dist/src/models/wrapper-deployment.js +48 -25
- package/dist/src/models/wrapper-enforcement.js +72 -0
- package/dist/src/models/wrapper-route.js +6 -3
- package/dist/src/policy/authorization.js +1 -0
- package/dist/src/policy/hitl-check.js +80 -0
- package/dist/src/policy/hitl-config.js +63 -0
- package/dist/src/policy/hitl-receipt.js +57 -0
- package/dist/src/policy/hitl-types.js +4 -0
- package/dist/src/policy/hitl-validation.js +39 -0
- package/dist/src/policy/hitl.js +117 -0
- package/dist/src/rules/activation.d.mts +3 -1
- package/dist/src/rules/activation.mjs +23 -2
- package/dist/src/rules/gate-coverage.js +51 -0
- package/dist/src/rules/gate-references.js +16 -0
- package/dist/src/rules/rule-frontmatter.schema.json +7 -1
- package/dist/src/serve/worker-command-request.js +21 -4
- package/dist/src/serve/worker-invocation-preparation.js +3 -1
- package/dist/src/serve/worker-invocation.js +21 -10
- package/dist/src/sessions/adapters/deepseek-harness.js +1 -0
- package/dist/src/sessions/adapters/grok-build-native.js +269 -0
- package/dist/src/sessions/adapters/grok-build.js +57 -15
- package/dist/src/sessions/adapters/hermes-state-db.js +252 -0
- package/dist/src/sessions/adapters/hermes.js +42 -3
- package/dist/src/sessions/adapters/warp.js +1 -1
- package/dist/src/sessions/batch-import.js +10 -0
- package/dist/src/sessions/contracts.js +1 -1
- package/dist/src/sessions/discovery-capability.js +38 -0
- package/dist/src/sessions/importer.js +8 -251
- package/dist/src/sessions/index.js +4 -0
- package/dist/src/sessions/intake-dir.js +71 -0
- package/dist/src/sessions/normalization.js +251 -0
- package/dist/src/sessions/tail.js +91 -0
- package/dist/src/sessions/workspace-discovery.js +83 -7
- package/dist/src/skills/adapters/local.js +32 -9
- package/dist/src/skills/agent-skill-sidecar.js +28 -0
- package/dist/src/skills/agent-skills.js +6 -23
- package/dist/src/skills/claude-surface-projection.js +25 -0
- package/dist/src/skills/cli-display.js +33 -0
- package/dist/src/skills/cli.js +2 -26
- package/dist/src/skills/collision-discovery.js +84 -0
- package/dist/src/skills/deployer.js +26 -361
- package/dist/src/skills/deployment-ownership.js +74 -0
- package/dist/src/skills/deployment-policy.js +114 -0
- package/dist/src/skills/deployment-projection.js +152 -0
- package/dist/src/skills/deployment-types.js +20 -0
- package/dist/src/skills/doctor.js +2 -2
- package/dist/src/skills/exporter.js +8 -31
- package/dist/src/skills/importer.js +4 -26
- package/dist/src/skills/provider-extensions.js +41 -0
- package/dist/src/skills/registry.js +22 -7
- package/dist/src/skills/run.js +6 -0
- package/dist/src/skills/types.js +0 -8
- package/dist/src/skills/validator-resources.js +68 -0
- package/dist/src/skills/validator.js +6 -55
- package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
- package/dist/src/storage/cli-migrate-options.js +125 -0
- package/dist/src/storage/cli-migrate.js +111 -0
- package/dist/src/storage/cli.js +4 -279
- package/dist/src/storage/migration-adapter.js +79 -0
- package/dist/src/storage/migration-copy.js +108 -0
- package/dist/src/storage/migration-protocol.js +14 -197
- package/dist/src/storage/migration-records.js +186 -0
- package/dist/src/storage/migration-types.js +12 -0
- package/dist/src/tracker/forge-http.js +2 -1
- package/dist/src/tracker/issue-pages.js +110 -0
- package/package.json +3 -1
- package/schemas/mission-v1.schema.json +335 -0
- package/schemas/models/model-catalog.v1.schema.json +19 -1
- package/schemas/models/model-config-compatibility.v1.schema.json +3 -2
- package/schemas/models/model-policy.v1.schema.json +1 -1
- package/tools/agents/providers/antigravity.mjs +3 -5
- package/tools/agents/providers/base.mjs +3 -3
- package/tools/agents/providers/claude.mjs +3 -5
- package/tools/agents/providers/codex.mjs +3 -5
- package/tools/agents/providers/copilot.mjs +3 -5
- package/tools/agents/providers/cursor.mjs +3 -5
- package/tools/agents/providers/factory.mjs +3 -5
- package/tools/agents/providers/grok-build.mjs +9 -7
- package/tools/agents/providers/model-wrapper.mjs +86 -0
- package/tools/agents/providers/omp.mjs +3 -1
- package/tools/agents/providers/openclaw.mjs +3 -5
- package/tools/agents/providers/opencode.mjs +3 -5
- package/tools/agents/providers/provider-paths-staging.mjs +44 -0
- package/tools/agents/providers/rule-binding-targets.mjs +146 -0
- package/tools/agents/providers/rule-delivery.mjs +9 -128
- package/tools/agents/providers/warp.mjs +3 -5
- package/tools/agents/providers/windsurf.mjs +3 -5
- package/tools/plugin/package-plugins.mjs +2 -2
- package/tools/skills/codex-skill-transform.mjs +232 -0
- package/tools/skills/deploy-skills-codex.mjs +8 -249
- package/tools/warp/warp-content.mjs +548 -0
- package/vscode-extension/schemas/aiwg.config.v1.json +177 -0
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { load as loadYaml } from 'js-yaml';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
reasoning: 'premium',
|
|
7
|
-
coding: 'standard',
|
|
8
|
-
efficiency: 'economy',
|
|
9
|
-
};
|
|
10
|
-
const EFFORTS = {
|
|
11
|
-
reasoning: 'high',
|
|
12
|
-
coding: 'medium',
|
|
13
|
-
efficiency: 'low',
|
|
14
|
-
};
|
|
4
|
+
import { MODEL_WRAPPER_DEFINITIONS } from './wrapper-definitions.js';
|
|
5
|
+
import { isFlagshipModel } from './tiers.js';
|
|
15
6
|
const CLAUDE_ALIASES = {
|
|
16
7
|
reasoning: 'opus',
|
|
17
8
|
coding: 'sonnet',
|
|
@@ -66,7 +57,7 @@ function artifactFields(file, content) {
|
|
|
66
57
|
if (/\.json$/i.test(file)) {
|
|
67
58
|
try {
|
|
68
59
|
const parsed = JSON.parse(content);
|
|
69
|
-
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
60
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
|
|
70
61
|
}
|
|
71
62
|
catch {
|
|
72
63
|
return null;
|
|
@@ -94,38 +85,69 @@ function addMismatch(mismatches, wrapper, file, field, reason, expected, actual)
|
|
|
94
85
|
reason,
|
|
95
86
|
});
|
|
96
87
|
}
|
|
97
|
-
async function validateArtifact(file,
|
|
98
|
-
const wrapper =
|
|
88
|
+
async function validateArtifact(file, definition, expectation) {
|
|
89
|
+
const { name: wrapper, role, tier, effort, readOnly } = definition;
|
|
99
90
|
const mismatches = [];
|
|
100
91
|
const content = await fs.readFile(file, 'utf8');
|
|
101
92
|
if (!content.trim()) {
|
|
102
93
|
addMismatch(mismatches, wrapper, file, 'content', 'wrapper artifact is empty');
|
|
103
94
|
return mismatches;
|
|
104
95
|
}
|
|
105
|
-
const fields = artifactFields(file, content)
|
|
96
|
+
const fields = artifactFields(file, content)
|
|
97
|
+
?? (expectation.provider === 'windsurf' && content.includes(`### ${wrapper}`) ? { name: wrapper } : null);
|
|
106
98
|
if (!fields) {
|
|
107
99
|
addMismatch(mismatches, wrapper, file, 'format', 'wrapper artifact is malformed or has no parseable metadata');
|
|
108
100
|
return mismatches;
|
|
109
101
|
}
|
|
110
|
-
const actualName = fieldValue(fields, 'name');
|
|
102
|
+
const actualName = fieldValue(fields, 'name') ?? (expectation.provider === 'opencode' ? wrapper : undefined);
|
|
111
103
|
if (actualName !== wrapper)
|
|
112
104
|
addMismatch(mismatches, wrapper, file, 'name', 'wrapper identity does not match its deployed filename', wrapper, actualName);
|
|
113
105
|
const actualRole = fieldValue(fields, 'model-role', 'modelRole', 'aiwg-model-role');
|
|
114
106
|
if (actualRole && actualRole !== role)
|
|
115
107
|
addMismatch(mismatches, wrapper, file, 'model-role', 'wrapper role is stale or mismatched', role, actualRole);
|
|
116
108
|
const actualTier = fieldValue(fields, 'model-tier', 'modelTier', 'aiwg-model-tier');
|
|
117
|
-
|
|
118
|
-
|
|
109
|
+
const standardFallback = tier === 'economy' && actualTier === 'standard'
|
|
110
|
+
&& (readOnly || expectation.provider === 'cursor');
|
|
111
|
+
if (actualTier && actualTier !== tier && !standardFallback)
|
|
112
|
+
addMismatch(mismatches, wrapper, file, 'model-tier', 'wrapper tier is stale or mismatched', tier, actualTier);
|
|
119
113
|
const actualModel = fieldValue(fields, 'model', 'model_hint', 'modelHint');
|
|
120
114
|
const expectedModel = expectation.models?.[role];
|
|
115
|
+
if (actualModel && isFlagshipModel(actualModel))
|
|
116
|
+
addMismatch(mismatches, wrapper, file, 'model', 'wrapper model is flagship; wrappers cannot elect flagship', undefined, actualModel);
|
|
117
|
+
if (readOnly) {
|
|
118
|
+
if (expectation.provider === 'codex' && fields.sandbox_mode !== 'read-only')
|
|
119
|
+
addMismatch(mismatches, wrapper, file, 'sandbox_mode', 'read-only wrapper must use the native read-only sandbox', 'read-only', fieldValue(fields, 'sandbox_mode'));
|
|
120
|
+
const tools = Array.isArray(fields.tools) ? fields.tools : typeof fields.tools === 'string' ? fields.tools.split(/[,\s]+/) : [];
|
|
121
|
+
if (['claude', 'copilot', 'factory', 'omp', 'antigravity', 'openclaw'].includes(expectation.provider ?? '') && tools.length === 0)
|
|
122
|
+
addMismatch(mismatches, wrapper, file, 'tools', 'read-only wrapper is missing its explicit tool allowlist');
|
|
123
|
+
if (tools.some(tool => /^(?:write|edit|create|apply[_-]?patch|multiedit|task|agent|write_to_file|replace_file_content)$/i.test(String(tool))))
|
|
124
|
+
addMismatch(mismatches, wrapper, file, 'tools', 'read-only wrapper exposes mutation or delegation tools');
|
|
125
|
+
const allowlists = {
|
|
126
|
+
claude: ['Read', 'Grep', 'Glob', 'Bash'], copilot: ['search/codebase', 'terminal'],
|
|
127
|
+
factory: ['Execute', 'Glob', 'Grep', 'Read'], omp: ['read', 'grep', 'glob', 'bash'],
|
|
128
|
+
antigravity: ['view_file', 'grep_search', 'run_command'], openclaw: ['Read', 'Grep', 'Glob', 'Bash'],
|
|
129
|
+
};
|
|
130
|
+
const allowed = allowlists[expectation.provider ?? ''];
|
|
131
|
+
if (allowed && (tools.length !== allowed.length || allowed.some(tool => !tools.includes(tool))))
|
|
132
|
+
addMismatch(mismatches, wrapper, file, 'tools', 'read-only wrapper tools differ from the provider allowlist');
|
|
133
|
+
if (expectation.provider === 'opencode') {
|
|
134
|
+
const permissions = fields.permission;
|
|
135
|
+
if (permissions?.edit !== 'deny' || permissions?.task !== 'deny' || permissions?.['*'] !== 'deny')
|
|
136
|
+
addMismatch(mismatches, wrapper, file, 'permission', 'read-only wrapper must deny edits, delegation and unlisted tools');
|
|
137
|
+
}
|
|
138
|
+
if (expectation.provider === 'cursor' && fields.readonly !== true)
|
|
139
|
+
addMismatch(mismatches, wrapper, file, 'readonly', 'Cursor wrapper must enable its native read-only control');
|
|
140
|
+
if (!content.includes('WorkerClaims') || !content.includes('criterion') || !content.includes('Stop rules'))
|
|
141
|
+
addMismatch(mismatches, wrapper, file, 'return-contract', 'read-only wrapper is missing its condensed worker return contract');
|
|
142
|
+
}
|
|
121
143
|
if (expectation.provider === 'codex') {
|
|
122
144
|
if (!actualModel)
|
|
123
145
|
addMismatch(mismatches, wrapper, file, 'model', 'Codex wrapper has no exact model pin', expectedModel);
|
|
124
146
|
else if (expectedModel && actualModel !== expectedModel)
|
|
125
147
|
addMismatch(mismatches, wrapper, file, 'model', 'Codex wrapper model does not match the effective catalog', expectedModel, actualModel);
|
|
126
148
|
const actualEffort = fieldValue(fields, 'model_reasoning_effort');
|
|
127
|
-
if (actualEffort !==
|
|
128
|
-
addMismatch(mismatches, wrapper, file, 'model_reasoning_effort', 'Codex wrapper effort does not match its role',
|
|
149
|
+
if (actualEffort !== effort)
|
|
150
|
+
addMismatch(mismatches, wrapper, file, 'model_reasoning_effort', 'Codex wrapper effort does not match its role', effort, actualEffort);
|
|
129
151
|
if (!fieldValue(fields, 'developer_instructions'))
|
|
130
152
|
addMismatch(mismatches, wrapper, file, 'developer_instructions', 'Codex wrapper has no bootstrap instructions', 'non-empty');
|
|
131
153
|
}
|
|
@@ -136,26 +158,27 @@ async function validateArtifact(file, role, expectation) {
|
|
|
136
158
|
if (!actualRole)
|
|
137
159
|
addMismatch(mismatches, wrapper, file, 'model-role', 'Claude wrapper is missing its canonical role', role);
|
|
138
160
|
if (!actualTier)
|
|
139
|
-
addMismatch(mismatches, wrapper, file, 'model-tier', 'Claude wrapper is missing its canonical tier',
|
|
161
|
+
addMismatch(mismatches, wrapper, file, 'model-tier', 'Claude wrapper is missing its canonical tier', tier);
|
|
140
162
|
}
|
|
141
163
|
return mismatches;
|
|
142
164
|
}
|
|
143
165
|
export async function verifyModelWrapperDeployment(agentsPath, expectation = {}) {
|
|
144
|
-
const expected =
|
|
166
|
+
const expected = MODEL_WRAPPER_DEFINITIONS;
|
|
145
167
|
if (!agentsPath)
|
|
146
168
|
return {
|
|
147
169
|
supported: false,
|
|
148
170
|
valid: false,
|
|
149
171
|
agentsPath: null,
|
|
150
172
|
found: [],
|
|
151
|
-
missing: expected.map((
|
|
173
|
+
missing: expected.map(({ name }) => name),
|
|
152
174
|
mismatches: [],
|
|
153
175
|
};
|
|
154
176
|
const files = await collectFiles(agentsPath);
|
|
155
177
|
const found = [];
|
|
156
178
|
const missing = [];
|
|
157
179
|
const mismatches = [];
|
|
158
|
-
for (const
|
|
180
|
+
for (const definition of expected) {
|
|
181
|
+
const wrapper = definition.name;
|
|
159
182
|
const matches = files.filter(file => path.basename(file).replace(/(?:\.agent)?\.(?:md|toml|json|yaml|yml)$/i, '') === wrapper);
|
|
160
183
|
if (matches.length === 0) {
|
|
161
184
|
missing.push(wrapper);
|
|
@@ -164,7 +187,7 @@ export async function verifyModelWrapperDeployment(agentsPath, expectation = {})
|
|
|
164
187
|
found.push(wrapper);
|
|
165
188
|
if (matches.length > 1)
|
|
166
189
|
addMismatch(mismatches, wrapper, matches[0], 'path', `multiple deployed wrapper artifacts found: ${matches.join(', ')}`);
|
|
167
|
-
mismatches.push(...await validateArtifact(matches[0],
|
|
190
|
+
mismatches.push(...await validateArtifact(matches[0], definition, expectation));
|
|
168
191
|
}
|
|
169
192
|
return {
|
|
170
193
|
supported: true,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Describes controls on deployed wrapper artifacts, distinct from headless CLI controls.
|
|
2
|
+
import { compileModelPolicy, loadProviderModelCatalog } from './catalog-policy.js';
|
|
3
|
+
import { MODEL_WRAPPER_DEFINITIONS } from './wrapper-definitions.js';
|
|
4
|
+
const NATIVE_CONTROLS = {
|
|
5
|
+
claude: { model: 'model', effort: 'effort' },
|
|
6
|
+
codex: { model: 'model', effort: 'model_reasoning_effort' },
|
|
7
|
+
copilot: { model: 'model' }, cursor: { model: 'model' },
|
|
8
|
+
factory: { model: 'model', effort: 'reasoningEffort' },
|
|
9
|
+
opencode: { model: 'model' }, omp: { model: 'model', effort: 'thinkingLevel' },
|
|
10
|
+
};
|
|
11
|
+
const GLOBAL_ONLY = new Set(['warp', 'hermes', 'grokbot', 'muse']);
|
|
12
|
+
export function wrapperControls(provider) {
|
|
13
|
+
return NATIVE_CONTROLS[provider] ?? {};
|
|
14
|
+
}
|
|
15
|
+
export function isConcreteWrapperModel(model) {
|
|
16
|
+
return Boolean(model && !/^(?:configured\/|Hint\(|auto$|inherit(?:ed)?$|default$|profile-selected$|global-delegation-model$)/i.test(model));
|
|
17
|
+
}
|
|
18
|
+
export function resolveWrapperPin(provider, wrapper, options = {}) {
|
|
19
|
+
const controls = wrapperControls(provider);
|
|
20
|
+
const catalog = options.catalog ?? loadProviderModelCatalog();
|
|
21
|
+
let tier = wrapper.tier;
|
|
22
|
+
let role = wrapper.role;
|
|
23
|
+
const compile = () => compileModelPolicy({ provider, artifact: 'agent', catalog,
|
|
24
|
+
policy: { role, tier, effort: options.effort ?? wrapper.effort,
|
|
25
|
+
...(options.override ? { override: options.override } : {}) } });
|
|
26
|
+
let policy = compile();
|
|
27
|
+
// Auto can select a flagship; every economy wrapper needs the concrete fallback.
|
|
28
|
+
if (controls.model && policy.effectiveModel === 'auto' && !options.override) {
|
|
29
|
+
tier = 'standard';
|
|
30
|
+
role = 'coding';
|
|
31
|
+
policy = compile();
|
|
32
|
+
}
|
|
33
|
+
if (controls.model && options.override && !isConcreteWrapperModel(options.override)) {
|
|
34
|
+
throw new Error(`${provider}: wrapper override must be a concrete model pin`);
|
|
35
|
+
}
|
|
36
|
+
const model = controls.model && isConcreteWrapperModel(policy.effectiveModel) ? policy.effectiveModel : undefined;
|
|
37
|
+
const effort = model && controls.effort ? policy.fields[controls.effort] : undefined;
|
|
38
|
+
if (model && controls.effort && !effort)
|
|
39
|
+
throw new Error(`${provider}: unsupported wrapper effort`);
|
|
40
|
+
return { tier, role, model, effort, controls,
|
|
41
|
+
enforcement: (GLOBAL_ONLY.has(provider) ? 'global-only' : model ? 'pinned' : 'inherited') };
|
|
42
|
+
}
|
|
43
|
+
/** Static artifact defaults; this does not inspect live sessions or assert runtime enforcement. */
|
|
44
|
+
export function wrapperEnforcementReport(provider) {
|
|
45
|
+
const catalog = loadProviderModelCatalog();
|
|
46
|
+
const controls = wrapperControls(provider);
|
|
47
|
+
const known = provider in catalog.providers;
|
|
48
|
+
const states = known ? MODEL_WRAPPER_DEFINITIONS.map(wrapper => resolveWrapperPin(provider, wrapper, { catalog }).enforcement) : [];
|
|
49
|
+
const state = GLOBAL_ONLY.has(provider) ? 'global-only'
|
|
50
|
+
: states.length > 0 && states.every(value => value === 'pinned') ? 'pinned' : 'inherited';
|
|
51
|
+
const effort = state === 'pinned' && controls.effort
|
|
52
|
+
? `pinned via ${controls.effort} (high/medium/low by wrapper)` : 'not enforced per wrapper';
|
|
53
|
+
const details = {
|
|
54
|
+
claude: 'Use AIWG wrappers or an explicit invocation model. Unpinned general-purpose agents inherit; CLAUDE_CODE_SUBAGENT_MODEL supplies a fallback and CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 can override pins.',
|
|
55
|
+
omp: 'Native model and thinkingLevel fields can pin exact operator role models; configured/* catalog entries are placeholders.',
|
|
56
|
+
'grok-build': 'Not enforced: native-agent model translation remains gated by #2577; configured selectors do not establish tier enforcement.',
|
|
57
|
+
openclaw: 'Markdown wrapper mirrors do not set native subagents.model or per-spawn overrides.',
|
|
58
|
+
openhuman: 'User harness wrappers carry semantic model hints; project wrappers omit model. Neither is an exact pin.',
|
|
59
|
+
antigravity: 'Wrapper mirrors do not project native CLI model/effort flags.',
|
|
60
|
+
windsurf: 'Portable wrapper model selection is unsupported; the main UI session controls selection.',
|
|
61
|
+
pi: 'Agents are reference skills; CLI model/thinking flags are separate from deployed wrappers.',
|
|
62
|
+
'deepseek-harness': 'Agent references do not pin the configured Harness route.',
|
|
63
|
+
hermes: 'All delegated workers share the provider delegation configuration.',
|
|
64
|
+
warp: 'Model selection follows the Warp run/profile.',
|
|
65
|
+
grokbot: 'No verified AIWG-owned per-worker model setting is available.',
|
|
66
|
+
muse: 'Session --model or settings.json model controls selection; per-agent pins are unverified.',
|
|
67
|
+
};
|
|
68
|
+
return `Tier enforcement (generated wrapper defaults): ${state}; effort: ${effort}. `
|
|
69
|
+
+ `${details[provider] ?? (known ? 'Native custom subagents carry explicit catalog model selectors.' : 'Provider wrapper controls are unverified.')} `
|
|
70
|
+
+ 'Explicit operator pins are preserved where supported. This is not a live resolved-model audit; provider/account policy may substitute models.';
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=wrapper-enforcement.js.map
|
|
@@ -5,7 +5,7 @@ import { resolveWorkerPlan } from './resolver.js';
|
|
|
5
5
|
function roleForTier(tier) {
|
|
6
6
|
if (tier === 'economy')
|
|
7
7
|
return 'efficiency';
|
|
8
|
-
if (tier === 'premium' || tier === 'max-quality')
|
|
8
|
+
if (tier === 'premium' || tier === 'flagship' || tier === 'max-quality')
|
|
9
9
|
return 'reasoning';
|
|
10
10
|
if (tier === 'standard')
|
|
11
11
|
return 'coding';
|
|
@@ -14,7 +14,7 @@ function roleForTier(tier) {
|
|
|
14
14
|
export function buildWrapperRouteEnvelope(request) {
|
|
15
15
|
if (!request.assignment.trim())
|
|
16
16
|
throw new Error('Wrapper routing requires a bounded assignment.');
|
|
17
|
-
const decision = routeModelTier(request);
|
|
17
|
+
const decision = routeModelTier({ ...request, agentName: request.agentName ?? request.capability.name });
|
|
18
18
|
if (request.worker?.snapshot.config.parallelism?.worker_dispatch && !request.deterministic) {
|
|
19
19
|
const worker = resolveWorkerPlan(request.worker.snapshot, {
|
|
20
20
|
...request.worker.request,
|
|
@@ -39,7 +39,10 @@ export function buildWrapperRouteEnvelope(request) {
|
|
|
39
39
|
? compileModelPolicy({
|
|
40
40
|
provider: request.provider,
|
|
41
41
|
artifact: 'agent',
|
|
42
|
-
policy: { role, tier
|
|
42
|
+
policy: { role, tier },
|
|
43
|
+
election: request.election,
|
|
44
|
+
flagshipAllowlist: request.flagshipAllowlist,
|
|
45
|
+
agentName: request.agentName ?? request.capability.name,
|
|
43
46
|
...(request.catalog ? { catalog: request.catalog } : {}),
|
|
44
47
|
})
|
|
45
48
|
: null;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { access, copyFile, mkdir, readFile, rename } from 'node:fs/promises';
|
|
10
10
|
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
11
11
|
import { load as loadYaml } from 'js-yaml';
|
|
12
|
+
export { resolveHitlAuthorization } from './hitl.js';
|
|
12
13
|
import { projectAiwgPath, projectControlPath } from '../config/project-artifacts.js';
|
|
13
14
|
/**
|
|
14
15
|
* Export provider mappings without inventing provider grants. Stable IDs,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Checks host-classified effects and requires a verified signed receipt before suppressing a workflow prompt.
|
|
2
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
4
|
+
import { effectSession, openLedger } from '../effects/host.js';
|
|
5
|
+
import { loadHitlLayers } from './hitl-config.js';
|
|
6
|
+
import { recordHitlAuthorization } from './hitl-receipt.js';
|
|
7
|
+
import { resolveHitlAuthorization, validHitlAction } from './hitl.js';
|
|
8
|
+
/** Resolve existing ancestors as well as new leaves; dangling links fail closed. */
|
|
9
|
+
async function canonical(path) {
|
|
10
|
+
try {
|
|
11
|
+
return await realpath(path);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code !== 'ENOENT')
|
|
15
|
+
throw error;
|
|
16
|
+
try {
|
|
17
|
+
await lstat(path);
|
|
18
|
+
throw new Error('Unresolved action symlink');
|
|
19
|
+
}
|
|
20
|
+
catch (statError) {
|
|
21
|
+
if (statError.code !== 'ENOENT')
|
|
22
|
+
throw statError;
|
|
23
|
+
}
|
|
24
|
+
const parent = dirname(path);
|
|
25
|
+
if (parent === path)
|
|
26
|
+
throw error;
|
|
27
|
+
return resolve(await canonical(parent), basename(path));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const policyPath = (path) => /(^|\/)(aiwg\.config|AGENTS\.md|WORKSPACE\.md|AIWG\.md|CLAUDE\.md)$/.test(path)
|
|
31
|
+
|| /(^|\/)(rules|policies|hooks)(\/|$)/.test(path)
|
|
32
|
+
|| /^(\.git|\.claude|\.codex|\.agents|\.github|\.gitea)(\/|$)/.test(path);
|
|
33
|
+
const secretPath = (path) => /(^|\/)(\.env(?:\.[^/]*)?|\.ssh|\.aws|credentials?|tokens?|secrets?)(\/|$)/i.test(path);
|
|
34
|
+
/** Input is a host descriptor, never an issue, model response, or authorization claim. */
|
|
35
|
+
export async function canonicalHitlAction(projectDir, input) {
|
|
36
|
+
if (!validHitlAction(input))
|
|
37
|
+
return input;
|
|
38
|
+
const root = await realpath(projectDir);
|
|
39
|
+
const resources = [];
|
|
40
|
+
for (const path of input.resources) {
|
|
41
|
+
const resource = relative(root, await canonical(resolve(root, path))).split('\\').join('/');
|
|
42
|
+
if (!resource || resource === '..' || resource.startsWith('../') || isAbsolute(resource))
|
|
43
|
+
return null;
|
|
44
|
+
resources.push(resource);
|
|
45
|
+
}
|
|
46
|
+
const action = { ...input, resources: [...new Set(resources)].sort() };
|
|
47
|
+
// Check both spellings: an alias must not hide a protected resource.
|
|
48
|
+
const paths = [...input.resources, ...resources];
|
|
49
|
+
if (paths.some(secretPath))
|
|
50
|
+
action.category = 'secret.access';
|
|
51
|
+
else if (action.category !== 'repo.read' && paths.some(policyPath))
|
|
52
|
+
action.category = 'policy.override';
|
|
53
|
+
return action;
|
|
54
|
+
}
|
|
55
|
+
/** No receipt, no automatic action. Errors retain the caller's existing review path. */
|
|
56
|
+
export async function checkHitlAuthorization(projectDir, input, options = {}) {
|
|
57
|
+
let context = { now: new Date().toISOString(), layers: [], ...options };
|
|
58
|
+
try {
|
|
59
|
+
const loaded = await loadHitlLayers(projectDir);
|
|
60
|
+
context = { ...context, layers: loaded.layers };
|
|
61
|
+
const action = await canonicalHitlAction(loaded.projectDir, input);
|
|
62
|
+
const decision = resolveHitlAuthorization(action, context);
|
|
63
|
+
if (decision.decision !== 'auto-authorized')
|
|
64
|
+
return decision;
|
|
65
|
+
// Reload policies and the clock at consumption time, including expiry and revocation.
|
|
66
|
+
context = { ...context, now: new Date().toISOString(), layers: (await loadHitlLayers(projectDir)).layers,
|
|
67
|
+
expectedPolicyVersion: options.expectedPolicyVersion ?? decision.policyVersion };
|
|
68
|
+
const ledger = openLedger(await effectSession(loaded.projectDir, 'custom'));
|
|
69
|
+
const recorded = await recordHitlAuthorization(ledger, action, context);
|
|
70
|
+
if (recorded.resolution.decision !== 'auto-authorized')
|
|
71
|
+
return recorded.resolution;
|
|
72
|
+
if (recorded.reconciled.result.verification.result !== 'present')
|
|
73
|
+
throw new Error('Unverified HITL receipt');
|
|
74
|
+
return { ...recorded.resolution, receipt: { file: recorded.file, effectId: recorded.intent.effectId } };
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return { ...resolveHitlAuthorization(null, context), decision: 'escalate', reason: 'authorization-check-unavailable' };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=hitl-check.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Loads governing workspace/member policies without merging or broadening their grants.
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
4
|
+
import { getConfigPath, readAiwgConfigCandidate } from '../config/aiwg-config.js';
|
|
5
|
+
export function ensureAuthorization(config) {
|
|
6
|
+
return config.authorization ??= { version: '1', default_effect: 'deny', resources: {}, permissions: {}, roles: {}, assignments: [] };
|
|
7
|
+
}
|
|
8
|
+
const inside = (child, root) => {
|
|
9
|
+
const path = relative(root, child);
|
|
10
|
+
return path === '' || (path !== '..' && !path.startsWith('../') && !isAbsolute(path));
|
|
11
|
+
};
|
|
12
|
+
async function canonicalDirectory(path) {
|
|
13
|
+
try {
|
|
14
|
+
return await realpath(path);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error.code !== 'ENOENT')
|
|
18
|
+
throw error;
|
|
19
|
+
const parent = dirname(path);
|
|
20
|
+
if (parent === path)
|
|
21
|
+
throw error;
|
|
22
|
+
return resolve(await canonicalDirectory(parent), basename(path));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Each config boundary narrows grants. A member without HITL policy cannot inherit approval. */
|
|
26
|
+
export async function loadHitlLayers(start) {
|
|
27
|
+
const layers = [];
|
|
28
|
+
const seen = new Set();
|
|
29
|
+
let current = await canonicalDirectory(resolve(start));
|
|
30
|
+
let projectDir;
|
|
31
|
+
let child;
|
|
32
|
+
while (true) {
|
|
33
|
+
if (seen.has(current))
|
|
34
|
+
throw new Error('Cyclic HITL workspace membership');
|
|
35
|
+
seen.add(current);
|
|
36
|
+
const config = await readAiwgConfigCandidate(current);
|
|
37
|
+
if (config) {
|
|
38
|
+
projectDir ??= current;
|
|
39
|
+
if (child && config.repos) {
|
|
40
|
+
const root = await canonicalDirectory(resolve(current, config.workspace?.root ?? '.'));
|
|
41
|
+
const members = await Promise.all(config.repos.map(repo => canonicalDirectory(resolve(root, repo.path))));
|
|
42
|
+
if (!members.some(member => inside(child, member))) {
|
|
43
|
+
throw new Error('HITL workspace does not declare this member');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
layers.unshift({ source: getConfigPath(current), policy: config.authorization?.hitl });
|
|
47
|
+
child = current;
|
|
48
|
+
if (config.workspace?.member_of) {
|
|
49
|
+
current = await canonicalDirectory(resolve(current, config.workspace.member_of));
|
|
50
|
+
const parent = await readAiwgConfigCandidate(current);
|
|
51
|
+
if (!parent?.repos)
|
|
52
|
+
throw new Error('HITL workspace.member_of must name a workspace manifest');
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const parent = dirname(current);
|
|
57
|
+
if (parent === current)
|
|
58
|
+
break;
|
|
59
|
+
current = parent;
|
|
60
|
+
}
|
|
61
|
+
return { projectDir: projectDir ?? resolve(start), layers };
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=hitl-config.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Records a credential-free decision artifact through existing effect intent/reconcile receipts.
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { projectAiwgWritePath, resolveProjectAiwgDirForWrite } from '../config/project-artifacts.js';
|
|
5
|
+
import { recordIntent, reconcileEffect } from '../effects/ledger.js';
|
|
6
|
+
import { payloadDigest } from '../effects/identity.js';
|
|
7
|
+
import { assertDigestOnly } from '../effects/redaction.js';
|
|
8
|
+
import { fileDigestVerifier } from '../effects/verifiers/file.js';
|
|
9
|
+
import { createVerifierRegistry } from '../effects/verifiers/registry.js';
|
|
10
|
+
import { hitlDigest, resolveHitlAuthorization, validHitlAction } from './hitl.js';
|
|
11
|
+
import { HITL_CATEGORIES, HITL_ENVIRONMENTS } from './hitl-types.js';
|
|
12
|
+
/** Resolve again at receipt time. A preview result supplied by an agent is never trusted. */
|
|
13
|
+
export async function recordHitlAuthorization(ledger, action, context) {
|
|
14
|
+
const resolution = resolveHitlAuthorization(action, context);
|
|
15
|
+
const receipt = {
|
|
16
|
+
kind: 'hitl-authorization', evaluatedAtDigest: hitlDigest(context.now),
|
|
17
|
+
sessionGrantDigest: hitlDigest(context.sessionAuthorization ?? null), ...resolution,
|
|
18
|
+
// Arbitrary user strings become digests, including paths, repo identity and profile names.
|
|
19
|
+
matchedProfile: resolution.matchedProfile ? hitlDigest(resolution.matchedProfile) : null,
|
|
20
|
+
action: validHitlAction(action) ? {
|
|
21
|
+
category: HITL_CATEGORIES.find(category => category === action.category) ?? 'restricted',
|
|
22
|
+
descriptorDigest: hitlDigest(action), categoryDigest: hitlDigest(action.category),
|
|
23
|
+
reversible: action.reversible, impact: action.impact,
|
|
24
|
+
} : { descriptorDigest: hitlDigest(action) },
|
|
25
|
+
scope: validHitlAction(action) ? {
|
|
26
|
+
environmentClass: HITL_ENVIRONMENTS.find(environment => environment === action.environment) ?? 'restricted',
|
|
27
|
+
repoDigest: hitlDigest(action.repo), environmentDigest: hitlDigest(action.environment),
|
|
28
|
+
resourceDigests: action.resources.map(hitlDigest),
|
|
29
|
+
} : null,
|
|
30
|
+
origins: context.layers.map(layer => ({ sourceDigest: hitlDigest(layer.source), policyDigest: hitlDigest(layer.policy ?? null) })),
|
|
31
|
+
};
|
|
32
|
+
assertDigestOnly(receipt);
|
|
33
|
+
const bytes = JSON.stringify(receipt) + '\n';
|
|
34
|
+
const digest = payloadDigest(bytes);
|
|
35
|
+
const root = resolveProjectAiwgDirForWrite(ledger.projectDir);
|
|
36
|
+
const relativePath = join('effects', 'authorization', `${digest.slice(7)}.json`);
|
|
37
|
+
const file = projectAiwgWritePath(ledger.projectDir, relativePath);
|
|
38
|
+
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
39
|
+
try {
|
|
40
|
+
await writeFile(file, bytes, { flag: 'wx', mode: 0o600 });
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code !== 'EEXIST')
|
|
44
|
+
throw error;
|
|
45
|
+
if (await readFile(file, 'utf8') !== bytes)
|
|
46
|
+
throw new Error('HITL receipt identity conflict');
|
|
47
|
+
}
|
|
48
|
+
const intent = await recordIntent(ledger, {
|
|
49
|
+
kind: 'file.digest', target: `file:${file}@${digest}`, payloadDigest: digest,
|
|
50
|
+
context: { policyVersion: resolution.policyVersion, decision: resolution.decision, provenance: resolution.provenance, receiptDigest: digest },
|
|
51
|
+
});
|
|
52
|
+
const reconciled = await reconcileEffect(ledger, intent.effectId, {
|
|
53
|
+
verifiers: createVerifierRegistry([fileDigestVerifier({ root })]),
|
|
54
|
+
});
|
|
55
|
+
return { resolution, file, intent, reconciled };
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=hitl-receipt.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Defines bounded HITL grants and trusted resolver inputs, separate from RBAC.
|
|
2
|
+
export const HITL_CATEGORIES = ['repo.read', 'repo.edit', 'docs.edit', 'test.run', 'testnet.configure'];
|
|
3
|
+
export const HITL_ENVIRONMENTS = ['local', 'development', 'test', 'testnet'];
|
|
4
|
+
//# sourceMappingURL=hitl-types.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Validates HITL with the existing config schema definitions, shared by loader and resolver.
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import Ajv from 'ajv';
|
|
4
|
+
import addFormats from 'ajv-formats';
|
|
5
|
+
function compiled() {
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
let schema;
|
|
8
|
+
// Source and compiled modules share the shipped config schema; no cwd or home lookup.
|
|
9
|
+
for (const relative of ['../../vscode-extension/schemas/aiwg.config.v1.json',
|
|
10
|
+
'../../../vscode-extension/schemas/aiwg.config.v1.json']) {
|
|
11
|
+
try {
|
|
12
|
+
schema = require(relative);
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error?.code !== 'MODULE_NOT_FOUND')
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!schema)
|
|
21
|
+
throw new Error('HITL config schema unavailable');
|
|
22
|
+
const ajv = new Ajv({ strict: true, allErrors: true });
|
|
23
|
+
addFormats(ajv);
|
|
24
|
+
return ajv.compile({
|
|
25
|
+
$ref: '#/definitions/HitlPolicy',
|
|
26
|
+
definitions: Object.fromEntries(['HitlPolicy', 'HitlProfile', 'HitlSelector'].map(key => [key, schema.definitions[key]])),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Compile at module initialization; resolving an action performs no filesystem I/O.
|
|
30
|
+
const validator = compiled();
|
|
31
|
+
export function validateHitlPolicy(value) {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return [];
|
|
34
|
+
if (validator(value))
|
|
35
|
+
return [];
|
|
36
|
+
// Never echo supplied values, which may contain credentials or injected text.
|
|
37
|
+
return ['authorization.hitl: invalid bounded policy (scope, categories, expiry or unknown fields)'];
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=hitl-validation.js.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Resolves bounded HITL authorization without I/O, clocks, or prompt-text authority.
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { HITL_CATEGORIES, HITL_ENVIRONMENTS } from './hitl-types.js';
|
|
4
|
+
import { validateHitlPolicy } from './hitl-validation.js';
|
|
5
|
+
export function hitlDigest(value) {
|
|
6
|
+
const canonical = (v) => Array.isArray(v) ? v.map(canonical)
|
|
7
|
+
: v && typeof v === 'object' ? Object.fromEntries(Object.entries(v).filter(([, x]) => x !== undefined)
|
|
8
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, x]) => [k, canonical(x)])) : v;
|
|
9
|
+
return `sha256:${createHash('sha256').update(JSON.stringify(canonical(value))).digest('hex')}`;
|
|
10
|
+
}
|
|
11
|
+
export const hitlPolicyVersion = (layers) => hitlDigest(layers);
|
|
12
|
+
const identifier = /^[A-Za-z0-9][A-Za-z0-9_.:/@-]{0,255}$/;
|
|
13
|
+
const pathValid = (path) => path.length > 0 && path.length <= 512 && !path.startsWith('/') && !path.includes(':')
|
|
14
|
+
&& !/[\\\x00-\x20*?\[\]{}!]/.test(path) && path.split('/').every(p => p !== '.' && p !== '..' && p !== '');
|
|
15
|
+
export function validHitlAction(value) {
|
|
16
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
17
|
+
return false;
|
|
18
|
+
return actionFieldsValid(value);
|
|
19
|
+
}
|
|
20
|
+
function actionFieldsValid(a) {
|
|
21
|
+
const keys = ['category', 'repo', 'environment', 'resources', 'reversible', 'impact'];
|
|
22
|
+
return Object.keys(a).length === keys.length && keys.every(k => Object.hasOwn(a, k))
|
|
23
|
+
&& [a.category, a.repo, a.environment].every(x => typeof x === 'string' && identifier.test(x))
|
|
24
|
+
&& Array.isArray(a.resources) && a.resources.length > 0 && a.resources.every(p => typeof p === 'string' && pathValid(p))
|
|
25
|
+
&& typeof a.reversible === 'boolean' && ['low', 'medium', 'high'].includes(a.impact);
|
|
26
|
+
}
|
|
27
|
+
/** Deliberately small glob language: * within a segment; ** crosses directories; ? one character. */
|
|
28
|
+
function glob(pattern, path) {
|
|
29
|
+
// Memoized matching bounds work by pattern length × path length, without regex backtracking.
|
|
30
|
+
const memo = new Map();
|
|
31
|
+
const match = (i, j) => {
|
|
32
|
+
const key = `${i}:${j}`;
|
|
33
|
+
if (memo.has(key))
|
|
34
|
+
return memo.get(key);
|
|
35
|
+
let result;
|
|
36
|
+
if (i === pattern.length)
|
|
37
|
+
result = j === path.length;
|
|
38
|
+
else if (pattern[i] === '*' && pattern[i + 1] === '*') {
|
|
39
|
+
if (pattern[i + 2] === '/') {
|
|
40
|
+
const slash = path.indexOf('/', j);
|
|
41
|
+
result = match(i + 3, j) || (slash >= 0 && match(i, slash + 1));
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
result = match(i + 2, j) || (j < path.length && match(i, j + 1));
|
|
45
|
+
}
|
|
46
|
+
else if (pattern[i] === '*')
|
|
47
|
+
result = match(i + 1, j)
|
|
48
|
+
|| (j < path.length && path[j] !== '/' && match(i, j + 1));
|
|
49
|
+
else
|
|
50
|
+
result = j < path.length && (pattern[i] === path[j] || (pattern[i] === '?' && path[j] !== '/'))
|
|
51
|
+
&& match(i + 1, j + 1);
|
|
52
|
+
memo.set(key, result);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
return match(0, 0);
|
|
56
|
+
}
|
|
57
|
+
function selected(s, a) {
|
|
58
|
+
return (!s.categories || s.categories.includes(a.category)) && (!s.repos || s.repos.includes(a.repo))
|
|
59
|
+
&& (!s.environments || s.environments.includes(a.environment))
|
|
60
|
+
&& (!s.resources || a.resources.some(p => s.resources.some(g => glob(g, p))));
|
|
61
|
+
}
|
|
62
|
+
function grant(p, a, now) {
|
|
63
|
+
return now < Date.parse(p.expiresAt) && p.reversible === true && a.reversible
|
|
64
|
+
&& p.categories.some(c => c === a.category) && p.repos.includes(a.repo)
|
|
65
|
+
&& p.environments.some(e => e === a.environment)
|
|
66
|
+
&& a.resources.every(path => p.resources.some(g => glob(g, path)))
|
|
67
|
+
&& (a.impact === 'low' || (a.impact === 'medium' && p.maxImpact === 'medium'));
|
|
68
|
+
}
|
|
69
|
+
export function resolveHitlAuthorization(action, context) {
|
|
70
|
+
const policyVersion = hitlPolicyVersion(context.layers);
|
|
71
|
+
const result = (decision, reason, provenance, matchedProfile = null) => ({ decision, reason, policyVersion, matchedProfile, provenance });
|
|
72
|
+
if (context.platform)
|
|
73
|
+
return result(context.platform === 'deny' ? 'deny' : 'escalate', 'platform-constraint', 'platform');
|
|
74
|
+
if (!validHitlAction(action))
|
|
75
|
+
return result('escalate', 'invalid-action-descriptor', 'default');
|
|
76
|
+
if (!HITL_CATEGORIES.some(c => c === action.category) || !HITL_ENVIRONMENTS.some(e => e === action.environment)
|
|
77
|
+
|| !action.reversible || action.impact === 'high')
|
|
78
|
+
return result('escalate', 'safety-category-requires-explicit-review', 'platform');
|
|
79
|
+
// Revalidate even when invoked directly with objects that bypassed the config loader.
|
|
80
|
+
if (context.layers.some(l => validateHitlPolicy(l.policy).length))
|
|
81
|
+
return result('escalate', 'invalid-policy', 'default');
|
|
82
|
+
if (context.layers.some(l => l.policy?.deny.some(s => selected(s, action))))
|
|
83
|
+
return result('deny', 'explicit-deny', 'explicit-deny');
|
|
84
|
+
const now = Date.parse(context.now);
|
|
85
|
+
if (!Number.isFinite(now))
|
|
86
|
+
return result('escalate', 'invalid-clock', 'default');
|
|
87
|
+
const session = context.sessionAuthorization;
|
|
88
|
+
if (session?.source === 'session-user') {
|
|
89
|
+
const probe = { version: '1', enabled: true, reviewedAt: context.now, maxAgeSeconds: 1,
|
|
90
|
+
expiresAt: session.profile.expiresAt, profiles: { session: session.profile }, deny: [], requireReview: [] };
|
|
91
|
+
if (!validateHitlPolicy(probe).length && grant(session.profile, action, now))
|
|
92
|
+
return result('auto-authorized', 'session-user-authorization', 'session-user', 'session');
|
|
93
|
+
}
|
|
94
|
+
if (context.expectedPolicyVersion && policyVersion !== context.expectedPolicyVersion)
|
|
95
|
+
return result('escalate', 'stale-policy-version', 'project-policy');
|
|
96
|
+
if (!context.layers.length)
|
|
97
|
+
return result('escalate', 'no-project-policy', 'default');
|
|
98
|
+
let matched = null;
|
|
99
|
+
for (const layer of context.layers) {
|
|
100
|
+
const p = layer.policy;
|
|
101
|
+
if (!p?.enabled)
|
|
102
|
+
return result('escalate', p ? 'policy-revoked' : 'missing-member-policy', 'project-policy');
|
|
103
|
+
const reviewed = Date.parse(p.reviewedAt);
|
|
104
|
+
if (now >= Date.parse(p.expiresAt))
|
|
105
|
+
return result('escalate', 'policy-expired', 'project-policy');
|
|
106
|
+
if (reviewed > now || now - reviewed >= p.maxAgeSeconds * 1000)
|
|
107
|
+
return result('escalate', 'stale-policy-review', 'project-policy');
|
|
108
|
+
if (p.requireReview.some(s => selected(s, action)))
|
|
109
|
+
return result('escalate', 'policy-requires-review', 'project-policy');
|
|
110
|
+
const entry = Object.entries(p.profiles).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).find(([, profile]) => grant(profile, action, now));
|
|
111
|
+
if (!entry)
|
|
112
|
+
return result('escalate', 'outside-profile-or-expired', 'project-policy');
|
|
113
|
+
matched = entry[0];
|
|
114
|
+
}
|
|
115
|
+
return result('auto-authorized', 'bounded-project-policy', 'project-policy', matched);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=hitl.js.map
|
|
@@ -7,7 +7,7 @@ export interface RuleFrontmatter extends Record<string, unknown> {
|
|
|
7
7
|
summary?: string;
|
|
8
8
|
bound_to: RuleBindings;
|
|
9
9
|
paths?: string[];
|
|
10
|
-
enforcedBy?:
|
|
10
|
+
enforcedBy?: string[];
|
|
11
11
|
}
|
|
12
12
|
export interface RuleDiagnostic { severity: 'error' | 'warn' | 'info'; code: string; message: string }
|
|
13
13
|
export type RuleValidationResult =
|
|
@@ -19,6 +19,8 @@ export const ruleFrontmatterSchema: Record<string, unknown>;
|
|
|
19
19
|
export function inferRuleActivation(enforcement?: unknown): 'on-demand';
|
|
20
20
|
export function validateRuleFrontmatter(data: unknown): RuleValidationResult;
|
|
21
21
|
export function parseRuleFrontmatter(content: string): RuleValidationResult & { data: unknown; body: string };
|
|
22
|
+
export const RULE_SUMMARY_MAX_LENGTH: number;
|
|
23
|
+
export function formatRuleFrontmatterError(file: string, data: unknown, diagnostics: RuleDiagnostic[]): string;
|
|
22
24
|
export const CORE_BODY_MAX_BYTES: number;
|
|
23
25
|
export const CORE_TOTAL_MAX_BYTES: number;
|
|
24
26
|
export const CORE_RULES_START: string;
|