@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.
Files changed (174) hide show
  1. package/agentic/code/providers/model-catalog.v1.json +62 -12
  2. package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
  3. package/dist/src/artifacts/binding-target-identity.js +51 -0
  4. package/dist/src/artifacts/checksum-manifest.js +12 -0
  5. package/dist/src/artifacts/index-builder.js +11 -13
  6. package/dist/src/artifacts/query-engine.js +5 -11
  7. package/dist/src/cli/handlers/doctor-help.js +32 -0
  8. package/dist/src/cli/handlers/gates.js +19 -18
  9. package/dist/src/cli/handlers/models-help.js +7 -1
  10. package/dist/src/cli/handlers/models.js +3 -3
  11. package/dist/src/cli/handlers/script-runner.js +8 -5
  12. package/dist/src/cli/handlers/sessions-intake.js +104 -0
  13. package/dist/src/cli/handlers/sessions-tail.js +172 -0
  14. package/dist/src/cli/handlers/sessions.js +90 -17
  15. package/dist/src/cli/handlers/skill-lint.js +10 -3
  16. package/dist/src/cli/handlers/steward-format.js +100 -0
  17. package/dist/src/cli/handlers/steward-models.js +167 -0
  18. package/dist/src/cli/handlers/steward.js +14 -248
  19. package/dist/src/cli/handlers/use-bundle-counts.js +87 -0
  20. package/dist/src/cli/handlers/use-skill-assets.js +207 -0
  21. package/dist/src/cli/handlers/use.js +35 -216
  22. package/dist/src/cli/handlers/utilities.js +1 -24
  23. package/dist/src/config/aiwg-config.js +7 -0
  24. package/dist/src/config/authorization-cli.js +97 -0
  25. package/dist/src/config/cli-help.js +1 -0
  26. package/dist/src/config/cli.js +10 -1
  27. package/dist/src/decision/context-pruning-common.js +41 -0
  28. package/dist/src/decision/context-pruning-evaluation.js +366 -0
  29. package/dist/src/decision/context-pruning-pilot.js +431 -0
  30. package/dist/src/decision/context-pruning-types.js +19 -0
  31. package/dist/src/decision/context-pruning.js +5 -846
  32. package/dist/src/decision/ensemble/contract.js +17 -26
  33. package/dist/src/decision/ensemble-study/artifacts.js +5 -0
  34. package/dist/src/decision/ensemble-study/score.js +4 -3
  35. package/dist/src/decision/feature-export.js +3 -9
  36. package/dist/src/decision/heldout/collector.js +2 -2
  37. package/dist/src/decision/issue-triage/runtime.js +3 -9
  38. package/dist/src/decision/qualification/gates.js +2 -1
  39. package/dist/src/decision/qualification/release.js +6 -64
  40. package/dist/src/decision/routing/report.js +2 -0
  41. package/dist/src/decision/sdlc-screening.js +3 -5
  42. package/dist/src/decision/sensitivity/comparative.js +5 -3
  43. package/dist/src/extensions/manifest.js +8 -1
  44. package/dist/src/extensions/project-local-doctor.js +78 -2
  45. package/dist/src/extensions/validation.js +10 -11
  46. package/dist/src/gates/driver.js +6 -77
  47. package/dist/src/gates/evaluate.js +6 -23
  48. package/dist/src/gates/floors.js +4 -4
  49. package/dist/src/gates/index.js +3 -3
  50. package/dist/src/gates/lattice.js +26 -0
  51. package/dist/src/gates/registry.js +2 -1
  52. package/dist/src/gates/report.js +19 -7
  53. package/dist/src/gates/upstream-ceiling.js +111 -0
  54. package/dist/src/issues/audit-cli.js +120 -0
  55. package/dist/src/issues/audit-contract.js +64 -0
  56. package/dist/src/issues/audit-local.js +82 -0
  57. package/dist/src/issues/audit.js +220 -0
  58. package/dist/src/lint/rule-activation.js +15 -1
  59. package/dist/src/mission-protocol/canonical-codecs.js +270 -0
  60. package/dist/src/mission-protocol/codecs.js +22 -550
  61. package/dist/src/mission-protocol/health-trace-codecs.js +281 -0
  62. package/dist/src/mission-protocol/health-trace-types.js +43 -0
  63. package/dist/src/mission-protocol/types.js +2 -42
  64. package/dist/src/mission-protocol/worker-contract-json.js +10 -0
  65. package/dist/src/mission-protocol/worker-review-gate.js +100 -0
  66. package/dist/src/mission-protocol/worker-review-types.js +2 -0
  67. package/dist/src/models/catalog-policy.js +280 -0
  68. package/dist/src/models/index.js +1 -1
  69. package/dist/src/models/model-catalog.v1.json +62 -12
  70. package/dist/src/models/policy-resources.js +28 -0
  71. package/dist/src/models/provider-models.js +5 -8
  72. package/dist/src/models/provider-policy.js +10 -546
  73. package/dist/src/models/resolver.js +26 -8
  74. package/dist/src/models/router.js +15 -2
  75. package/dist/src/models/tiers.js +13 -0
  76. package/dist/src/models/types.js +0 -6
  77. package/dist/src/models/worker-ceilings.js +59 -0
  78. package/dist/src/models/worker-invocation-policy.js +243 -0
  79. package/dist/src/models/worker-plan.js +16 -20
  80. package/dist/src/models/worker-review-lineage.js +55 -0
  81. package/dist/src/models/worker-selection-policy.js +1 -1
  82. package/dist/src/models/wrapper-definitions.js +14 -0
  83. package/dist/src/models/wrapper-deployment.js +48 -25
  84. package/dist/src/models/wrapper-enforcement.js +72 -0
  85. package/dist/src/models/wrapper-route.js +6 -3
  86. package/dist/src/policy/authorization.js +1 -0
  87. package/dist/src/policy/hitl-check.js +80 -0
  88. package/dist/src/policy/hitl-config.js +63 -0
  89. package/dist/src/policy/hitl-receipt.js +57 -0
  90. package/dist/src/policy/hitl-types.js +4 -0
  91. package/dist/src/policy/hitl-validation.js +39 -0
  92. package/dist/src/policy/hitl.js +117 -0
  93. package/dist/src/rules/activation.d.mts +3 -1
  94. package/dist/src/rules/activation.mjs +23 -2
  95. package/dist/src/rules/gate-coverage.js +51 -0
  96. package/dist/src/rules/gate-references.js +16 -0
  97. package/dist/src/rules/rule-frontmatter.schema.json +7 -1
  98. package/dist/src/serve/worker-command-request.js +21 -4
  99. package/dist/src/serve/worker-invocation-preparation.js +3 -1
  100. package/dist/src/serve/worker-invocation.js +21 -10
  101. package/dist/src/sessions/adapters/deepseek-harness.js +1 -0
  102. package/dist/src/sessions/adapters/grok-build-native.js +269 -0
  103. package/dist/src/sessions/adapters/grok-build.js +57 -15
  104. package/dist/src/sessions/adapters/hermes-state-db.js +252 -0
  105. package/dist/src/sessions/adapters/hermes.js +42 -3
  106. package/dist/src/sessions/adapters/warp.js +1 -1
  107. package/dist/src/sessions/batch-import.js +10 -0
  108. package/dist/src/sessions/contracts.js +1 -1
  109. package/dist/src/sessions/discovery-capability.js +38 -0
  110. package/dist/src/sessions/importer.js +8 -251
  111. package/dist/src/sessions/index.js +4 -0
  112. package/dist/src/sessions/intake-dir.js +71 -0
  113. package/dist/src/sessions/normalization.js +251 -0
  114. package/dist/src/sessions/tail.js +91 -0
  115. package/dist/src/sessions/workspace-discovery.js +83 -7
  116. package/dist/src/skills/adapters/local.js +32 -9
  117. package/dist/src/skills/agent-skill-sidecar.js +28 -0
  118. package/dist/src/skills/agent-skills.js +6 -23
  119. package/dist/src/skills/claude-surface-projection.js +25 -0
  120. package/dist/src/skills/cli-display.js +33 -0
  121. package/dist/src/skills/cli.js +2 -26
  122. package/dist/src/skills/collision-discovery.js +84 -0
  123. package/dist/src/skills/deployer.js +26 -361
  124. package/dist/src/skills/deployment-ownership.js +74 -0
  125. package/dist/src/skills/deployment-policy.js +114 -0
  126. package/dist/src/skills/deployment-projection.js +152 -0
  127. package/dist/src/skills/deployment-types.js +20 -0
  128. package/dist/src/skills/doctor.js +2 -2
  129. package/dist/src/skills/exporter.js +8 -31
  130. package/dist/src/skills/importer.js +4 -26
  131. package/dist/src/skills/provider-extensions.js +41 -0
  132. package/dist/src/skills/registry.js +22 -7
  133. package/dist/src/skills/run.js +6 -0
  134. package/dist/src/skills/types.js +0 -8
  135. package/dist/src/skills/validator-resources.js +68 -0
  136. package/dist/src/skills/validator.js +6 -55
  137. package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
  138. package/dist/src/storage/cli-migrate-options.js +125 -0
  139. package/dist/src/storage/cli-migrate.js +111 -0
  140. package/dist/src/storage/cli.js +4 -279
  141. package/dist/src/storage/migration-adapter.js +79 -0
  142. package/dist/src/storage/migration-copy.js +108 -0
  143. package/dist/src/storage/migration-protocol.js +14 -197
  144. package/dist/src/storage/migration-records.js +186 -0
  145. package/dist/src/storage/migration-types.js +12 -0
  146. package/dist/src/tracker/forge-http.js +2 -1
  147. package/dist/src/tracker/issue-pages.js +110 -0
  148. package/package.json +3 -1
  149. package/schemas/mission-v1.schema.json +335 -0
  150. package/schemas/models/model-catalog.v1.schema.json +19 -1
  151. package/schemas/models/model-config-compatibility.v1.schema.json +3 -2
  152. package/schemas/models/model-policy.v1.schema.json +1 -1
  153. package/tools/agents/providers/antigravity.mjs +3 -5
  154. package/tools/agents/providers/base.mjs +3 -3
  155. package/tools/agents/providers/claude.mjs +3 -5
  156. package/tools/agents/providers/codex.mjs +3 -5
  157. package/tools/agents/providers/copilot.mjs +3 -5
  158. package/tools/agents/providers/cursor.mjs +3 -5
  159. package/tools/agents/providers/factory.mjs +3 -5
  160. package/tools/agents/providers/grok-build.mjs +9 -7
  161. package/tools/agents/providers/model-wrapper.mjs +86 -0
  162. package/tools/agents/providers/omp.mjs +3 -1
  163. package/tools/agents/providers/openclaw.mjs +3 -5
  164. package/tools/agents/providers/opencode.mjs +3 -5
  165. package/tools/agents/providers/provider-paths-staging.mjs +44 -0
  166. package/tools/agents/providers/rule-binding-targets.mjs +146 -0
  167. package/tools/agents/providers/rule-delivery.mjs +9 -128
  168. package/tools/agents/providers/warp.mjs +3 -5
  169. package/tools/agents/providers/windsurf.mjs +3 -5
  170. package/tools/plugin/package-plugins.mjs +2 -2
  171. package/tools/skills/codex-skill-transform.mjs +232 -0
  172. package/tools/skills/deploy-skills-codex.mjs +8 -249
  173. package/tools/warp/warp-content.mjs +548 -0
  174. package/vscode-extension/schemas/aiwg.config.v1.json +177 -0
@@ -1,3 +1,4 @@
1
+ import { assertGateReportDecision } from './report.js';
1
2
  import { lstatSync } from 'node:fs';
2
3
  import { readFile } from 'node:fs/promises';
3
4
  import path from 'node:path';
@@ -159,11 +160,12 @@ export async function validateGateFile(kind, filePath, options = {}) {
159
160
  else {
160
161
  // Full report validation needs the trusted evaluation context
161
162
  // (`validateGateReport` re-derives the report byte-identically).
162
- // `validate` checks the closed schema, the kind and the self-digest,
163
+ // `validate` checks component ceilings, the closed schema, kind and self-digest,
163
164
  // so rewritten evidence with a stale digest still fails here.
164
165
  const report = validateGateDocument(document);
165
166
  if (!isRecord(document) || document.kind !== 'GateReport')
166
167
  throw new Error('expected kind GateReport');
168
+ assertGateReportDecision(report);
167
169
  const { digest, ...fields } = report;
168
170
  if (typeof digest !== 'string' || artifactDigest(fields) !== digest) {
169
171
  throw new Error('report digest does not match its content');
@@ -276,83 +278,10 @@ export function listGatePacks(options = {}) {
276
278
  return summaries.filter(entry => entry.namespace === options.namespace);
277
279
  return summaries;
278
280
  }
279
- /**
280
- * Packs referenced by one rule's `enforcedBy` frontmatter (#2830 stub; full
281
- * coverage is #2839). Scans bundled and project-local `rules/*.md` for an
282
- * `enforcedBy: [aiwg:<bundle>/<pack>#<gate>]` list naming the rule. Returns
283
- * the referenced pack ids (without gate fragments). Empty when no rule
284
- * declares `enforcedBy` — rules remain guidance until they name a check.
285
- */
281
+ /** List the distinct packs named by validated rule coverage declarations. */
286
282
  export async function packsReferencedByRule(ruleId, options = {}) {
287
- const { readdir, readFile: readRuleFile, stat } = await import('node:fs/promises');
288
- const roots = [];
289
- const root = rootDir(options);
290
- for (const sub of ['frameworks', 'addons', 'extensions']) {
291
- roots.push(path.join(root, 'agentic/code', sub));
292
- }
293
- roots.push(path.join(baseDir(options), '.aiwg'));
294
- const ruleFiles = [];
295
- const walk = async (dir, depth) => {
296
- if (depth > 5 || ruleFiles.length > 500)
297
- return;
298
- let entries;
299
- try {
300
- entries = await readdir(dir, { withFileTypes: true });
301
- }
302
- catch {
303
- return;
304
- }
305
- for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
306
- if (ruleFiles.length > 500)
307
- return;
308
- const full = path.join(dir, entry.name);
309
- if (entry.isDirectory()) {
310
- if (entry.name === 'node_modules' || entry.name.startsWith('.git'))
311
- continue;
312
- await walk(full, depth + 1);
313
- }
314
- else if (entry.isFile() && entry.name.endsWith('.md')) {
315
- if (!full.replace(/\\/g, '/').includes('/rules/'))
316
- continue;
317
- ruleFiles.push(full);
318
- }
319
- }
320
- };
321
- for (const dir of roots)
322
- await walk(dir, 0);
323
- const referenced = new Set();
324
- for (const file of ruleFiles) {
325
- let content;
326
- try {
327
- const st = await stat(file);
328
- if (st.size > 65_536)
329
- continue;
330
- content = await readRuleFile(file, 'utf8');
331
- }
332
- catch {
333
- continue;
334
- }
335
- const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/);
336
- if (!match)
337
- continue;
338
- const frontmatter = match[1];
339
- if (!frontmatter.includes('enforcedBy'))
340
- continue;
341
- const ruleName = path.basename(file, '.md');
342
- const dirName = path.basename(path.dirname(file));
343
- const names = new Set([ruleName, dirName === 'rules' ? null : `${dirName}/${ruleName}`, file]);
344
- if (!names.has(ruleId) && ![...names].filter(Boolean).some(name => ruleId.endsWith(String(name))))
345
- continue;
346
- for (const line of frontmatter.split('\n')) {
347
- const trimmed = line.trim().replace(/^-\s*/, '');
348
- const id = trimmed.match(/(aiwg|framework|addon|extension|project):[^\s,'"\]]+/)?.[1]
349
- ? trimmed.match(/((?:aiwg|framework|addon|extension|project):[^\s,'"\]]+)/)?.[1]
350
- : null;
351
- if (id)
352
- referenced.add(id.split('#')[0]);
353
- }
354
- }
355
- return [...referenced].sort();
283
+ const { listRuleGateCoverage } = await import('../rules/gate-coverage.js');
284
+ return [...new Set(listRuleGateCoverage(options, ruleId).flatMap(rule => rule.enforcedBy.map(reference => reference.split('#')[0])))].sort();
356
285
  }
357
286
  /** Show one pack by full id, rest-path or short pack name. */
358
287
  export function showGatePack(id, options = {}) {
@@ -1,4 +1,5 @@
1
- import { qualificationIntegrityAllowlistProblems } from '../decision/qualification/release.js';
1
+ import { ceilingDecision, maxOutcome } from './lattice.js';
2
+ import { evaluateUpstreamCeiling } from './upstream-ceiling.js';
2
3
  import { artifactDigest } from '../decision/validate.js';
3
4
  import { evaluatePredicate } from '../decision/predicates.js';
4
5
  import { clopperPearsonInterval } from './stats/clopper-pearson.js';
@@ -12,11 +13,7 @@ import { qualifyGateParameter } from './types.js';
12
13
  export class GateEvaluationError extends Error {
13
14
  constructor(message) { super(message); this.name = 'GateEvaluationError'; }
14
15
  }
15
- const RANK = { PROMOTE: 0, HOLD: 1, ROLLBACK: 2 };
16
- /** Shared outcome lattice. The maximum never upgrades any component. */
17
- export function maxOutcome(...outcomes) {
18
- return outcomes.reduce((worst, outcome) => (RANK[outcome] > RANK[worst] ? outcome : worst), 'PROMOTE');
19
- }
16
+ export { maxOutcome } from './lattice.js';
20
17
  /**
21
18
  * Per-gate outcome from its own status: `pass` promotes, `fail` takes the
22
19
  * gate's `onFail`, `insufficient` takes `onInsufficient` (always HOLD by load
@@ -390,13 +387,10 @@ function evaluateObservation(gate, observation, context) {
390
387
  if (upstream === null)
391
388
  return { ...base, status: 'insufficient', reason: 'upstream-missing',
392
389
  statistic: { method: 'upstream-integrity' } };
393
- const problems = qualificationIntegrityAllowlistProblems(upstream.metadata);
390
+ const { problems, compromised } = evaluateUpstreamCeiling(upstream.metadata);
394
391
  if (!problems.length) {
395
392
  return { ...base, status: 'pass', reason: 'upstream-clean', statistic: { method: 'upstream-integrity' } };
396
393
  }
397
- const compromised = problems.includes('compromised')
398
- || upstream.metadata.release_gate?.decision === 'ROLLBACK'
399
- || upstream.metadata.integrity_state === 'compromised';
400
394
  return { ...base, status: 'fail', reason: compromised ? 'upstream-compromised' : 'upstream-allowlist',
401
395
  statistic: { method: 'upstream-integrity' } };
402
396
  }
@@ -440,18 +434,7 @@ function rerunProviderOrFail(provider, args, providerId) {
440
434
  }
441
435
  }
442
436
  function upstreamOutcome(upstream) {
443
- if (upstream === null)
444
- return { ceiling: 'HOLD', problems: ['upstream-ceiling-missing'] };
445
- const problems = qualificationIntegrityAllowlistProblems(upstream.metadata);
446
- const release = upstream.metadata.release_gate?.decision;
447
- const compromised = problems.includes('compromised')
448
- || release === 'ROLLBACK'
449
- || upstream.metadata.integrity_state === 'compromised';
450
- if (compromised)
451
- return { ceiling: 'ROLLBACK', problems };
452
- if (problems.length || release === 'HOLD')
453
- return { ceiling: 'HOLD', problems };
454
- return { ceiling: 'PROMOTE', problems };
437
+ return evaluateUpstreamCeiling(upstream?.metadata ?? null);
455
438
  }
456
439
  /**
457
440
  * Pure, deterministic gate evaluation. The binding is resolved internally
@@ -685,7 +668,7 @@ export function evaluateGates(input) {
685
668
  const packOutcome = maxOutcome(...gateEvidence.map(entry => entry.outcome));
686
669
  const { ceiling: upstreamCeiling, problems: upstreamProblems } = upstreamOutcome(upstream);
687
670
  const bindingCeiling = binding.spec.ceiling ?? 'PROMOTE';
688
- const decision = maxOutcome(packOutcome, upstreamCeiling, bindingCeiling);
671
+ const decision = ceilingDecision(packOutcome, upstreamCeiling, bindingCeiling);
689
672
  const body = {
690
673
  apiVersion: binding.apiVersion,
691
674
  kind: 'GateReport',
@@ -1,6 +1,6 @@
1
+ import { GATE_RANK } from './lattice.js';
1
2
  import { validateGateDocument } from './schema.js';
2
3
  import { splitPackId } from './registry.js';
3
- const OUTCOME_RANK = { PROMOTE: 0, HOLD: 1, ROLLBACK: 2 };
4
4
  const OUTCOMES = ['PROMOTE', 'HOLD', 'ROLLBACK'];
5
5
  const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
6
6
  const DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
@@ -22,7 +22,7 @@ export const INTEGRITY_CEILING_FLOOR_PACK_VERSION = '1.0.0';
22
22
  export function projectCeilingSatisfied(declared, configured) {
23
23
  if (configured === undefined)
24
24
  return true;
25
- return OUTCOME_RANK[declared ?? 'PROMOTE'] >= OUTCOME_RANK[configured];
25
+ return GATE_RANK[declared ?? 'PROMOTE'] >= GATE_RANK[configured];
26
26
  }
27
27
  /**
28
28
  * Resolves the effective project floors: the configured entries, verbatim.
@@ -64,7 +64,7 @@ export function assertCeilingDefaults(ceilings) {
64
64
  continue;
65
65
  if (!starValid)
66
66
  throw new Error(`gates.ceilings: per-study ceilings require the project-wide '*' default ceiling`);
67
- if (OUTCOME_RANK[ceiling] < OUTCOME_RANK[star]) {
67
+ if (GATE_RANK[ceiling] < GATE_RANK[star]) {
68
68
  throw new Error(`gates.ceilings.${study}: must tighten the project default ceiling ${String(star)}, not loosen it`);
69
69
  }
70
70
  }
@@ -124,7 +124,7 @@ export function validateGatesConfig(gates) {
124
124
  for (const [study, ceiling] of Object.entries(gates.ceilings)) {
125
125
  if (study !== '*' && typeof ceiling === 'string'
126
126
  && OUTCOMES.includes(ceiling)
127
- && OUTCOME_RANK[ceiling] < OUTCOME_RANK[star]) {
127
+ && GATE_RANK[ceiling] < GATE_RANK[star]) {
128
128
  errors.push(`gates.ceilings.${study}: must tighten the project default ceiling ${star}, not loosen it`);
129
129
  }
130
130
  }
@@ -1,17 +1,17 @@
1
1
  /**
2
2
  * Gates capability phase 1 core (epic #2824): declarative gate packs, a pure deterministic
3
- * evaluator and digest-bound reports. Experimental and default-off: nothing in the
4
- * decision runtime imports this module, so existing behavior is unchanged.
3
+ * evaluator and digest-bound reports. Decision consumers share its outcome lattice.
5
4
  */
6
5
  export { GATES_API_VERSION, qualifyGateParameter } from './types.js';
7
6
  export { GateSchemaError, validateGateDocument } from './schema.js';
8
7
  export { GateRegistryError, GATE_NAMESPACES, splitPackId, validateResolvedPack, resolveThresholdDefault, assertGateTightens, applyGateExtends, composeGatePack, resolveGateBinding, expandFloorPacks, enforceProjectFloors, authoredGatePacksOf, gateProvidersOf, GateRegistry, } from './registry.js';
9
8
  export { INTEGRITY_CEILING_FLOOR_PACK_ID, INTEGRITY_CEILING_FLOOR_PACK_VERSION, assertCeilingDefaults, projectCeilingSatisfied, resolveProjectFloors, validateGatesConfig, } from './floors.js';
10
9
  export { GateEvaluationError, maxOutcome, gateStatusOutcome, sealUpstream, sealGateHoldout, evaluateGates, } from './evaluate.js';
11
- export { validateGateReport } from './report.js';
10
+ export { assertGateReportDecision, validateGateReport } from './report.js';
12
11
  export { createCoreProviderRegistry, evidenceProvider, pairedProvider, proportionProvider, scalarProvider, screeningProvider } from './providers/index.js';
13
12
  export { MetricProviderRegistry } from './providers/index.js';
14
13
  export { GATE_PACKS_DIR, GATE_PACK_MAX_BYTES, isGatePackFile, listGatePackFiles, readBundleGatePacksDeclaration, loadGatePackFile, originForPackDir, registerBundleGatePacks, resolveGatePacksDir, discoverShippedGatePacks, } from './discovery.js';
15
14
  export { buildGatesRegistry, validateGateFile, loadHoldoutFile, loadUpstreamFile, evaluateGatesFromFiles, installedAiwgRoot, listGatePacks, loadProjectFloorsForEvaluate, showGatePack, packsReferencedByRule, } from './driver.js';
16
15
  export { GateProviderError, computeProviderCodeDigest, deriveIsolatedSeed, loadGateBundleProviders, invokeBundleProvider, providerBindingPin, runIsolatedProvider, runIsolatedProviderSync, sealProviderSection, snapshotProviderDir, isLoaderIssuedProvider, isolationLaunchPlan, isolationSandboxStatus, parseIsolatedFrame, probeIsolationSandbox, isBundleProvidersEnabled, GATE_PROVIDER_MAX_FILE_BYTES, GATE_PROVIDER_MAX_FILES, GATE_PROVIDER_MAX_TOTAL_BYTES, GATE_PROVIDER_DEFAULT_TIMEOUT_MS, GATE_PROVIDER_MAX_TIMEOUT_MS, GATE_PROVIDER_DEFAULT_MAX_RECORDS, GATE_PROVIDER_MAX_OUTPUT_BYTES, } from './providers/loader.js';
16
+ export { GATE_RANK, ceilingDecision, assertDecisionCeiling, GateDecisionUpgradeError } from './lattice.js';
17
17
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,26 @@
1
+ export const GATE_RANK = Object.freeze({ PROMOTE: 0, HOLD: 1, ROLLBACK: 2 });
2
+ /** The strictest outcome wins; an empty set has no restriction. */
3
+ export function maxOutcome(...outcomes) {
4
+ return outcomes.reduce((worst, outcome) => GATE_RANK[outcome] > GATE_RANK[worst] ? outcome : worst, 'PROMOTE');
5
+ }
6
+ export function ceilingDecision(decision, ...ceilings) {
7
+ return maxOutcome(decision, ...ceilings);
8
+ }
9
+ export class GateDecisionUpgradeError extends Error {
10
+ code = 'report-upgrades-component';
11
+ decision;
12
+ component;
13
+ constructor(decision, component) {
14
+ super(`Report decision differs from components: cannot upgrade ${component} to ${decision} (report-upgrades-component)`);
15
+ this.name = 'GateDecisionUpgradeError';
16
+ this.decision = decision;
17
+ this.component = component;
18
+ }
19
+ }
20
+ /** Validate a carried verdict independently of its digest or reproducibility checks. */
21
+ export function assertDecisionCeiling(decision, ...components) {
22
+ const component = maxOutcome(...components);
23
+ if (GATE_RANK[decision] < GATE_RANK[component])
24
+ throw new GateDecisionUpgradeError(decision, component);
25
+ }
26
+ //# sourceMappingURL=lattice.js.map
@@ -1,3 +1,4 @@
1
+ import { ceilingDecision } from './lattice.js';
1
2
  import { canonicalJson } from '../security/artifact-trust.js';
2
3
  import { artifactDigest } from '../decision/validate.js';
3
4
  import { validateGateDocument } from './schema.js';
@@ -428,7 +429,7 @@ export function assertGateTightens(parent, child, params) {
428
429
  else if (minimumAfter < minimumBefore) {
429
430
  fail(`gate ${child.id} may only raise minimumN`);
430
431
  }
431
- if (parent.onFail === 'ROLLBACK' && child.onFail !== 'ROLLBACK') {
432
+ if (ceilingDecision(child.onFail, parent.onFail) !== child.onFail) {
432
433
  fail(`gate ${child.id} may not demote onFail ROLLBACK -> HOLD`);
433
434
  }
434
435
  // Insufficient evidence always holds: ROLLBACK needs an observed blocking
@@ -1,6 +1,7 @@
1
+ import { assertDecisionCeiling, GateDecisionUpgradeError } from './lattice.js';
1
2
  import { canonicalJson } from '../security/artifact-trust.js';
2
3
  import { artifactDigest } from '../decision/validate.js';
3
- import { evaluateGates, maxOutcome } from './evaluate.js';
4
+ import { evaluateGates } from './evaluate.js';
4
5
  import { validateGateDocument } from './schema.js';
5
6
  /**
6
7
  * Validates a gate report against its trusted inputs. The report is re-derived
@@ -85,12 +86,14 @@ export function validateGateReport(report, input) {
85
86
  }
86
87
  if (expected.decision !== parsed.decision)
87
88
  reasons.push('report-decision-mismatch');
88
- const components = [
89
- ...parsed.gateEvidence.map(entry => entry.outcome),
90
- parsed.ceilings.packOutcome, parsed.ceilings.upstreamCeiling, parsed.ceilings.bindingCeiling,
91
- ];
92
- if (maxOutcome(parsed.decision, maxOutcome(...components)) !== parsed.decision) {
93
- reasons.push('report-upgrades-component');
89
+ try {
90
+ assertGateReportDecision(parsed);
91
+ assertDecisionCeiling(parsed.decision, input.upstream?.metadata.release_gate.decision ?? 'PROMOTE', input.binding.spec.ceiling ?? 'PROMOTE');
92
+ }
93
+ catch (error) {
94
+ if (!(error instanceof GateDecisionUpgradeError))
95
+ throw error;
96
+ return { valid: false, reasons: [...reasons, error.code], error };
94
97
  }
95
98
  return { valid: reasons.length === 0, reasons };
96
99
  }
@@ -99,4 +102,13 @@ function stripDigest(report) {
99
102
  void _dropped;
100
103
  return fields;
101
104
  }
105
+ /** Validate carried component ceilings even when no trusted replay context is available. */
106
+ export function assertGateReportDecision(report) {
107
+ const components = [
108
+ ...report.gateEvidence.map(entry => entry.outcome),
109
+ report.ceilings.packOutcome, report.ceilings.upstreamCeiling, report.ceilings.bindingCeiling,
110
+ report.upstream?.decision ?? 'PROMOTE',
111
+ ];
112
+ assertDecisionCeiling(report.decision, ...components);
113
+ }
102
114
  //# sourceMappingURL=report.js.map
@@ -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
@@ -0,0 +1,120 @@
1
+ // Wire issue-audit into the existing skill executor and configured tracker/label routing.
2
+ import { parseArgs } from 'node:util';
3
+ import { resolve } from 'node:path';
4
+ import { resolveIssueLabels } from '../config/aiwg-config.js';
5
+ import { projectAiwgWritePath } from '../config/project-artifacts.js';
6
+ import { resolveTrackerAuthority, chooseTrackerAccess } from '../tracker/capability-protocol.js';
7
+ import { readConfig, readGitRemoteUrls } from '../tracker/project-inputs.js';
8
+ import { cliForgeTransport, httpForgeTransport, forgeEndpointFromRemote } from '../tracker/forge-http.js';
9
+ import { createForgeAuditTracker } from '../tracker/issue-pages.js';
10
+ import { resolveToken } from './live.js';
11
+ import { localIssueRoot } from './local.js';
12
+ import { createLocalAuditTracker } from './audit-local.js';
13
+ import { runIssueAudit, renderIssueAudit, needsAuditContent } from './audit.js';
14
+ import { AuditStop, auditDigest, parseAuditFilter } from './audit-contract.js';
15
+ export async function main(args, cwd = process.cwd(), dependencies = {}) {
16
+ const output = dependencies.output ?? console.log;
17
+ let format = 'markdown';
18
+ try {
19
+ const { values: v } = parseArgs({ args, strict: true, options: {
20
+ filter: { type: 'string' }, guidance: { type: 'string' }, provider: { type: 'string' },
21
+ checkpoint: { type: 'string' }, 'page-size': { type: 'string' }, 'max-items': { type: 'string' }, 'max-pages': { type: 'string' },
22
+ 'max-bytes': { type: 'string' }, 'max-context-bytes': { type: 'string' },
23
+ select: { type: 'string' }, format: { type: 'string' }, 'all-open': { type: 'boolean' },
24
+ 'dry-run': { type: 'boolean' }, apply: { type: 'boolean' }, interactive: { type: 'boolean' }, help: { type: 'boolean' },
25
+ } });
26
+ format = v.format ?? 'markdown';
27
+ if (!['json', 'markdown'].includes(format))
28
+ throw new AuditStop('format-invalid');
29
+ if (v.help) {
30
+ output('aiwg run skill issue-audit -- [--filter "status:open label:bug"] [--guidance TEXT] [--provider local|gitea|github]\n'
31
+ + ' [--checkpoint PATH] [--page-size 25] [--max-items 250] [--max-pages 100] [--max-bytes 65536]\n'
32
+ + ' [--max-context-bytes 262144] [--select ID,ID] [--format json|markdown]\n'
33
+ + 'Rerun the same scope/checkpoint to resume. Execution is read-only; cleanup decisions use the instructional workflow.');
34
+ return 0;
35
+ }
36
+ if (v.apply || v.interactive)
37
+ throw new AuditStop('use-instructional-workflow-for-interactive-or-apply');
38
+ const number = (name, fallback) => {
39
+ const value = Number(v[name] ?? fallback);
40
+ if (!Number.isSafeInteger(value) || value < 1)
41
+ throw new AuditStop(`invalid-${name}`);
42
+ return value;
43
+ };
44
+ const pageSize = number('page-size', 25);
45
+ const maxItems = number('max-items', 250);
46
+ const maxPages = number('max-pages', 100);
47
+ const maxBytes = number('max-bytes', 65_536);
48
+ const maxContextBytes = number('max-context-bytes', 262_144);
49
+ if (pageSize > 100)
50
+ throw new AuditStop('invalid-page-size');
51
+ const config = dependencies.config === undefined ? await readConfig(cwd) : dependencies.config;
52
+ const authority = resolveTrackerAuthority(config, dependencies.remoteUrls ?? await readGitRemoteUrls(cwd));
53
+ const provider = v.provider ?? authority.provider;
54
+ if (provider !== 'local' && provider !== 'gitea' && provider !== 'github')
55
+ throw new AuditStop('tracker-provider-unresolved');
56
+ const taxonomy = resolveIssueLabels(config?.issues, provider);
57
+ if (taxonomy.diagnostics.some(d => d.severity === 'error'))
58
+ throw new AuditStop('label-taxonomy-invalid');
59
+ const filter = v.filter ?? 'status:open';
60
+ const parsedFilter = parseAuditFilter(filter);
61
+ const nativeFilter = [`status:${parsedFilter.status}`, ...parsedFilter.labels.map(role => `label:${JSON.stringify(taxonomy.labels[role]?.resolved_name ?? role)}`)].join(' ');
62
+ const selection = v.select === undefined ? null : new Set(v.select.split(',').map(s => s.trim()).filter(Boolean));
63
+ const checkpoint = v.checkpoint ? resolve(cwd, v.checkpoint) : projectAiwgWritePath(cwd, 'working', 'issue-audit', 'checkpoint.json');
64
+ const env = dependencies.env ?? process.env;
65
+ let tracker = dependencies.tracker;
66
+ if (!tracker) {
67
+ if (provider === 'local')
68
+ tracker = createLocalAuditTracker(localIssueRoot(cwd));
69
+ else {
70
+ const endpoint = forgeEndpointFromRemote(provider, authority.issueTrackerUrl);
71
+ if (!endpoint)
72
+ throw new AuditStop('tracker-repository-unresolved');
73
+ const token = resolveToken(provider, env);
74
+ const access = chooseTrackerAccess({ ...authority, provider }, [
75
+ { kind: 'http-api', provider, remoteName: authority.issueTrackerRemote, available: !!token, authenticated: !!token },
76
+ { kind: 'cli', provider, remoteName: authority.issueTrackerRemote, available: provider === 'github', cli: 'gh' },
77
+ ]);
78
+ const transport = access.kind === 'http-api' && token
79
+ ? httpForgeTransport({ provider, apiBaseUrl: endpoint.apiBaseUrl, token, maxResponseBytes: maxBytes })
80
+ : access.kind === 'cli' ? cliForgeTransport({ provider, hostname: endpoint.host, maxResponseBytes: maxBytes }) : null;
81
+ if (!transport)
82
+ throw new AuditStop('tracker-no-access-route');
83
+ tracker = createForgeAuditTracker(provider, endpoint.repository, transport, `${provider}:${endpoint.apiBaseUrl}:${endpoint.repository}:${config?.remotes?.tracker_actor?.login ?? ''}`);
84
+ }
85
+ }
86
+ const nativeTracker = tracker;
87
+ const semanticTracker = { ...nativeTracker,
88
+ async listMetadata(options) {
89
+ const page = await nativeTracker.listMetadata(options);
90
+ return { ...page, items: page.items.map(i => ({ ...i, labels: [...i.labels,
91
+ ...Object.values(taxonomy.labels).filter(l => i.labels.includes(l.resolved_name)).map(l => l.role)] })) };
92
+ },
93
+ };
94
+ const controller = new AbortController();
95
+ const interrupt = () => controller.abort();
96
+ process.once('SIGINT', interrupt);
97
+ process.once('SIGTERM', interrupt);
98
+ try {
99
+ const report = await runIssueAudit(semanticTracker, { checkpoint, pageSize, maxItems, maxPages, maxBytes, maxContextBytes,
100
+ filter: nativeFilter, guidance: v.guidance, signal: controller.signal,
101
+ policyKey: auditDigest([selection ? [...selection].sort() : null, taxonomy.labels]),
102
+ select: i => selection ? selection.has(i.id) : needsAuditContent(i) });
103
+ output(format === 'json' ? JSON.stringify({ ...report, scope: { provider, filter }, diagnostics: taxonomy.diagnostics })
104
+ : `${renderIssueAudit(report)}${taxonomy.diagnostics.map(d => `\n${d.severity}: ${d.message}`).join('')}`);
105
+ return report.coverage.incomplete ? 2 : 0;
106
+ }
107
+ finally {
108
+ process.removeListener('SIGINT', interrupt);
109
+ process.removeListener('SIGTERM', interrupt);
110
+ }
111
+ }
112
+ catch (error) {
113
+ const reason = error instanceof AuditStop ? error.reason : 'audit-error';
114
+ output(format === 'json' ? JSON.stringify({ mode: 'read-only', coverage: {
115
+ totalSeen: 0, totalHydrated: 0, totalCompleted: 0, incomplete: true, reason
116
+ } }) : `# Issue Audit\n\nCoverage: INCOMPLETE (${reason})`);
117
+ return 2;
118
+ }
119
+ }
120
+ //# sourceMappingURL=audit-cli.js.map
@@ -0,0 +1,64 @@
1
+ // Shared bounded retrieval and checkpoint envelope for issue-audit backends.
2
+ import { createHash } from 'node:crypto';
3
+ export class AuditStop extends Error {
4
+ reason;
5
+ constructor(reason) {
6
+ super(reason);
7
+ this.reason = reason;
8
+ }
9
+ }
10
+ export const auditBytes = (value) => Buffer.byteLength(JSON.stringify(value));
11
+ export const auditDigest = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
12
+ export function boundedPageSize(value) {
13
+ if (!Number.isSafeInteger(value) || value < 1 || value > 100)
14
+ throw new AuditStop('invalid-page-size');
15
+ return value;
16
+ }
17
+ export function encodeAuditCursor(value) {
18
+ return Buffer.from(JSON.stringify(value)).toString('base64url');
19
+ }
20
+ export function decodeAuditCursor(cursor) {
21
+ try {
22
+ if (!/^[A-Za-z0-9_-]{1,8192}$/.test(cursor))
23
+ throw new Error();
24
+ return JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
25
+ }
26
+ catch {
27
+ throw new AuditStop('cursor-invalidated');
28
+ }
29
+ }
30
+ /** Reject unsupported filters rather than quietly broadening audit coverage. */
31
+ export function parseAuditFilter(expression) {
32
+ const result = { status: 'open', labels: [] };
33
+ const tokens = /(?:^|\s+)(status|label):("(?:[^"\\]|\\.)*"|'[^']*'|[^\s"']+)/gy;
34
+ let position = 0;
35
+ const input = expression.trim();
36
+ while (position < input.length) {
37
+ const match = tokens.exec(input);
38
+ if (!match)
39
+ throw new AuditStop('filter-invalid');
40
+ let value = match[2];
41
+ if (value.startsWith('"')) {
42
+ try {
43
+ value = JSON.parse(value);
44
+ }
45
+ catch {
46
+ throw new AuditStop('filter-invalid');
47
+ }
48
+ }
49
+ else if (value.startsWith("'"))
50
+ value = value.slice(1, -1);
51
+ if (!value)
52
+ throw new AuditStop('filter-invalid');
53
+ if (match[1] === 'status') {
54
+ if (!['open', 'closed', 'all'].includes(value))
55
+ throw new AuditStop('filter-invalid');
56
+ result.status = value;
57
+ }
58
+ else
59
+ result.labels.push(value);
60
+ position = tokens.lastIndex;
61
+ }
62
+ return result;
63
+ }
64
+ //# sourceMappingURL=audit-contract.js.map