@aiwg/cli 2026.10.10 → 2026.10.12

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 (156) hide show
  1. package/agentic/code/providers/model-capabilities.v1.json +78 -14
  2. package/agentic/code/providers/model-catalog.v1.json +62 -12
  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 +287 -31
  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 +61 -0
  20. package/dist/src/cli/handlers/use.js +18 -28
  21. package/dist/src/cli/handlers/utilities.js +1 -24
  22. package/dist/src/config/aiwg-config.js +7 -0
  23. package/dist/src/config/authorization-cli.js +89 -0
  24. package/dist/src/config/cli-help.js +1 -0
  25. package/dist/src/config/cli.js +10 -1
  26. package/dist/src/config/worker-context.js +337 -0
  27. package/dist/src/decision/context-pruning.js +3 -2
  28. package/dist/src/decision/ensemble/contract.js +15 -4
  29. package/dist/src/decision/ensemble-study/artifacts.js +5 -0
  30. package/dist/src/decision/ensemble-study/score.js +4 -3
  31. package/dist/src/decision/feature-export.js +3 -9
  32. package/dist/src/decision/heldout/collector.js +2 -2
  33. package/dist/src/decision/issue-triage/runtime.js +3 -9
  34. package/dist/src/decision/qualification/gates.js +2 -1
  35. package/dist/src/decision/qualification/release.js +2 -3
  36. package/dist/src/decision/routing/report.js +2 -0
  37. package/dist/src/decision/sdlc-screening.js +3 -5
  38. package/dist/src/decision/sensitivity/comparative.js +5 -3
  39. package/dist/src/gates/driver.js +6 -77
  40. package/dist/src/gates/evaluate.js +4 -11
  41. package/dist/src/gates/floors.js +4 -4
  42. package/dist/src/gates/index.js +3 -3
  43. package/dist/src/gates/lattice.js +26 -0
  44. package/dist/src/gates/registry.js +2 -1
  45. package/dist/src/gates/report.js +19 -7
  46. package/dist/src/issues/audit-cli.js +120 -0
  47. package/dist/src/issues/audit-contract.js +64 -0
  48. package/dist/src/issues/audit-local.js +82 -0
  49. package/dist/src/issues/audit.js +220 -0
  50. package/dist/src/lint/rule-activation.js +15 -1
  51. package/dist/src/mcp/tools/worker-invoke.mjs +108 -10
  52. package/dist/src/mission-protocol/canonical-codecs.js +270 -0
  53. package/dist/src/mission-protocol/codecs.js +22 -550
  54. package/dist/src/mission-protocol/health-trace-codecs.js +281 -0
  55. package/dist/src/mission-protocol/health-trace-types.js +43 -0
  56. package/dist/src/mission-protocol/types.js +2 -42
  57. package/dist/src/mission-protocol/worker-contract-json.js +10 -0
  58. package/dist/src/mission-protocol/worker-review-gate.js +100 -0
  59. package/dist/src/mission-protocol/worker-review-types.js +2 -0
  60. package/dist/src/models/catalog-policy.js +280 -0
  61. package/dist/src/models/index.js +1 -1
  62. package/dist/src/models/model-capabilities.v1.json +78 -14
  63. package/dist/src/models/model-catalog.v1.json +62 -12
  64. package/dist/src/models/policy-resources.js +28 -0
  65. package/dist/src/models/provider-policy.js +10 -539
  66. package/dist/src/models/resolver.js +26 -8
  67. package/dist/src/models/router.js +15 -2
  68. package/dist/src/models/tiers.js +13 -0
  69. package/dist/src/models/types.js +0 -6
  70. package/dist/src/models/worker-ceilings.js +59 -0
  71. package/dist/src/models/worker-invocation-policy.js +243 -0
  72. package/dist/src/models/worker-plan.js +16 -20
  73. package/dist/src/models/worker-review-lineage.js +55 -0
  74. package/dist/src/models/worker-selection-policy.js +1 -1
  75. package/dist/src/models/wrapper-route.js +6 -3
  76. package/dist/src/policy/authorization.js +30 -1
  77. package/dist/src/policy/hitl-config.js +63 -0
  78. package/dist/src/policy/hitl-receipt.js +57 -0
  79. package/dist/src/policy/hitl-types.js +4 -0
  80. package/dist/src/policy/hitl-validation.js +39 -0
  81. package/dist/src/policy/hitl.js +117 -0
  82. package/dist/src/process/aiwg-probe-command.d.mts +15 -0
  83. package/dist/src/process/aiwg-probe-command.mjs +37 -0
  84. package/dist/src/rules/activation.d.mts +1 -1
  85. package/dist/src/rules/activation.mjs +0 -2
  86. package/dist/src/rules/gate-coverage.js +51 -0
  87. package/dist/src/rules/gate-references.js +16 -0
  88. package/dist/src/rules/rule-frontmatter.schema.json +7 -1
  89. package/dist/src/serve/worker-command-request.js +21 -4
  90. package/dist/src/serve/worker-invocation-preparation.js +3 -1
  91. package/dist/src/serve/worker-invocation.js +21 -10
  92. package/dist/src/sessions/adapters/deepseek-harness.js +1 -0
  93. package/dist/src/sessions/adapters/grok-build-native.js +269 -0
  94. package/dist/src/sessions/adapters/grok-build.js +57 -15
  95. package/dist/src/sessions/adapters/grokbot.js +7 -0
  96. package/dist/src/sessions/adapters/hermes-state-db.js +252 -0
  97. package/dist/src/sessions/adapters/hermes.js +42 -3
  98. package/dist/src/sessions/adapters/warp.js +1 -1
  99. package/dist/src/sessions/batch-import.js +44 -6
  100. package/dist/src/sessions/contracts.js +20 -1
  101. package/dist/src/sessions/coverage-preflight.js +7 -1
  102. package/dist/src/sessions/discovery-capability.js +38 -0
  103. package/dist/src/sessions/fortemi-export-mapping.js +33 -3
  104. package/dist/src/sessions/host-catalog.js +157 -0
  105. package/dist/src/sessions/image-blobs.js +141 -0
  106. package/dist/src/sessions/importer.js +9 -232
  107. package/dist/src/sessions/index.js +6 -0
  108. package/dist/src/sessions/intake-dir.js +71 -0
  109. package/dist/src/sessions/normalization.js +251 -0
  110. package/dist/src/sessions/refresh.js +25 -2
  111. package/dist/src/sessions/repository.js +164 -22
  112. package/dist/src/sessions/tail.js +91 -0
  113. package/dist/src/sessions/workspace-discovery.js +88 -9
  114. package/dist/src/skills/agent-skill-sidecar.js +28 -0
  115. package/dist/src/skills/agent-skills.js +4 -23
  116. package/dist/src/skills/claude-surface-projection.js +25 -0
  117. package/dist/src/skills/deployer.js +8 -288
  118. package/dist/src/skills/deployment-policy.js +114 -0
  119. package/dist/src/skills/deployment-projection.js +152 -0
  120. package/dist/src/skills/deployment-types.js +20 -0
  121. package/dist/src/skills/exporter.js +8 -31
  122. package/dist/src/skills/provider-extensions.js +41 -0
  123. package/dist/src/skills/run.js +6 -0
  124. package/dist/src/skills/types.js +0 -8
  125. package/dist/src/skills/validator-resources.js +68 -0
  126. package/dist/src/skills/validator.js +6 -55
  127. package/dist/src/storage/cli-migrate-options.js +125 -0
  128. package/dist/src/storage/cli-migrate.js +111 -0
  129. package/dist/src/storage/cli.js +4 -279
  130. package/dist/src/storage/migration-adapter.js +79 -0
  131. package/dist/src/storage/migration-copy.js +108 -0
  132. package/dist/src/storage/migration-protocol.js +14 -197
  133. package/dist/src/storage/migration-records.js +186 -0
  134. package/dist/src/storage/migration-types.js +12 -0
  135. package/dist/src/tracker/forge-http.js +2 -1
  136. package/dist/src/tracker/issue-pages.js +110 -0
  137. package/package.json +7 -1
  138. package/schemas/mission-v1.schema.json +335 -0
  139. package/schemas/models/model-catalog.v1.schema.json +19 -1
  140. package/schemas/models/model-config-compatibility.v1.schema.json +3 -2
  141. package/schemas/models/model-policy.v1.schema.json +1 -1
  142. package/tools/agents/providers/provider-paths-staging.mjs +35 -0
  143. package/tools/agents/providers/rule-binding-targets.mjs +146 -0
  144. package/tools/agents/providers/rule-delivery.mjs +7 -126
  145. package/tools/ralph-external/lib/muse-adapter.mjs +10 -0
  146. package/tools/ralph-external/lib/worker-context.mjs +237 -0
  147. package/tools/ralph-external/lib/worker-invocation-ancestry.mjs +132 -0
  148. package/tools/ralph-external/lib/worker-invocation-processes.mjs +123 -0
  149. package/tools/ralph-external/lib/worker-isolation-status.mjs +48 -0
  150. package/tools/ralph-external/lib/worker-isolation.mjs +17 -29
  151. package/tools/ralph-external/lib/worker-launch-cli.mjs +3 -1
  152. package/tools/ralph-external/lib/worker-overflow.mjs +48 -13
  153. package/tools/ralph-external/lib/worker-retry-evidence.mjs +103 -0
  154. package/tools/ralph-external/lib/worker-termination.mjs +82 -0
  155. package/tools/ralph-external/session-launcher.mjs +51 -96
  156. package/vscode-extension/schemas/aiwg.config.v1.json +177 -0
@@ -462,9 +462,120 @@
462
462
  ]
463
463
  },
464
464
  "workerBrief": {
465
+ "$defs": {
466
+ "regressionCheck": {
467
+ "type": "object",
468
+ "additionalProperties": false,
469
+ "properties": {
470
+ "kind": {
471
+ "enum": [
472
+ "command",
473
+ "path"
474
+ ]
475
+ },
476
+ "target": {
477
+ "type": "string",
478
+ "minLength": 1,
479
+ "maxLength": 1024
480
+ },
481
+ "expectedStatus": {
482
+ "enum": [
483
+ "passed",
484
+ "failed",
485
+ "present",
486
+ "absent"
487
+ ]
488
+ }
489
+ },
490
+ "required": [
491
+ "kind",
492
+ "target",
493
+ "expectedStatus"
494
+ ],
495
+ "allOf": [
496
+ {
497
+ "if": {
498
+ "properties": {
499
+ "kind": {
500
+ "const": "command"
501
+ }
502
+ }
503
+ },
504
+ "then": {
505
+ "properties": {
506
+ "expectedStatus": {
507
+ "enum": [
508
+ "passed",
509
+ "failed"
510
+ ]
511
+ }
512
+ }
513
+ },
514
+ "else": {
515
+ "properties": {
516
+ "expectedStatus": {
517
+ "enum": [
518
+ "present",
519
+ "absent"
520
+ ]
521
+ }
522
+ }
523
+ }
524
+ }
525
+ ]
526
+ },
527
+ "oracleCommand": {
528
+ "type": "object",
529
+ "additionalProperties": false,
530
+ "properties": {
531
+ "command": {
532
+ "type": "string",
533
+ "minLength": 1,
534
+ "maxLength": 1024
535
+ },
536
+ "expectedExitCode": {
537
+ "type": "integer",
538
+ "minimum": 0,
539
+ "maximum": 255
540
+ }
541
+ },
542
+ "required": [
543
+ "command",
544
+ "expectedExitCode"
545
+ ]
546
+ }
547
+ },
465
548
  "type": "object",
466
549
  "additionalProperties": false,
467
550
  "properties": {
551
+ "uncertaintyPolicy": {
552
+ "description": "Omitted or default follows the conductor policy; stop-and-report pauses uncertain work and reports the uncertainty.",
553
+ "enum": [
554
+ "default",
555
+ "stop-and-report"
556
+ ]
557
+ },
558
+ "mustNotRegress": {
559
+ "type": "array",
560
+ "maxItems": 64,
561
+ "items": {
562
+ "$ref": "#/$defs/workerBrief/$defs/regressionCheck"
563
+ }
564
+ },
565
+ "verificationOracle": {
566
+ "type": "array",
567
+ "maxItems": 64,
568
+ "items": {
569
+ "$ref": "#/$defs/workerBrief/$defs/oracleCommand"
570
+ },
571
+ "minItems": 1
572
+ },
573
+ "designReviewRequired": {
574
+ "type": "boolean"
575
+ },
576
+ "designReviewArtifact": {
577
+ "$ref": "#/$defs/workerArtifact"
578
+ },
468
579
  "version": {
469
580
  "const": 1
470
581
  },
@@ -1015,9 +1126,173 @@
1015
1126
  ]
1016
1127
  },
1017
1128
  "workerVerification": {
1129
+ "$defs": {
1130
+ "oracleResult": {
1131
+ "type": "object",
1132
+ "additionalProperties": false,
1133
+ "properties": {
1134
+ "command": {
1135
+ "type": "string",
1136
+ "minLength": 1,
1137
+ "maxLength": 1024
1138
+ },
1139
+ "exitCode": {
1140
+ "type": [
1141
+ "integer",
1142
+ "null"
1143
+ ],
1144
+ "minimum": 0,
1145
+ "maximum": 255
1146
+ },
1147
+ "evidence": {
1148
+ "$ref": "#/$defs/workerArtifact"
1149
+ }
1150
+ },
1151
+ "required": [
1152
+ "command",
1153
+ "exitCode",
1154
+ "evidence"
1155
+ ]
1156
+ },
1157
+ "reviewRound": {
1158
+ "type": "object",
1159
+ "additionalProperties": false,
1160
+ "properties": {
1161
+ "round": {
1162
+ "type": "integer",
1163
+ "minimum": 1,
1164
+ "maximum": 64
1165
+ },
1166
+ "headSha": {
1167
+ "type": "string",
1168
+ "pattern": "^(?:[a-f0-9]{40}|[a-f0-9]{64})$"
1169
+ },
1170
+ "reviewerObservationRef": {
1171
+ "type": "string",
1172
+ "minLength": 1,
1173
+ "maxLength": 1024
1174
+ },
1175
+ "artifact": {
1176
+ "$ref": "#/$defs/workerArtifact"
1177
+ }
1178
+ },
1179
+ "required": [
1180
+ "round",
1181
+ "headSha",
1182
+ "reviewerObservationRef",
1183
+ "artifact"
1184
+ ]
1185
+ },
1186
+ "finding": {
1187
+ "type": "object",
1188
+ "additionalProperties": false,
1189
+ "properties": {
1190
+ "id": {
1191
+ "type": "string",
1192
+ "minLength": 1,
1193
+ "maxLength": 1024
1194
+ },
1195
+ "class": {
1196
+ "enum": [
1197
+ "A",
1198
+ "B",
1199
+ "C"
1200
+ ]
1201
+ },
1202
+ "severity": {
1203
+ "enum": [
1204
+ "blocker",
1205
+ "major",
1206
+ "minor",
1207
+ "info"
1208
+ ]
1209
+ },
1210
+ "round": {
1211
+ "type": "integer",
1212
+ "minimum": 1,
1213
+ "maximum": 64
1214
+ },
1215
+ "status": {
1216
+ "enum": [
1217
+ "open",
1218
+ "resolved",
1219
+ "follow-up",
1220
+ "out-of-scope"
1221
+ ]
1222
+ },
1223
+ "summary": {
1224
+ "type": "string",
1225
+ "minLength": 1,
1226
+ "maxLength": 1024
1227
+ },
1228
+ "followUp": {
1229
+ "$ref": "#/$defs/workerArtifact"
1230
+ }
1231
+ },
1232
+ "required": [
1233
+ "id",
1234
+ "class",
1235
+ "severity",
1236
+ "round",
1237
+ "status",
1238
+ "summary"
1239
+ ],
1240
+ "allOf": [
1241
+ {
1242
+ "if": {
1243
+ "properties": {
1244
+ "class": {
1245
+ "const": "A"
1246
+ }
1247
+ }
1248
+ },
1249
+ "then": {
1250
+ "properties": {
1251
+ "status": {
1252
+ "enum": [
1253
+ "open",
1254
+ "resolved"
1255
+ ]
1256
+ }
1257
+ }
1258
+ }
1259
+ }
1260
+ ]
1261
+ }
1262
+ },
1018
1263
  "type": "object",
1019
1264
  "additionalProperties": false,
1020
1265
  "properties": {
1266
+ "headSha": {
1267
+ "type": "string",
1268
+ "pattern": "^(?:[a-f0-9]{40}|[a-f0-9]{64})$"
1269
+ },
1270
+ "reviewRounds": {
1271
+ "type": "array",
1272
+ "maxItems": 64,
1273
+ "items": {
1274
+ "$ref": "#/$defs/workerVerification/$defs/reviewRound"
1275
+ }
1276
+ },
1277
+ "findingsLedger": {
1278
+ "type": "array",
1279
+ "maxItems": 64,
1280
+ "items": {
1281
+ "$ref": "#/$defs/workerVerification/$defs/finding"
1282
+ }
1283
+ },
1284
+ "roundsToClean": {
1285
+ "type": "integer",
1286
+ "minimum": 1,
1287
+ "maximum": 64
1288
+ },
1289
+ "oracleResults": {
1290
+ "type": "array",
1291
+ "maxItems": 64,
1292
+ "items": {
1293
+ "$ref": "#/$defs/workerVerification/$defs/oracleResult"
1294
+ }
1295
+ },
1021
1296
  "status": {
1022
1297
  "enum": [
1023
1298
  "pending",
@@ -1104,6 +1379,7 @@
1104
1379
  "pattern": "^sha256:[a-f0-9]{64}$"
1105
1380
  },
1106
1381
  "evidence": {
1382
+ "type": "array",
1107
1383
  "minItems": 1
1108
1384
  }
1109
1385
  }
@@ -1538,6 +1814,34 @@
1538
1814
  "type": "object",
1539
1815
  "additionalProperties": false,
1540
1816
  "properties": {
1817
+ "uncertaintyPolicy": {
1818
+ "description": "Omitted or default follows the conductor policy; stop-and-report pauses uncertain work and reports the uncertainty.",
1819
+ "enum": [
1820
+ "default",
1821
+ "stop-and-report"
1822
+ ]
1823
+ },
1824
+ "mustNotRegress": {
1825
+ "type": "array",
1826
+ "maxItems": 64,
1827
+ "items": {
1828
+ "$ref": "#/$defs/workerBrief/$defs/regressionCheck"
1829
+ }
1830
+ },
1831
+ "verificationOracle": {
1832
+ "type": "array",
1833
+ "maxItems": 64,
1834
+ "items": {
1835
+ "$ref": "#/$defs/workerBrief/$defs/oracleCommand"
1836
+ },
1837
+ "minItems": 1
1838
+ },
1839
+ "designReviewRequired": {
1840
+ "type": "boolean"
1841
+ },
1842
+ "designReviewArtifact": {
1843
+ "$ref": "#/$defs/workerArtifact"
1844
+ },
1541
1845
  "version": {
1542
1846
  "const": 1
1543
1847
  },
@@ -1951,6 +2255,36 @@
1951
2255
  "type": "object",
1952
2256
  "additionalProperties": false,
1953
2257
  "properties": {
2258
+ "headSha": {
2259
+ "type": "string",
2260
+ "pattern": "^(?:[a-f0-9]{40}|[a-f0-9]{64})$"
2261
+ },
2262
+ "reviewRounds": {
2263
+ "type": "array",
2264
+ "maxItems": 64,
2265
+ "items": {
2266
+ "$ref": "#/$defs/workerVerification/$defs/reviewRound"
2267
+ }
2268
+ },
2269
+ "findingsLedger": {
2270
+ "type": "array",
2271
+ "maxItems": 64,
2272
+ "items": {
2273
+ "$ref": "#/$defs/workerVerification/$defs/finding"
2274
+ }
2275
+ },
2276
+ "roundsToClean": {
2277
+ "type": "integer",
2278
+ "minimum": 1,
2279
+ "maximum": 64
2280
+ },
2281
+ "oracleResults": {
2282
+ "type": "array",
2283
+ "maxItems": 64,
2284
+ "items": {
2285
+ "$ref": "#/$defs/workerVerification/$defs/oracleResult"
2286
+ }
2287
+ },
1954
2288
  "status": {
1955
2289
  "enum": [
1956
2290
  "pending",
@@ -2046,6 +2380,7 @@
2046
2380
  "maxLength": 1024
2047
2381
  },
2048
2382
  "findings": {
2383
+ "type": "array",
2049
2384
  "minItems": 1
2050
2385
  }
2051
2386
  }
@@ -24,6 +24,23 @@
24
24
  "efficiency": { "$ref": "#/$defs/model" }
25
25
  }
26
26
  },
27
+ "tiers": {
28
+ "type": "object", "additionalProperties": false,
29
+ "required": ["flagship", "premium", "standard", "economy"],
30
+ "properties": {
31
+ "flagship": {
32
+ "allOf": [
33
+ { "$ref": "#/$defs/model" },
34
+ { "type": "object", "required": ["selection"], "properties": { "selection": { "const": "user-elected" } } }
35
+ ]
36
+ },
37
+ "premium": { "$ref": "#/$defs/model" },
38
+ "standard": { "$ref": "#/$defs/model" },
39
+ "economy": { "$ref": "#/$defs/model" }
40
+ }
41
+ },
42
+ "verified_at": { "type": "string", "format": "date" },
43
+ "evidence": { "type": "string", "minLength": 1 },
27
44
  "sourceUrl": { "type": "string", "format": "uri" },
28
45
  "verifiedAt": { "type": "string", "format": "date" }
29
46
  }
@@ -61,7 +78,8 @@
61
78
  "id": { "type": "string", "minLength": 1 },
62
79
  "status": { "enum": ["active", "deprecated", "unverified"] },
63
80
  "fallback": { "type": "string", "minLength": 1 },
64
- "observed": { "type": "boolean" }
81
+ "observed": { "type": "boolean" },
82
+ "selection": { "const": "user-elected" }
65
83
  }
66
84
  },
67
85
  "workerObservation": {
@@ -137,7 +137,7 @@
137
137
  }
138
138
  }
139
139
  },
140
- "tier": { "enum": ["economy", "standard", "premium", "max-quality"] },
140
+ "tier": { "enum": ["economy", "standard", "premium", "flagship", "max-quality"] },
141
141
  "provider": {
142
142
  "enum": ["claude", "codex", "copilot", "cursor", "factory", "grokbot", "hermes", "muse", "opencode", "openclaw", "openhuman", "warp", "windsurf"]
143
143
  }
@@ -149,7 +149,7 @@
149
149
  "type": "object",
150
150
  "additionalProperties": false,
151
151
  "properties": {
152
- "model-tier": { "enum": ["economy", "standard", "premium", "max-quality"] },
152
+ "model-tier": { "enum": ["economy", "standard", "premium", "flagship", "max-quality"] },
153
153
  "model-override": { "type": "string", "minLength": 1 },
154
154
  "rationale": { "type": "string", "minLength": 1 }
155
155
  }
@@ -205,6 +205,7 @@
205
205
  "economy",
206
206
  "standard",
207
207
  "premium",
208
+ "flagship",
208
209
  "max-quality"
209
210
  ]
210
211
  },
@@ -7,7 +7,7 @@
7
7
  "required": ["role", "tier"],
8
8
  "properties": {
9
9
  "role": { "enum": ["efficiency", "coding", "reasoning"] },
10
- "tier": { "enum": ["economy", "standard", "premium"] },
10
+ "tier": { "enum": ["economy", "standard", "premium", "flagship", "max-quality"] },
11
11
  "effort": { "enum": ["minimal", "low", "medium", "high", "xhigh"] },
12
12
  "override": { "type": "string", "minLength": 1 }
13
13
  }
@@ -0,0 +1,35 @@
1
+ /** Stage and restore provider path overrides without writing through getter-only accessors. */
2
+ export function captureProviderPathDescriptors(provider) {
3
+ return Object.getOwnPropertyDescriptors(provider.paths);
4
+ }
5
+
6
+ export function setStagedProviderPath(provider, key, value) {
7
+ try {
8
+ Object.defineProperty(provider.paths, key, {
9
+ value,
10
+ writable: true,
11
+ enumerable: true,
12
+ configurable: true,
13
+ });
14
+ return;
15
+ } catch {
16
+ const descriptor = Object.getOwnPropertyDescriptor(provider.paths, key);
17
+ if (descriptor?.set || descriptor?.writable) provider.paths[key] = value;
18
+ else throw new Error(`Cannot stage provider path '${key}': accessor has no setter and cannot be redefined`);
19
+ }
20
+ }
21
+
22
+ export function restoreProviderPaths(provider, descriptors) {
23
+ for (const key of Object.keys(provider.paths)) {
24
+ if (!(key in descriptors)) {
25
+ try { delete provider.paths[key]; } catch { /* keep operator-owned key */ }
26
+ }
27
+ }
28
+ for (const [key, descriptor] of Object.entries(descriptors)) {
29
+ try {
30
+ Object.defineProperty(provider.paths, key, descriptor);
31
+ } catch {
32
+ if (descriptor.set || descriptor.writable) provider.paths[key] = descriptor.value;
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,146 @@
1
+ /** Discover and bind rule targets from indexed and currently deployed bundle sources. */
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { importImpl } from '../../_resolve-impl.mjs';
5
+ import { contentHash } from './base.mjs';
6
+ const { RULE_BINDING_TYPES } = await importImpl(import.meta.url, 'rules/activation.mjs');
7
+
8
+ function isPackageSource(directory, root) {
9
+ return path.relative(root, directory).split(path.sep).slice(0, 2).join('/') === 'agentic/code';
10
+ }
11
+
12
+ function bindingBundleRoot(file, root) {
13
+ // Packaged contracts retain their established project/user override policy.
14
+ if (isPackageSource(file, root)) return undefined;
15
+ let directory = path.dirname(file);
16
+ while (path.dirname(directory) !== directory) {
17
+ if (['rules', 'behaviors'].includes(path.basename(directory))) return path.dirname(directory);
18
+ directory = path.dirname(directory);
19
+ }
20
+ return undefined;
21
+ }
22
+
23
+ export async function resolveDeliveryRuleBindings(opts, rules, configs, root, packageRelations) {
24
+ const bindings = new Map();
25
+ const targets = [];
26
+ const targetKeys = new Set();
27
+ if (rules.some(rule => Object.values(rule.bound_to).some(ids => ids.length))) {
28
+ const { loadLocalCapabilityEntries, loadLocalOverrideCapabilityEntries, createRuleBindingTargetResolver } = await importImpl(import.meta.url, 'artifacts/query-engine.js');
29
+ // Framework graph paths are package-relative; project graph paths belong
30
+ // to the queried project. Normalize before merging so one source cannot
31
+ // become two apparently ambiguous targets after a source-index rebuild.
32
+ const indexEntries = new Map();
33
+ const entryPaths = new Map();
34
+ const loadEntries = (cwd, overridesOnly = false) => (overridesOnly
35
+ ? loadLocalOverrideCapabilityEntries(cwd)
36
+ : loadLocalCapabilityEntries(cwd, undefined, indexEntries)).map(entry => {
37
+ const anchor = entry.path.startsWith('agentic/code/') ? root : cwd;
38
+ const key = `${anchor}\0${entry.path}`;
39
+ if (!entryPaths.has(key)) entryPaths.set(key, path.resolve(anchor, entry.path));
40
+ const resolvedPath = entryPaths.get(key);
41
+ // Canonical IDs hash the indexed package-relative path. Keep it through
42
+ // resolution; the selected target is anchored to root below.
43
+ return { ...entry, path: entry.path.startsWith('agentic/code/') ? entry.path
44
+ : opts.mapInputPath ? opts.mapInputPath(resolvedPath) : resolvedPath };
45
+ });
46
+ let rebuilt = false;
47
+ const cacheDir = process.env.AIWG_RULE_BINDING_INDEX_CACHE;
48
+ const cacheFile = cacheDir && path.join(cacheDir, `${contentHash(opts.logicalInputPath ? opts.logicalInputPath(root) : root)}.json`);
49
+ const buildSourceEntries = async (refresh = false) => {
50
+ if (!refresh && cacheFile) {
51
+ try { return JSON.parse(fs.readFileSync(cacheFile, 'utf8')).map(entry => ({ ...entry, path: path.isAbsolute(entry.path) && opts.mapInputPath ? opts.mapInputPath(entry.path) : entry.path })); }
52
+ catch (error) {
53
+ if (error.code !== 'ENOENT' && !(error instanceof SyntaxError)) throw error;
54
+ }
55
+ }
56
+ const { collectRuleBindingEntries } = await importImpl(import.meta.url, 'artifacts/index-builder.js');
57
+ const sourceEntries = await collectRuleBindingEntries(root,
58
+ root === opts.srcRoot && !fs.existsSync(path.join(root, 'agentic')) ? '.' : 'agentic/code');
59
+ rebuilt = true;
60
+ const entries = sourceEntries.map(entry => ({ ...entry, path: entry.path.startsWith('agentic/code/')
61
+ ? entry.path : path.resolve(root, entry.path) }));
62
+ if (cacheFile) {
63
+ fs.mkdirSync(cacheDir, { recursive: true });
64
+ // Workers may publish the same immutable source snapshot concurrently.
65
+ const temporary = `${cacheFile}.${process.pid}.tmp`;
66
+ fs.writeFileSync(temporary, JSON.stringify(entries.map(entry => ({ ...entry, path: opts.logicalInputPath ? opts.logicalInputPath(entry.path) : entry.path }))));
67
+ fs.renameSync(temporary, cacheFile);
68
+ }
69
+ return entries;
70
+ };
71
+ const localEntries = opts.bindingEntries || loadEntries(opts.target, Boolean(packageRelations));
72
+ let entries = [...localEntries];
73
+ if (!opts.bindingEntries) {
74
+ // The validated package table is authoritative for its exact source digest.
75
+ // Keep the canonical resolver for aliases, local overrides and ambiguity.
76
+ const sourceEntries = packageRelations
77
+ ? Object.values(packageRelations.index.artifacts).map(entry => ({ ...entry,
78
+ indexScope: 'packaged', indexGraph: 'framework' }))
79
+ : loadEntries(root);
80
+ // A relocated project graph may also be visible while querying the
81
+ // package root. Keep its project-anchored instance only.
82
+ const uniqueSources = sourceEntries.filter(entry => !(opts.sharedProjectGraph &&
83
+ entry.path.startsWith(path.join(root, '.aiwg') + path.sep) &&
84
+ localEntries.some(local => local.type === entry.type && local.name === entry.name)));
85
+ entries.push(...uniqueSources);
86
+ if (!sourceEntries.length) entries.push(...await buildSourceEntries());
87
+ }
88
+ // Include first-time invocations before their installed entry is persisted.
89
+ // Scan only selected bundle roots; use the existing metadata extractor without
90
+ // creating a full index or treating a stale project index as authoritative.
91
+ if (!opts.bindingEntries) {
92
+ const selectedRoots = new Set([opts.srcRoot, ...(opts.additionalSources || []),
93
+ ...rules.map(rule => bindingBundleRoot(rule.file, root)).filter(Boolean),
94
+ ...Object.values(configs.project.installed || {}).filter(entry => entry.localPath)
95
+ .map(entry => path.resolve(opts.target, entry.localPath))]);
96
+ const { collectRuleBindingEntries } = await importImpl(import.meta.url, 'artifacts/index-builder.js');
97
+ for (const localRoot of selectedRoots) {
98
+ if (localRoot === root || isPackageSource(localRoot, root) || !fs.existsSync(localRoot)) continue;
99
+ const scoped = (await collectRuleBindingEntries(localRoot, '.'))
100
+ .map(entry => ({ ...entry, path: path.resolve(localRoot, entry.path) }));
101
+ localEntries.push(...scoped);
102
+ entries.push(...scoped);
103
+ }
104
+ }
105
+ // A stored index can predate the source tree (edge/dev checkouts). Rebuild once from source
106
+ // before reporting a binding target as missing.
107
+ const resolvedTargets = new Map();
108
+ const identityOptions = { cwd: opts.target, packageRoot: root, logicalPath: opts.logicalInputPath };
109
+ let resolveBinding = createRuleBindingTargetResolver(entries, identityOptions);
110
+ const resolveTarget = async (type, id, bundleRoot) => {
111
+ const key = `${bundleRoot}:${type}:${id}`;
112
+ if (resolvedTargets.has(key)) return resolvedTargets.get(key);
113
+ let target;
114
+ try { target = resolveBinding(type, id, bundleRoot); }
115
+ catch (error) {
116
+ if (packageRelations || rebuilt || opts.bindingEntries || !/^Missing /.test(error.message)) throw error;
117
+ indexEntries.clear();
118
+ entryPaths.clear();
119
+ entries = [...localEntries, ...await buildSourceEntries(true)];
120
+ rebuilt = true;
121
+ resolveBinding = createRuleBindingTargetResolver(entries, identityOptions);
122
+ target = resolveBinding(type, id, bundleRoot);
123
+ // A rebuild replaces the input set for every lookup.
124
+ resolvedTargets.clear();
125
+ }
126
+ resolvedTargets.set(key, target);
127
+ return target;
128
+ };
129
+ for (const rule of rules.filter(rule => rule.tagged)) {
130
+ for (const [key, type] of Object.entries(RULE_BINDING_TYPES)) {
131
+ for (const id of rule.bound_to[key]) {
132
+ const target = await resolveTarget(type, id, bindingBundleRoot(rule.file, root));
133
+ const source = path.isAbsolute(target.path) ? target.path : path.resolve(target.path.startsWith('agentic/code/') ? root : opts.target, target.path);
134
+ if (!fs.existsSync(source)) throw new Error(`${rule.file}: binding target content missing: ${source}`);
135
+ bindings.set(source, [...(bindings.get(source) || []), rule]);
136
+ const key = `${target.type}:${source}`;
137
+ if (!targetKeys.has(key)) {
138
+ targetKeys.add(key);
139
+ targets.push({ ...target, source });
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ return { bindings, targets };
146
+ }