@aiwg/cli 2026.10.12 → 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.
Files changed (56) hide show
  1. package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
  2. package/dist/src/cli/handlers/use-bundle-counts.js +32 -6
  3. package/dist/src/cli/handlers/use-skill-assets.js +207 -0
  4. package/dist/src/cli/handlers/use.js +30 -193
  5. package/dist/src/config/authorization-cli.js +11 -3
  6. package/dist/src/decision/context-pruning-common.js +41 -0
  7. package/dist/src/decision/context-pruning-evaluation.js +366 -0
  8. package/dist/src/decision/context-pruning-pilot.js +431 -0
  9. package/dist/src/decision/context-pruning-types.js +19 -0
  10. package/dist/src/decision/context-pruning.js +5 -847
  11. package/dist/src/decision/ensemble/contract.js +4 -24
  12. package/dist/src/decision/qualification/release.js +5 -62
  13. package/dist/src/extensions/manifest.js +8 -1
  14. package/dist/src/extensions/project-local-doctor.js +78 -2
  15. package/dist/src/extensions/validation.js +10 -11
  16. package/dist/src/gates/evaluate.js +3 -13
  17. package/dist/src/gates/upstream-ceiling.js +111 -0
  18. package/dist/src/models/provider-models.js +5 -8
  19. package/dist/src/models/wrapper-definitions.js +14 -0
  20. package/dist/src/models/wrapper-deployment.js +48 -25
  21. package/dist/src/models/wrapper-enforcement.js +72 -0
  22. package/dist/src/policy/hitl-check.js +80 -0
  23. package/dist/src/rules/activation.d.mts +2 -0
  24. package/dist/src/rules/activation.mjs +23 -0
  25. package/dist/src/skills/adapters/local.js +32 -9
  26. package/dist/src/skills/agent-skills.js +2 -0
  27. package/dist/src/skills/cli-display.js +33 -0
  28. package/dist/src/skills/cli.js +2 -26
  29. package/dist/src/skills/collision-discovery.js +84 -0
  30. package/dist/src/skills/deployer.js +20 -75
  31. package/dist/src/skills/deployment-ownership.js +74 -0
  32. package/dist/src/skills/doctor.js +2 -2
  33. package/dist/src/skills/importer.js +4 -26
  34. package/dist/src/skills/registry.js +22 -7
  35. package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
  36. package/package.json +3 -1
  37. package/tools/agents/providers/antigravity.mjs +3 -5
  38. package/tools/agents/providers/base.mjs +3 -3
  39. package/tools/agents/providers/claude.mjs +3 -5
  40. package/tools/agents/providers/codex.mjs +3 -5
  41. package/tools/agents/providers/copilot.mjs +3 -5
  42. package/tools/agents/providers/cursor.mjs +3 -5
  43. package/tools/agents/providers/factory.mjs +3 -5
  44. package/tools/agents/providers/grok-build.mjs +9 -7
  45. package/tools/agents/providers/model-wrapper.mjs +86 -0
  46. package/tools/agents/providers/omp.mjs +3 -1
  47. package/tools/agents/providers/openclaw.mjs +3 -5
  48. package/tools/agents/providers/opencode.mjs +3 -5
  49. package/tools/agents/providers/provider-paths-staging.mjs +9 -0
  50. package/tools/agents/providers/rule-delivery.mjs +4 -4
  51. package/tools/agents/providers/warp.mjs +3 -5
  52. package/tools/agents/providers/windsurf.mjs +3 -5
  53. package/tools/plugin/package-plugins.mjs +2 -2
  54. package/tools/skills/codex-skill-transform.mjs +232 -0
  55. package/tools/skills/deploy-skills-codex.mjs +8 -249
  56. package/tools/warp/warp-content.mjs +548 -0
@@ -1,4 +1,5 @@
1
- import { assertDecisionCeiling, ceilingDecision, GATE_RANK, GateDecisionUpgradeError } from '../../gates/lattice.js';
1
+ import { evaluateUpstreamCeiling, integrityProblems } from '../../gates/upstream-ceiling.js';
2
+ import { assertDecisionCeiling, GATE_RANK, GateDecisionUpgradeError } from '../../gates/lattice.js';
2
3
  import { createHash } from 'node:crypto';
3
4
  import { existsSync, readFileSync } from 'node:fs';
4
5
  import { dirname, resolve } from 'node:path';
@@ -297,26 +298,7 @@ export function validateEnsembleAggregate(value) {
297
298
  }
298
299
  /** D17 findings derived from the carried #2037/#2048 integrity fields alone. */
299
300
  export function integrityMetadataFindings(integrity, minimumPairs) {
300
- const findings = [];
301
- if (integrity.integrity_state !== 'verified')
302
- findings.push('integrity-not-verified');
303
- if (integrity.integrity_mode === 'standard')
304
- findings.push('integrity-mode-standard');
305
- if (integrity.trusted_score_source === 'local-unverified')
306
- findings.push('untrusted-score-source');
307
- if (integrity.fresh_workspace_required && !integrity.fresh_workspace_verified)
308
- findings.push('fresh-workspace-unverified');
309
- if (integrity.uncertainty === null)
310
- findings.push('uncertainty-missing');
311
- if (integrity.paired_baseline === null)
312
- findings.push('paired-baseline-missing');
313
- if (integrity.weak_signal_reason !== null)
314
- findings.push('weak-signal');
315
- if (integrity.compromise_labels.length > 0)
316
- findings.push('compromised');
317
- if (integrity.sample_n < minimumPairs)
318
- findings.push('insufficient-samples');
319
- return findings;
301
+ return integrityProblems(integrity, 'ensemble', minimumPairs);
320
302
  }
321
303
  /** The finding for one paired delta against its preregistered threshold, or null when it passes. */
322
304
  export function pairedDeltaFinding(threshold, item) {
@@ -332,9 +314,7 @@ export function pairedDeltaFinding(threshold, item) {
332
314
  }
333
315
  /** Upstream ROLLBACK or any compromise gives ROLLBACK; upstream HOLD or any finding gives HOLD. */
334
316
  export function ensembleIntegrityDecision(integrity, findingCount) {
335
- const upstream = integrity.release_gate.decision;
336
- const compromised = integrity.integrity_state === 'compromised' || integrity.compromise_labels.length > 0;
337
- return ceilingDecision(upstream, compromised ? 'ROLLBACK' : 'PROMOTE', findingCount > 0 ? 'HOLD' : 'PROMOTE');
317
+ return evaluateUpstreamCeiling(integrity, { policy: 'upstream', findings: findingCount }).ceiling;
338
318
  }
339
319
  /** A D17 report may keep or tighten the upstream #2037/#2048 decision, never loosen it. Every
340
320
  * finding, passed flag and the decision are recomputed from the carried integrity fields and the
@@ -1,59 +1,7 @@
1
1
  import { ceilingDecision } from '../../gates/lattice.js';
2
2
  import { canonicalSha256, matchEvidenceDigest } from '../../gates/stats/index.js';
3
- /**
4
- * #2037/#2048 integrity modes whose verified state has a trusted score source.
5
- * Mirrors tools/eval buildIntegrityMetadata: each strict mode maps to exactly one source.
6
- */
7
- export const VERIFIED_QUALIFICATION_INTEGRITY_SOURCES = Object.freeze({
8
- fresh: 'fresh-workspace',
9
- locked: 'locked-artifact-snapshot',
10
- 'full-locked': 'full-locked-workspace',
11
- });
12
- /**
13
- * Allowlist check for promotable integrity metadata. Any malformed, unknown or
14
- * unverified mode/state/score-source is a problem; an empty result is the only
15
- * state that may PROMOTE. Callers still honour upstream HOLD/ROLLBACK separately.
16
- */
17
- export function qualificationIntegrityAllowlistProblems(integrity) {
18
- const value = integrity;
19
- if (!value || typeof value !== 'object' || Array.isArray(value)
20
- || !Number.isSafeInteger(value.sample_n) || value.sample_n < 0
21
- || typeof value.integrity_mode !== 'string' || typeof value.integrity_state !== 'string'
22
- || typeof value.trusted_score_source !== 'string'
23
- || typeof value.fresh_workspace_required !== 'boolean' || typeof value.fresh_workspace_verified !== 'boolean'
24
- || !Array.isArray(value.compromise_labels) || value.compromise_labels.some(label => typeof label !== 'string')
25
- || !(value.weak_signal_reason === null || typeof value.weak_signal_reason === 'string')
26
- || !('uncertainty' in value) || !('paired_baseline' in value)
27
- || !value.release_gate || typeof value.release_gate !== 'object'
28
- || !['PROMOTE', 'HOLD', 'ROLLBACK'].includes(value.release_gate.decision)
29
- || !Array.isArray(value.release_gate.reasons)) {
30
- return ['integrity-invalid'];
31
- }
32
- const problems = [];
33
- const expectedSource = Object.hasOwn(VERIFIED_QUALIFICATION_INTEGRITY_SOURCES, value.integrity_mode)
34
- ? VERIFIED_QUALIFICATION_INTEGRITY_SOURCES[value.integrity_mode] : undefined;
35
- if (value.integrity_state !== 'verified')
36
- problems.push('integrity-not-verified');
37
- if (expectedSource === undefined)
38
- problems.push('integrity-mode-not-allowlisted');
39
- else if (value.trusted_score_source !== expectedSource)
40
- problems.push('untrusted-score-source');
41
- if (value.fresh_workspace_required && !value.fresh_workspace_verified)
42
- problems.push('fresh-workspace-unverified');
43
- if (value.uncertainty === null || value.uncertainty === undefined)
44
- problems.push('uncertainty-missing');
45
- if (value.paired_baseline === null || value.paired_baseline === undefined)
46
- problems.push('paired-baseline-missing');
47
- if (value.weak_signal_reason !== null)
48
- problems.push('weak-signal');
49
- if (value.compromise_labels.length > 0)
50
- problems.push('compromised');
51
- if (value.sample_n <= 0)
52
- problems.push('insufficient-samples');
53
- if (value.release_gate.decision !== 'PROMOTE')
54
- problems.push(`upstream-integrity-${value.release_gate.decision.toLowerCase()}`);
55
- return problems;
56
- }
3
+ export { VERIFIED_QUALIFICATION_INTEGRITY_SOURCES, qualificationIntegrityAllowlistProblems, } from '../../gates/upstream-ceiling.js';
4
+ import { evaluateUpstreamCeiling } from '../../gates/upstream-ceiling.js';
57
5
  /** D30 compile/prefix cache, D03 receipt replay and D15 result cache evidence, each a verified evidence manifest. */
58
6
  export const QUALIFICATION_CACHE_LAYERS = ['compilePrefixCache', 'receiptReplay', 'resultCache'];
59
7
  const REQUIRED_PINS = [
@@ -111,15 +59,10 @@ export function buildQualificationReleaseRecord(executed, input) {
111
59
  const suites = manifest.evidence.map(item => ({
112
60
  caseId: item.caseId, outcome: item.outcome, evidenceHash: item.digest, verified: verified.get(item.caseId) === true,
113
61
  })).sort((a, b) => a.caseId.localeCompare(b.caseId));
114
- const releaseDecision = input.integrity.release_gate.decision;
62
+ const integrityGate = evaluateUpstreamCeiling(input.integrity, { policy: 'qualification-release' });
115
63
  const withinBudgets = Object.entries(input.budgets).length > 0
116
64
  && Object.keys(input.actuals).length === Object.keys(input.budgets).length
117
65
  && Object.entries(input.budgets).every(([name, limit]) => input.actuals[name] !== undefined && input.actuals[name] <= limit);
118
- const integrityVerified = input.integrity.integrity_state === 'verified'
119
- && input.integrity.integrity_mode !== 'standard'
120
- && input.integrity.trusted_score_source !== 'local-unverified'
121
- && input.integrity.compromise_labels.length === 0
122
- && input.integrity.sample_n > 0 && input.integrity.uncertainty !== null;
123
66
  const benchmark = input.benchmark;
124
67
  const benchmarkVerified = benchmark !== undefined && benchmark.decision === 'pass'
125
68
  && /^sha256:[0-9a-f]{64}$/.test(benchmark.planDigest)
@@ -130,11 +73,11 @@ export function buildQualificationReleaseRecord(executed, input) {
130
73
  const snapshotVerified = snapshot !== undefined && /^sha256:[0-9a-f]{64}$/.test(snapshot.digest)
131
74
  && Number.isSafeInteger(snapshot.artifactCount) && snapshot.artifactCount > 0;
132
75
  const metricsRecorded = input.metrics !== undefined && input.metrics.overall.sampleN > 0;
133
- const complete = withinBudgets && integrityVerified && benchmarkVerified && snapshotVerified && metricsRecorded && !manifest.dirty && input.reviewer !== null && input.reviewer.trim().length > 0
76
+ const complete = withinBudgets && benchmarkVerified && snapshotVerified && metricsRecorded && !manifest.dirty && input.reviewer !== null && input.reviewer.trim().length > 0
134
77
  && suites.length === manifest.cases.length && suites.every(item => item.outcome === 'pass' && item.verified)
135
78
  && report.gates.length === 7 && report.gates.every(gate => gate.status === 'pass')
136
79
  && report.decision === 'PROMOTE';
137
- const decision = ceilingDecision(releaseDecision, report.decision, complete ? 'PROMOTE' : 'HOLD', input.integrity.integrity_state === 'compromised' || input.integrity.compromise_labels.length > 0 ? 'ROLLBACK' : 'PROMOTE');
80
+ const decision = ceilingDecision(integrityGate.ceiling, report.decision, complete ? 'PROMOTE' : 'HOLD');
138
81
  const fields = {
139
82
  schemaVersion: 'decision-qualification-release/v2',
140
83
  runId: manifest.runId, sourceCommit: manifest.sourceCommit, dirty: manifest.dirty,
@@ -272,12 +272,19 @@ export function zodErrorToValidationErrors(err, manifestPath, input) {
272
272
  && issue.path.length === 3 && issue.path[0] === 'providerConfig'
273
273
  && issue.path[1] === 'capabilities'
274
274
  && ['nativeFeatures', 'emulation'].includes(String(issue.path[2]))) {
275
- return issue.keys.map(key => ({ ...issue, path: [...issue.path, key] }));
275
+ return issue.keys.map(key => ({ ...issue, path: [...issue.path, key], keys: [key] }));
276
276
  }
277
277
  return [issue];
278
278
  });
279
279
  return issues.map((issue) => {
280
280
  let actual = 'invalid';
281
+ if (issue.code === 'unrecognized_keys') {
282
+ // Name each rejected key so doctor/use output identifies the culprit
283
+ // (#3724: a typo'd or unknown platform key must not vanish into
284
+ // a bare "invalid").
285
+ const keys = issue.keys.map((key) => `"${String(key)}"`).join(', ');
286
+ actual = `unknown key(s): ${keys}`;
287
+ }
281
288
  if (issue.code === 'invalid_type' && hasInput) {
282
289
  let value = input;
283
290
  for (const segment of issue.path) {
@@ -13,7 +13,9 @@
13
13
  * @implements #1037
14
14
  */
15
15
  import { join } from 'path';
16
+ import { readFile, readdir } from 'fs/promises';
16
17
  import { discoverProjectLocalBundles } from './project-local-discovery.js';
18
+ import { parseRuleFrontmatter, formatRuleFrontmatterError } from '../rules/activation.mjs';
17
19
  import { buildUpstreamRegistry } from './upstream-registry.js';
18
20
  import { resolveShadows } from './shadow-resolver.js';
19
21
  import { checkBundleManifestIgnored } from './project-local-gitignore.js';
@@ -48,6 +50,56 @@ const TYPE_DIR = {
48
50
  plugin: 'plugins',
49
51
  provider: 'providers',
50
52
  };
53
+ /**
54
+ * Rule files `aiwg use` validates at deploy time via the shared frontmatter
55
+ * contract (`parseRuleFrontmatter` in `src/rules/activation.mjs`, #3728).
56
+ * Mirrors deploy's selection for a bundle source root: top-level `rules/`
57
+ * markdown (minus deploy's excluded/generated names) plus every
58
+ * `BEHAVIOR.md` under `behaviors/`.
59
+ */
60
+ const RULE_MD_EXCLUDED = new Set([
61
+ 'README.md', 'manifest.md', 'agent-template.md', 'openai-compat.md',
62
+ 'factory-compat.md', 'windsurf-compat.md', 'DEVELOPMENT_GUIDE.md',
63
+ ]);
64
+ async function collectBundleRuleFiles(artifactPath) {
65
+ const files = [];
66
+ try {
67
+ const entries = await readdir(join(artifactPath, 'rules'), { withFileTypes: true });
68
+ for (const entry of entries) {
69
+ if (!entry.isFile() || !entry.name.toLowerCase().endsWith('.md'))
70
+ continue;
71
+ if (RULE_MD_EXCLUDED.has(entry.name))
72
+ continue;
73
+ const lower = entry.name.toLowerCase();
74
+ if (lower.endsWith('.soul.md') || lower.endsWith('.core.md'))
75
+ continue;
76
+ if (/^(RULES-INDEX|RULES-ONDEMAND)\.(md|mdc)$/.test(entry.name))
77
+ continue;
78
+ files.push(join(artifactPath, 'rules', entry.name));
79
+ }
80
+ }
81
+ catch {
82
+ // Absent rules dir — nothing to validate.
83
+ }
84
+ const walkBehaviors = async (dir) => {
85
+ let entries;
86
+ try {
87
+ entries = await readdir(dir, { withFileTypes: true });
88
+ }
89
+ catch {
90
+ return;
91
+ }
92
+ for (const entry of entries) {
93
+ const full = join(dir, entry.name);
94
+ if (entry.isDirectory())
95
+ await walkBehaviors(full);
96
+ else if (entry.isFile() && entry.name === 'BEHAVIOR.md')
97
+ files.push(full);
98
+ }
99
+ };
100
+ await walkBehaviors(join(artifactPath, 'behaviors'));
101
+ return files;
102
+ }
51
103
  export async function buildProjectLocalDoctorSection(opts) {
52
104
  const { projectDir, frameworkRoot, config, quiet = false } = opts;
53
105
  const discovery = await discoverProjectLocalBundles(projectDir);
@@ -87,8 +139,27 @@ export async function buildProjectLocalDoctorSection(opts) {
87
139
  lines.push('');
88
140
  }
89
141
  }
142
+ // Rule frontmatter validation (#3728): the same validator `aiwg use`
143
+ // applies at deploy time, so a bundle that would fail deployment is
144
+ // flagged here instead of passing with a clean bill of health.
145
+ const ruleErrors = [];
146
+ for (const bundle of discovery.bundles) {
147
+ for (const file of await collectBundleRuleFiles(bundle.artifactPath)) {
148
+ let content;
149
+ try {
150
+ content = await readFile(file, 'utf-8');
151
+ }
152
+ catch {
153
+ continue;
154
+ }
155
+ const parsed = parseRuleFrontmatter(content);
156
+ if (!parsed.valid) {
157
+ ruleErrors.push(formatRuleFrontmatterError(projectRelativePathIfInside(projectDir, file) ?? file, parsed.data, parsed.diagnostics));
158
+ }
159
+ }
160
+ }
90
161
  // Validation
91
- const validationErrors = discovery.errors.length + quickrefErrors.length;
162
+ const validationErrors = discovery.errors.length + quickrefErrors.length + ruleErrors.length;
92
163
  if (validationErrors === 0) {
93
164
  if (!quiet)
94
165
  lines.push(` Validation: ✓ all manifests${quickrefAudit.exists ? ' and project quickref source' : ''} valid`);
@@ -98,7 +169,12 @@ export async function buildProjectLocalDoctorSection(opts) {
98
169
  for (const e of discovery.errors.slice(0, 10)) {
99
170
  lines.push(` ✗ ${e.path}: ${e.field} — ${e.actual}`);
100
171
  }
101
- for (const error of quickrefErrors.slice(0, Math.max(0, 10 - discovery.errors.length))) {
172
+ const quickrefShown = quickrefErrors.slice(0, Math.max(0, 10 - discovery.errors.length));
173
+ for (const error of quickrefShown) {
174
+ lines.push(` ✗ ${error}`);
175
+ }
176
+ const ruleShown = ruleErrors.slice(0, Math.max(0, 10 - discovery.errors.length - quickrefShown.length));
177
+ for (const error of ruleShown) {
102
178
  lines.push(` ✗ ${error}`);
103
179
  }
104
180
  if (validationErrors > 10) {
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import { z } from 'zod';
13
13
  import { integer, dateTime, url, number } from '../schema/zod-validation.mjs';
14
+ import { PROVIDER_IDS } from '../providers/provider-definitions.js';
14
15
  // ============================================
15
16
  // Core Enums & Primitives
16
17
  // ============================================
@@ -68,17 +69,15 @@ export const HookEventSchema = z.enum([
68
69
  // ============================================
69
70
  /**
70
71
  * Platform compatibility matrix
71
- */
72
- export const PlatformCompatibilitySchema = z.object({
73
- claude: PlatformSupportSchema.optional(),
74
- factory: PlatformSupportSchema.optional(),
75
- cursor: PlatformSupportSchema.optional(),
76
- copilot: PlatformSupportSchema.optional(),
77
- windsurf: PlatformSupportSchema.optional(),
78
- codex: PlatformSupportSchema.optional(),
79
- opencode: PlatformSupportSchema.optional(),
80
- generic: PlatformSupportSchema.optional(),
81
- }).refine((data) => Object.values(data).some((val) => val !== undefined), { error: 'At least one platform must be specified' });
72
+ *
73
+ * Keys are derived from the provider registry (`PROVIDER_IDS` in
74
+ * `src/providers/provider-definitions.ts`), the single source of truth for
75
+ * provider ids — so every registered provider (pi, hermes, …) is accepted.
76
+ * Strict: an unknown platform key is a validation error, never silently
77
+ * stripped (#3724).
78
+ */
79
+ const platformCompatibilityShape = Object.fromEntries(PROVIDER_IDS.map((id) => [id, PlatformSupportSchema.optional()]));
80
+ export const PlatformCompatibilitySchema = z.strictObject(platformCompatibilityShape).refine((data) => Object.values(data).some((val) => val !== undefined), { error: 'At least one platform must be specified' });
82
81
  /**
83
82
  * Deployment configuration
84
83
  */
@@ -1,5 +1,5 @@
1
1
  import { ceilingDecision, maxOutcome } from './lattice.js';
2
- import { qualificationIntegrityAllowlistProblems } from '../decision/qualification/release.js';
2
+ import { evaluateUpstreamCeiling } from './upstream-ceiling.js';
3
3
  import { artifactDigest } from '../decision/validate.js';
4
4
  import { evaluatePredicate } from '../decision/predicates.js';
5
5
  import { clopperPearsonInterval } from './stats/clopper-pearson.js';
@@ -387,13 +387,10 @@ function evaluateObservation(gate, observation, context) {
387
387
  if (upstream === null)
388
388
  return { ...base, status: 'insufficient', reason: 'upstream-missing',
389
389
  statistic: { method: 'upstream-integrity' } };
390
- const problems = qualificationIntegrityAllowlistProblems(upstream.metadata);
390
+ const { problems, compromised } = evaluateUpstreamCeiling(upstream.metadata);
391
391
  if (!problems.length) {
392
392
  return { ...base, status: 'pass', reason: 'upstream-clean', statistic: { method: 'upstream-integrity' } };
393
393
  }
394
- const compromised = problems.includes('compromised')
395
- || upstream.metadata.release_gate?.decision === 'ROLLBACK'
396
- || upstream.metadata.integrity_state === 'compromised';
397
394
  return { ...base, status: 'fail', reason: compromised ? 'upstream-compromised' : 'upstream-allowlist',
398
395
  statistic: { method: 'upstream-integrity' } };
399
396
  }
@@ -437,14 +434,7 @@ function rerunProviderOrFail(provider, args, providerId) {
437
434
  }
438
435
  }
439
436
  function upstreamOutcome(upstream) {
440
- if (upstream === null)
441
- return { ceiling: 'HOLD', problems: ['upstream-ceiling-missing'] };
442
- const problems = qualificationIntegrityAllowlistProblems(upstream.metadata);
443
- const release = upstream.metadata.release_gate?.decision;
444
- const compromised = problems.includes('compromised')
445
- || release === 'ROLLBACK'
446
- || upstream.metadata.integrity_state === 'compromised';
447
- return { ceiling: ceilingDecision(release ?? 'HOLD', compromised ? 'ROLLBACK' : 'PROMOTE', problems.length ? 'HOLD' : 'PROMOTE'), problems };
437
+ return evaluateUpstreamCeiling(upstream?.metadata ?? null);
448
438
  }
449
439
  /**
450
440
  * Pure, deterministic gate evaluation. The binding is resolved internally
@@ -0,0 +1,111 @@
1
+ // Shared upstream-ceiling evaluation with explicit policies for retained report contracts.
2
+ import { ceilingDecision } from './lattice.js';
3
+ /**
4
+ * #2037/#2048 integrity modes whose verified state has a trusted score source.
5
+ * Mirrors tools/eval buildIntegrityMetadata: each strict mode maps to exactly one source.
6
+ */
7
+ export const VERIFIED_QUALIFICATION_INTEGRITY_SOURCES = Object.freeze({
8
+ fresh: 'fresh-workspace',
9
+ locked: 'locked-artifact-snapshot',
10
+ 'full-locked': 'full-locked-workspace',
11
+ });
12
+ /**
13
+ * Allowlist check for promotable integrity metadata. Any malformed, unknown or
14
+ * unverified mode/state/score-source is a problem; an empty result is the only
15
+ * state that may PROMOTE. Callers still honour upstream HOLD/ROLLBACK separately.
16
+ */
17
+ export function qualificationIntegrityAllowlistProblems(integrity) {
18
+ const value = integrity;
19
+ if (!value || typeof value !== 'object' || Array.isArray(value)
20
+ || !Number.isSafeInteger(value.sample_n) || value.sample_n < 0
21
+ || typeof value.integrity_mode !== 'string' || typeof value.integrity_state !== 'string'
22
+ || typeof value.trusted_score_source !== 'string'
23
+ || typeof value.fresh_workspace_required !== 'boolean' || typeof value.fresh_workspace_verified !== 'boolean'
24
+ || !Array.isArray(value.compromise_labels) || value.compromise_labels.some(label => typeof label !== 'string')
25
+ || !(value.weak_signal_reason === null || typeof value.weak_signal_reason === 'string')
26
+ || !('uncertainty' in value) || !('paired_baseline' in value)
27
+ || !value.release_gate || typeof value.release_gate !== 'object'
28
+ || !['PROMOTE', 'HOLD', 'ROLLBACK'].includes(value.release_gate.decision)
29
+ || !Array.isArray(value.release_gate.reasons)) {
30
+ return ['integrity-invalid'];
31
+ }
32
+ const problems = [];
33
+ const expectedSource = Object.hasOwn(VERIFIED_QUALIFICATION_INTEGRITY_SOURCES, value.integrity_mode)
34
+ ? VERIFIED_QUALIFICATION_INTEGRITY_SOURCES[value.integrity_mode] : undefined;
35
+ if (value.integrity_state !== 'verified')
36
+ problems.push('integrity-not-verified');
37
+ if (expectedSource === undefined)
38
+ problems.push('integrity-mode-not-allowlisted');
39
+ else if (value.trusted_score_source !== expectedSource)
40
+ problems.push('untrusted-score-source');
41
+ if (value.fresh_workspace_required && !value.fresh_workspace_verified)
42
+ problems.push('fresh-workspace-unverified');
43
+ if (value.uncertainty === null || value.uncertainty === undefined)
44
+ problems.push('uncertainty-missing');
45
+ if (value.paired_baseline === null || value.paired_baseline === undefined)
46
+ problems.push('paired-baseline-missing');
47
+ if (value.weak_signal_reason !== null)
48
+ problems.push('weak-signal');
49
+ if (value.compromise_labels.length > 0)
50
+ problems.push('compromised');
51
+ if (value.sample_n <= 0)
52
+ problems.push('insufficient-samples');
53
+ if (value.release_gate.decision !== 'PROMOTE')
54
+ problems.push(`upstream-integrity-${value.release_gate.decision.toLowerCase()}`);
55
+ return problems;
56
+ }
57
+ export function integrityProblems(integrity, policy = 'allowlist', minimumSamples = 1) {
58
+ if (policy === 'allowlist')
59
+ return qualificationIntegrityAllowlistProblems(integrity);
60
+ if (policy === 'upstream')
61
+ return [];
62
+ const problems = [];
63
+ if (integrity.integrity_state !== 'verified')
64
+ problems.push('integrity-not-verified');
65
+ if (policy === 'context-pruning') {
66
+ if (integrity.release_gate.decision === 'ROLLBACK')
67
+ problems.push('upstream-rollback');
68
+ if (integrity.release_gate.decision === 'HOLD')
69
+ problems.push('upstream-hold');
70
+ return problems;
71
+ }
72
+ if (integrity.integrity_mode === 'standard')
73
+ problems.push('integrity-mode-standard');
74
+ if (integrity.trusted_score_source === 'local-unverified')
75
+ problems.push('untrusted-score-source');
76
+ if (policy === 'ensemble' && integrity.fresh_workspace_required && !integrity.fresh_workspace_verified) {
77
+ problems.push('fresh-workspace-unverified');
78
+ }
79
+ if (integrity.uncertainty === null)
80
+ problems.push('uncertainty-missing');
81
+ if (policy === 'ensemble' && integrity.paired_baseline === null)
82
+ problems.push('paired-baseline-missing');
83
+ if (policy === 'ensemble' && integrity.weak_signal_reason !== null)
84
+ problems.push('weak-signal');
85
+ if (integrity.compromise_labels.length > 0)
86
+ problems.push('compromised');
87
+ if (policy === 'qualification-release' ? !(integrity.sample_n > 0) : integrity.sample_n < minimumSamples) {
88
+ problems.push('insufficient-samples');
89
+ }
90
+ return problems;
91
+ }
92
+ /** Evaluate the same upstream-ceiling primitive used by the integrity-ceiling pack.
93
+ * Callers validate/seal evidence before evaluation. Legacy policies preserve their
94
+ * versioned report semantics, including context pruning's verified-state-only check.
95
+ */
96
+ export function evaluateUpstreamCeiling(integrity, options = {}) {
97
+ if (integrity === null)
98
+ return { ceiling: 'HOLD', problems: ['upstream-ceiling-missing'], compromised: false };
99
+ const policy = options.policy ?? 'allowlist';
100
+ const problems = integrityProblems(integrity, policy, options.minimumSamples);
101
+ const release = integrity?.release_gate?.decision;
102
+ const hasCompromiseLabels = policy === 'allowlist' ? problems.includes('compromised')
103
+ : (integrity?.compromise_labels?.length ?? 0) > 0;
104
+ const compromised = release === 'ROLLBACK' || (policy !== 'context-pruning'
105
+ && (integrity?.integrity_state === 'compromised' || hasCompromiseLabels));
106
+ return {
107
+ ceiling: ceilingDecision(release ?? 'HOLD', compromised ? 'ROLLBACK' : 'PROMOTE', problems.length || (options.findings ?? 0) > 0 ? 'HOLD' : 'PROMOTE'),
108
+ problems, compromised,
109
+ };
110
+ }
111
+ //# sourceMappingURL=upstream-ceiling.js.map
@@ -2,11 +2,8 @@ import { readAiwgConfig } from '../config/aiwg-config.js';
2
2
  import { normalizeProviderDefinitionId } from '../providers/provider-definitions.js';
3
3
  import { collectProviderInventory } from '../providers/provider-inventory.js';
4
4
  import { resolveDynamicModelCatalog } from './model-discovery.js';
5
- export const MODEL_WRAPPERS = {
6
- reasoning: 'aiwg-model-reasoning-worker',
7
- coding: 'aiwg-model-coding-worker',
8
- efficiency: 'aiwg-model-efficiency-worker',
9
- };
5
+ import { MODEL_WRAPPER_DEFINITIONS } from './wrapper-definitions.js';
6
+ export { MODEL_WRAPPERS, MODEL_WRAPPER_DEFINITIONS } from './wrapper-definitions.js';
10
7
  async function configuredProviders(cwd) {
11
8
  try {
12
9
  const config = await readAiwgConfig(cwd);
@@ -48,14 +45,14 @@ export async function loadProviderModelMetadata(cwd, aiwgRoot) {
48
45
  const roles = catalog.providers[provider]?.roles;
49
46
  if (!roles)
50
47
  continue;
51
- providers[provider] = Object.keys(MODEL_WRAPPERS)
52
- .flatMap(role => {
48
+ providers[provider] = MODEL_WRAPPER_DEFINITIONS
49
+ .flatMap(({ role, name }) => {
53
50
  const model = roles[role];
54
51
  return model ? [{
55
52
  provider,
56
53
  role,
57
54
  model: model.id,
58
- wrapper: MODEL_WRAPPERS[role],
55
+ wrapper: name,
59
56
  status: model.status ?? 'unknown',
60
57
  observed: model.observed ?? false,
61
58
  source: catalog.discovery?.providers?.[provider]?.source
@@ -0,0 +1,14 @@
1
+ // Canonical wrapper identities reuse the three catalog roles and their existing tiers.
2
+ export const MODEL_WRAPPERS = {
3
+ reasoning: 'aiwg-model-reasoning-worker',
4
+ coding: 'aiwg-model-coding-worker',
5
+ efficiency: 'aiwg-model-efficiency-worker',
6
+ };
7
+ export const MODEL_WRAPPER_DEFINITIONS = [
8
+ { name: MODEL_WRAPPERS.reasoning, role: 'reasoning', tier: 'premium', effort: 'high', readOnly: false },
9
+ { name: MODEL_WRAPPERS.coding, role: 'coding', tier: 'standard', effort: 'medium', readOnly: false },
10
+ { name: MODEL_WRAPPERS.efficiency, role: 'efficiency', tier: 'economy', effort: 'low', readOnly: false },
11
+ { name: 'aiwg-model-explorer', role: 'efficiency', tier: 'economy', effort: 'low', readOnly: true },
12
+ { name: 'aiwg-model-verifier', role: 'coding', tier: 'standard', effort: 'medium', readOnly: true },
13
+ ];
14
+ //# sourceMappingURL=wrapper-definitions.js.map