@lesliechan721/aw 0.1.0-beta.69 → 0.1.0-beta.72

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 (121) hide show
  1. package/dist/authoring/assets/aw-config.mjs +1 -1
  2. package/dist/authoring/assets/aw-config.mjs.map +1 -1
  3. package/dist/authoring/assets/aw-runtime-config.mjs +1 -1
  4. package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -1
  5. package/dist/authoring/scripts/add-skill.mjs +8 -8
  6. package/dist/authoring/scripts/add-skill.mjs.map +1 -1
  7. package/dist/authoring/scripts/init-plugin.mjs +8 -8
  8. package/dist/authoring/scripts/init-plugin.mjs.map +1 -1
  9. package/dist/authoring/scripts/lib/skill-scaffold.mjs +2 -2
  10. package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
  11. package/dist/authoring/scripts/validate-plugin.mjs +2 -2
  12. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  13. package/dist/authoring/scripts/validate-skill.mjs +1 -1
  14. package/dist/src/authoring/workspace-commands.d.ts +1 -0
  15. package/dist/src/authoring/workspace-commands.js +4 -1
  16. package/dist/src/authoring/workspace-commands.js.map +1 -1
  17. package/dist/src/commands/aw-capabilities.d.ts +1 -1
  18. package/dist/src/commands/aw-capabilities.js +14 -13
  19. package/dist/src/commands/aw-capabilities.js.map +1 -1
  20. package/dist/src/commands/catalog-dev-source.d.ts +3 -0
  21. package/dist/src/commands/catalog-dev-source.js +78 -8
  22. package/dist/src/commands/catalog-dev-source.js.map +1 -1
  23. package/dist/src/commands/catalog-publish.d.ts +16 -0
  24. package/dist/src/commands/catalog-publish.js +127 -90
  25. package/dist/src/commands/catalog-publish.js.map +1 -1
  26. package/dist/src/commands/catalog-source.d.ts +4 -0
  27. package/dist/src/commands/catalog-source.js +24 -8
  28. package/dist/src/commands/catalog-source.js.map +1 -1
  29. package/dist/src/commands/catalog-status.js +2 -2
  30. package/dist/src/commands/catalog-status.js.map +1 -1
  31. package/dist/src/commands/catalog-workspace-resolution.d.ts +4 -0
  32. package/dist/src/commands/catalog-workspace-resolution.js +18 -3
  33. package/dist/src/commands/catalog-workspace-resolution.js.map +1 -1
  34. package/dist/src/commands/console.js +1 -1
  35. package/dist/src/commands/console.js.map +1 -1
  36. package/dist/src/commands/init.js +1 -1
  37. package/dist/src/commands/init.js.map +1 -1
  38. package/dist/src/commands/intent-command.d.ts +2 -0
  39. package/dist/src/commands/intent-command.js +8 -1
  40. package/dist/src/commands/intent-command.js.map +1 -1
  41. package/dist/src/commands/managed-commands.d.ts +8 -1
  42. package/dist/src/commands/managed-commands.js +52 -8
  43. package/dist/src/commands/managed-commands.js.map +1 -1
  44. package/dist/src/commands/public-config-confirmation.d.ts +8 -0
  45. package/dist/src/commands/public-config-confirmation.js +56 -0
  46. package/dist/src/commands/public-config-confirmation.js.map +1 -0
  47. package/dist/src/commands/public-interruption.d.ts +9 -0
  48. package/dist/src/commands/public-interruption.js +23 -0
  49. package/dist/src/commands/public-interruption.js.map +1 -0
  50. package/dist/src/commands/public-lifecycle-result.d.ts +53 -0
  51. package/dist/src/commands/public-lifecycle-result.js +102 -0
  52. package/dist/src/commands/public-lifecycle-result.js.map +1 -0
  53. package/dist/src/commands/public-lifecycle.d.ts +26 -0
  54. package/dist/src/commands/public-lifecycle.js +469 -0
  55. package/dist/src/commands/public-lifecycle.js.map +1 -0
  56. package/dist/src/commands/public-plugin-query.d.ts +15 -0
  57. package/dist/src/commands/public-plugin-query.js +154 -0
  58. package/dist/src/commands/public-plugin-query.js.map +1 -0
  59. package/dist/src/commands/rebuild-command.js +4 -2
  60. package/dist/src/commands/rebuild-command.js.map +1 -1
  61. package/dist/src/commands/rebuild-integration.d.ts +1 -0
  62. package/dist/src/commands/rebuild-integration.js.map +1 -1
  63. package/dist/src/commands/runtime.d.ts +4 -0
  64. package/dist/src/commands/runtime.js +16 -2
  65. package/dist/src/commands/runtime.js.map +1 -1
  66. package/dist/src/commands/status-v6.js +2 -2
  67. package/dist/src/commands/status-v6.js.map +1 -1
  68. package/dist/src/commands/targets-command.d.ts +2 -0
  69. package/dist/src/commands/targets-command.js +55 -1
  70. package/dist/src/commands/targets-command.js.map +1 -1
  71. package/dist/src/commands/write-commands.js +1 -1
  72. package/dist/src/commands/write-commands.js.map +1 -1
  73. package/dist/src/index.js +664 -761
  74. package/dist/src/index.js.map +1 -1
  75. package/dist/src/intent/diagnostics.js +2 -2
  76. package/dist/src/intent/diagnostics.js.map +1 -1
  77. package/dist/src/output/command-receipt.js +1 -1
  78. package/dist/src/output/command-receipt.js.map +1 -1
  79. package/dist/src/output/public-result.d.ts +43 -0
  80. package/dist/src/output/public-result.js +139 -0
  81. package/dist/src/output/public-result.js.map +1 -0
  82. package/dist/src/output/receipt-projection.d.ts +7 -0
  83. package/dist/src/output/receipt-projection.js +575 -0
  84. package/dist/src/output/receipt-projection.js.map +1 -0
  85. package/dist/src/recovery/coordinator.d.ts +4 -0
  86. package/dist/src/recovery/coordinator.js +7 -7
  87. package/dist/src/recovery/coordinator.js.map +1 -1
  88. package/dist/src/recovery/joint-coordinator.js +19 -6
  89. package/dist/src/recovery/joint-coordinator.js.map +1 -1
  90. package/dist/src/recovery/retirement.d.ts +2 -0
  91. package/dist/src/recovery/retirement.js +9 -8
  92. package/dist/src/recovery/retirement.js.map +1 -1
  93. package/dist/src/review/review-selection.js +4 -1
  94. package/dist/src/review/review-selection.js.map +1 -1
  95. package/dist/src/review/review-types.d.ts +1 -1
  96. package/dist/src/review/review-types.js.map +1 -1
  97. package/dist/src/review/source-binding.js +2 -2
  98. package/dist/src/review/source-binding.js.map +1 -1
  99. package/dist/src/tui/catalog-generation.js +1 -1
  100. package/dist/src/tui/catalog-generation.js.map +1 -1
  101. package/dist/src/tui/model.js +1 -1
  102. package/dist/src/tui/model.js.map +1 -1
  103. package/dist/src/tui/operation-review-planner.js +3 -2
  104. package/dist/src/tui/operation-review-planner.js.map +1 -1
  105. package/dist/src/utils/catalog-generation-resolver.js +3 -3
  106. package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
  107. package/dist/src/utils/catalog-generation-service.d.ts +12 -1
  108. package/dist/src/utils/catalog-generation-service.js +10 -0
  109. package/dist/src/utils/catalog-generation-service.js.map +1 -1
  110. package/dist/src/utils/catalog-generation-state.js +1 -1
  111. package/dist/src/utils/catalog-generation-state.js.map +1 -1
  112. package/dist/src/utils/catalog-generation-store.js +1 -1
  113. package/dist/src/utils/catalog-generation-store.js.map +1 -1
  114. package/dist/src/utils/catalog-operation-context.js +1 -1
  115. package/dist/src/utils/catalog-operation-context.js.map +1 -1
  116. package/dist/src/utils/catalog-sources.js +2 -2
  117. package/dist/src/utils/catalog-sources.js.map +1 -1
  118. package/dist/src/utils/plugin-scripts.d.ts +1 -1
  119. package/dist/src/utils/plugin-scripts.js +29 -7
  120. package/dist/src/utils/plugin-scripts.js.map +1 -1
  121. package/package.json +3 -3
@@ -0,0 +1,575 @@
1
+ import { projectTarget } from '../commands/public-lifecycle-result.js';
2
+ import { commandResult, safePublicMessage } from './public-result.js';
3
+ /** Pick only the declared domain DTO members. Never spread a service result. */
4
+ function pick(value, keys) {
5
+ return Object.fromEntries(keys.filter((key) => Object.hasOwn(value, key)).map((key) => [key, value[key]]));
6
+ }
7
+ function record(value) { return value && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Error) ? value : {}; }
8
+ function list(value) { return Array.isArray(value) ? value.map(record) : []; }
9
+ function mapField(data, key, project) {
10
+ if (Array.isArray(data[key]))
11
+ data[key] = list(data[key]).map(project);
12
+ else if (data[key] !== undefined && data[key] !== null)
13
+ data[key] = project(record(data[key]));
14
+ }
15
+ function message(value, code, publicRoots = []) {
16
+ // Legacy domain messages can contain translated text, exception paths, or script output.
17
+ // Their stable codes remain usable; only safe English messages cross this boundary.
18
+ const text = typeof value === 'string' ? value : '';
19
+ if (!text || /[\u3400-\u9fff]/u.test(text))
20
+ return `The operation reported ${code}.`;
21
+ return safePublicMessage(text.replace(/\n\s*at\s[\s\S]*/u, '')
22
+ .replace(/(^|[\s"'`(])((?:\/[^\s"'`),;]+|[A-Za-z]:\\[^\s"'`),;]+))/gu, (_match, prefix, location) => `${prefix}${!location.split(/[\\/]/u).includes('..') && publicRoots.some((root) => location === root || location.startsWith(`${root}/`) || location.startsWith(`${root}\\`)) ? location : '<path>'}`), code);
23
+ }
24
+ function diagnostic(value, severity = 'error', subject, publicRoots = []) {
25
+ const entry = typeof value === 'string' ? { message: value } : record(value);
26
+ const code = typeof entry.code === 'string' ? entry.code : severity === 'warning' ? 'commandWarning' : 'commandFailed';
27
+ const identity = { ...subject, ...pick(entry, ['pluginId', 'sourceId', 'scope', 'field']),
28
+ ...(typeof entry.plugin === 'string' ? { pluginId: entry.plugin } : {}) };
29
+ return { code, severity: entry.blocking === false || entry.severity === 'warning' ? 'warning' : severity,
30
+ message: message(entry.message, code, publicRoots), ...(Object.keys(identity).length ? { subject: identity } : {}) };
31
+ }
32
+ function issue(value) {
33
+ return { ...pick(value, ['code', 'path', 'blocking', 'stage', 'severity']), ...(typeof value.subject === 'string' ? { subject: value.subject } : {}), message: message(value.message, String(value.code ?? 'commandFailed')) };
34
+ }
35
+ function configIssue(value) {
36
+ return { ...pick(value, ['type', 'code', 'key', 'source', 'path']), message: message(value.message, String(value.code ?? 'configInvalid')) };
37
+ }
38
+ function configField(value) {
39
+ const data = pick(value, ['key', 'title', 'kind', 'reserved', 'writable', 'canSet', 'canUnset', 'valueState', 'effectiveValue', 'sourceLayer', 'storedValue', 'storedSourceLayer', 'invalidOverride', 'fallback', 'value', 'source', 'matchedPreset', 'valid', 'issues']);
40
+ mapField(data, 'issues', configIssue);
41
+ for (const key of ['invalidOverride', 'fallback'])
42
+ mapField(data, key, (entry) => {
43
+ const result = pick(entry, ['state', 'sourceLayer', 'effectiveValue', 'issues']);
44
+ mapField(result, 'issues', configIssue);
45
+ return result;
46
+ });
47
+ return data;
48
+ }
49
+ function configDefinition(value) {
50
+ const data = pick(value, ['type', 'title', 'description', 'default', 'required', 'sensitive', 'const', 'valueRef', 'choices', 'validation', 'properties', 'additionalProperties', 'variants', 'items']);
51
+ mapField(data, 'valueRef', (entry) => pick(entry, ['plugin', 'field', 'key', 'label', 'include']));
52
+ mapField(data, 'choices', (entry) => ({ allowCustom: entry.allowCustom, presets: list(entry.presets).map((preset) => pick(preset, ['id', 'title', 'description', 'value', 'recommended'])) }));
53
+ mapField(data, 'validation', (entry) => {
54
+ const validation = pick(entry, ['minLength', 'maxLength', 'pattern', 'format', 'integer', 'minimum', 'maximum', 'multipleOf', 'minProperties', 'maxProperties', 'key', 'minItems', 'maxItems', 'uniqueItems', 'uniqueBy']);
55
+ mapField(validation, 'key', (key) => pick(key, ['minLength', 'maxLength', 'pattern', 'format']));
56
+ return validation;
57
+ });
58
+ if (data.properties)
59
+ data.properties = Object.fromEntries(Object.entries(record(data.properties)).map(([key, field]) => [key, configDefinition(record(field))]));
60
+ if (data.additionalProperties && typeof data.additionalProperties === 'object')
61
+ data.additionalProperties = configDefinition(record(data.additionalProperties));
62
+ if (data.items)
63
+ data.items = configDefinition(record(data.items));
64
+ mapField(data, 'variants', (entry) => {
65
+ const variant = (value) => ({ properties: Object.fromEntries(Object.entries(record(record(value).properties)).map(([key, field]) => [key, configDefinition(record(field))])) });
66
+ return { ...pick(entry, ['discriminator', 'missing']), cases: Object.fromEntries(Object.entries(record(entry.cases)).map(([key, value]) => [key, variant(value)])), ...(entry.otherwise ? { otherwise: variant(entry.otherwise) } : {}) };
67
+ });
68
+ return data;
69
+ }
70
+ function nativeClosure(value) {
71
+ return { reader: value.reader, definitions: list(value.definitions).map((entry) => pick(entry, ['key', 'protocol'])), consumers: list(value.consumers).map((entry) => ({ ...pick(entry, ['kind', 'key']), tools: list(entry.tools).map((tool) => pick(tool, ['key', 'platforms', 'policy', 'fallback'])) })) };
72
+ }
73
+ function nativeChange(value) {
74
+ return { producer: producer(record(value.producer)), before: value.before === null ? null : nativeClosure(record(value.before)), after: value.after === null ? null : nativeClosure(record(value.after)) };
75
+ }
76
+ function versionCheck(value) {
77
+ const data = pick(value, ['plugin', 'ok', 'status', 'baseVersion', 'currentVersion', 'baseTarget', 'currentTarget', 'productionChanged', 'baseDigest', 'currentDigest', 'changedPaths', 'warnings', 'errors']);
78
+ for (const key of ['warnings', 'errors'])
79
+ if (Array.isArray(data[key]))
80
+ data[key] = data[key].map((entry) => typeof entry === 'string' ? message(entry, 'pluginVersionCheck') : issue(record(entry)));
81
+ return data;
82
+ }
83
+ function versionReport(value) {
84
+ const data = pick(value, ['schemaVersion', 'policy', 'ok', 'base', 'requestedBase', 'baseCommit', 'checkedPlugins', 'checks']);
85
+ mapField(data, 'base', (entry) => pick(entry, ['requested', 'commit']));
86
+ mapField(data, 'checks', versionCheck);
87
+ return data;
88
+ }
89
+ function producer(value) {
90
+ return pick(value, ['sourceId', 'sourceIdentity', 'pluginName', 'kind', 'key', 'scope', 'projectRoot', 'platform']);
91
+ }
92
+ function commandResults(values, diagnostics) {
93
+ return values?.map((entry) => {
94
+ const subject = { pluginId: `${entry.producer.sourceId}/${entry.producer.pluginName}`, scope: entry.producer.scope };
95
+ diagnostics.push(...entry.errors.map((error) => diagnostic(error, 'error', subject)));
96
+ return { ...pick(entry, ['state', 'commandIds', 'removedCommandIds']), producer: producer(record(entry.producer)), errors: entry.errors.map((error) => issue(record(error))), blockerCodes: entry.errors.map((error) => error.code) };
97
+ });
98
+ }
99
+ function applyResult(value, diagnostics) {
100
+ const data = pick(value, ['state', 'reason']);
101
+ data.targetResults = value.targetResults.map((entry) => {
102
+ const subject = { pluginId: entry.target.pluginId ?? entry.target.pluginName, target: entry.target.platform, scope: entry.target.scope };
103
+ if (entry.errorCode)
104
+ diagnostics.push(diagnostic({ code: entry.errorCode, message: entry.message }, 'error', subject));
105
+ return { ...pick(entry, ['action', 'state', 'relation', 'requiredBy', 'errorCode']), ...(entry.message ? { message: message(entry.message, entry.errorCode ?? 'configApplyFailed') } : {}), target: pick(entry.target, ['pluginName', 'pluginId', 'platform', 'scope']),
106
+ ...(entry.errorCode ? { blockerCodes: [entry.errorCode] } : {}) };
107
+ });
108
+ if ('error' in value && value.error) {
109
+ data.error = issue(record(value.error));
110
+ diagnostics.push(diagnostic(value.error));
111
+ }
112
+ if ('errors' in value && value.errors) {
113
+ data.errors = value.errors.map((entry) => issue(record(entry)));
114
+ diagnostics.push(...value.errors.map((entry) => diagnostic(entry)));
115
+ }
116
+ if (value.commandResults)
117
+ data.commandResults = commandResults(value.commandResults, diagnostics);
118
+ return data;
119
+ }
120
+ function sourceImpact(value) {
121
+ const data = pick(value, ['impactSchemaVersion', 'inventorySchemaVersion', 'sourceId', 'inventoryComplete', 'primaryChange', 'references', 'affectedReferences', 'changes', 'errors']);
122
+ mapField(data, 'primaryChange', (entry) => pick(entry, ['fromSourceId', 'toSourceId']));
123
+ for (const key of ['references', 'affectedReferences'])
124
+ mapField(data, key, (entry) => pick(entry, ['category', 'sourceId', 'pluginId', 'platform', 'scope', 'projectRecord', 'marketplaceName']));
125
+ mapField(data, 'changes', (entry) => {
126
+ const changes = pick(entry, ['added', 'removed', 'changed', 'newlyIncompatible', 'dependencyChanged', 'platformSupportChanged']);
127
+ mapField(changes, 'platformSupportChanged', (change) => pick(change, ['pluginId', 'removedPlatforms', 'addedPlatforms']));
128
+ return changes;
129
+ });
130
+ mapField(data, 'errors', (entry) => ({ ...pick(entry, ['code', 'kind']), ...(entry.relevance ? { relevance: pick(record(entry.relevance), ['global', 'sourceId', 'pluginName', 'platform', 'scope']) } : {}) }));
131
+ return data;
132
+ }
133
+ function active(value) { return pick(value, ['sourceConfigFingerprint', 'sourceIdentity', 'requestedRef', 'resolvedCommit', 'logicalIdentity', 'manifestDigest', 'snapshotDigest', 'activatedAt']); }
134
+ function resolution(value) { return pick(value, ['sourceIdentity', 'logicalIdentity', 'catalogVersion', 'channel', 'requestedRef', 'resolvedCommit', 'manifestDigest', 'snapshotDigest']); }
135
+ function compatibility(value) { return pick(value, ['state', 'requiredCapabilities', 'missingCapabilities']); }
136
+ function sourceEntry(value) {
137
+ const data = pick(value, ['sourceId', 'configuredSourceIdentity', 'active', 'activeReady', 'configMatchesActive', 'catalogVersion', 'channel', 'storeKey', 'lastSync', 'compatibility', 'errorCode']);
138
+ if (value.configuration) {
139
+ const configuration = pick(record(value.configuration), ['id', 'type', 'url', 'path', 'refPolicy', 'subdir', 'primary', 'autoCheck', 'sourceIdentity', 'managedBy']);
140
+ mapField(configuration, 'refPolicy', (entry) => pick(entry, ['type', 'ref']));
141
+ mapField(configuration, 'managedBy', (entry) => pick(entry, ['kind', 'workspaceIdentity']));
142
+ data.configuration = configuration;
143
+ }
144
+ mapField(data, 'active', active);
145
+ mapField(data, 'lastSync', (entry) => pick(entry, ['syncedAt', 'mode', 'state', 'resolvedCommit', 'errorCode']));
146
+ mapField(data, 'compatibility', compatibility);
147
+ return data;
148
+ }
149
+ function reviewSkills(value) {
150
+ return { ...pick(value, ['skill', 'sourcePath', 'finalPath', 'digest', 'state', 'evidencePath']), profile: pick(record(value.profile), ['platform', 'scope', 'inputDigest']) };
151
+ }
152
+ function requirementsObservations(value) { return { ...pick(value, ['code', 'blocking', 'path', 'provenance', 'command', 'capability']), message: message(value.message, String(value.code)) }; }
153
+ const writeCommands = new Set(['source.add', 'source.update', 'source.remove', 'source.sync', 'cache.prune', 'target.set', 'target.exclude', 'target.include',
154
+ 'plugin.config.set', 'plugin.config.unset', 'plugin.config.reset', 'plugin.config.apply', 'command.install', 'command.update', 'command.remove', 'command.package.sync', 'command.package.remove',
155
+ 'dev.source.activate', 'dev.source.deactivate', 'dev.plugin.create', 'dev.plugin.remove', 'dev.plugin.build', 'dev.skill.create', 'dev.skill.export', 'dev.catalog.create', 'dev.catalog.version',
156
+ 'dev.catalog.build', 'dev.catalog.publish.plan', 'dev.catalog.publish.apply', 'dev.review.prepare', 'dev.eval.prepare', 'dev.plugin.requirements']);
157
+ export function isPublicWrite(command) { return writeCommands.has(command); }
158
+ function projectData(command, r, diagnostics) {
159
+ switch (command) {
160
+ case 'self.describe': return pick(r, ['awVersion', 'coreVersion', 'capabilities', 'capabilitySetDigest']);
161
+ case 'self.check': {
162
+ const data = pick(r, ['awVersion', 'coreVersion', 'source', 'plugin', 'requiredCapabilities', 'capabilitySetDigest', 'missingCapabilities', 'observations']);
163
+ mapField(data, 'source', (entry) => pick(entry, ['kind', 'path']));
164
+ mapField(data, 'plugin', (entry) => pick(entry, ['name', 'version']));
165
+ mapField(data, 'observations', requirementsObservations);
166
+ return data;
167
+ }
168
+ case 'dev.plugin.requirements': {
169
+ const data = pick(r, ['plugin', 'pluginDirectory', 'workspaceRoot', 'workspaceRootResolvedFrom', 'mutation', 'declared', 'derived', 'detected', 'effective', 'capabilitySetDigest', 'unsupportedByCurrentAw', 'observations']);
170
+ mapField(data, 'plugin', (entry) => pick(entry, ['name', 'version']));
171
+ mapField(data, 'mutation', (entry) => pick(entry, ['action', 'capability', 'changed']));
172
+ mapField(data, 'observations', requirementsObservations);
173
+ return data;
174
+ }
175
+ case 'dev.plugin.capabilities': {
176
+ const data = pick(r, ['awVersion', 'coreVersion', 'surface']);
177
+ if (r.capabilities)
178
+ data.capabilities = Object.fromEntries(Object.entries(record(r.capabilities)).map(([surface, entries]) => [surface,
179
+ list(entries).map((entry) => pick(entry, ['field', 'type', 'required', 'acceptedValues', 'owner', 'provenance', 'requires', 'conflicts', 'profiles']))]));
180
+ return data;
181
+ }
182
+ case 'source.status': {
183
+ const data = pick(r, ['primarySourceId', 'sources', 'remote', 'complete']);
184
+ mapField(data, 'sources', sourceEntry);
185
+ mapField(data, 'remote', (entry) => {
186
+ const remote = pick(entry, ['sourceId', 'checked', 'candidate', 'outcome']);
187
+ mapField(remote, 'candidate', resolution);
188
+ if (entry.error)
189
+ diagnostics.push(diagnostic(entry.error, 'error', { sourceId: String(entry.sourceId) }));
190
+ return remote;
191
+ });
192
+ for (const entry of list(r.sources))
193
+ if (entry.errorCode)
194
+ diagnostics.push(diagnostic({ code: entry.errorCode }, 'error', { sourceId: String(entry.sourceId) }));
195
+ return data;
196
+ }
197
+ case 'source.add':
198
+ case 'source.update':
199
+ case 'source.remove': {
200
+ const data = pick(r, ['sourceId', 'changed', 'primarySourceId', 'configDigest', 'primaryChange', 'references']);
201
+ mapField(data, 'primaryChange', (entry) => pick(entry, ['fromSourceId', 'toSourceId']));
202
+ mapField(data, 'references', (entry) => pick(entry, ['category', 'sourceId', 'pluginId', 'platform', 'scope', 'projectRecord', 'marketplaceName']));
203
+ if (r.impact)
204
+ data.impact = sourceImpact(record(r.impact));
205
+ return data;
206
+ }
207
+ case 'source.sync': {
208
+ const data = pick(r, ['sourceId', 'mode', 'outcome', 'activeChanged', 'resolution', 'active', 'lastSync', 'impact']);
209
+ mapField(data, 'resolution', resolution);
210
+ mapField(data, 'active', active);
211
+ mapField(data, 'impact', sourceImpact);
212
+ mapField(data, 'lastSync', (entry) => pick(entry, ['syncedAt', 'mode', 'state', 'resolvedCommit', 'errorCode']));
213
+ return data;
214
+ }
215
+ case 'cache.status':
216
+ case 'cache.prune': {
217
+ const data = command === 'cache.status'
218
+ ? pick(r, ['entries', 'totals'])
219
+ : { ...pick(r, ['dryRun', 'entries', 'deleted', 'retained', 'reclaimableBytes', 'deletedBytes']), preview: r.dryRun === true };
220
+ mapField(data, 'entries', (entry) => pick(entry, ['storeKey', 'category', 'status', 'generationReference', 'ageMs', 'reclaimableBytes', 'reason']));
221
+ mapField(data, 'totals', (entry) => pick(entry, ['entries', 'reclaimableEntries', 'reclaimableBytes']));
222
+ mapField(data, 'deleted', (entry) => pick(entry, ['storeKey', 'bytes']));
223
+ mapField(data, 'retained', (entry) => pick(entry, ['storeKey', 'reason']));
224
+ return data;
225
+ }
226
+ case 'target.list':
227
+ case 'target.set':
228
+ case 'target.exclude':
229
+ case 'target.include': {
230
+ // Recovery's backend member includes live execution details and is intentionally not projected.
231
+ const recovery = r;
232
+ const data = pick(r, ['scope', 'policy', 'preferencesChanged', 'allSatisfied', 'inSync', 'outputsMayHaveChanged']);
233
+ if (r.policy)
234
+ data.policy = pick(record(r.policy), ['schemaVersion', 'targets', 'exclusions']);
235
+ if (r.selection)
236
+ data.selection = { targets: record(r.selection).agents, ...pick(record(r.selection), ['origin', 'preferences']) };
237
+ if (r.intent)
238
+ data.requirements = pick(record(r.intent), ['state', 'digest', 'roots']);
239
+ if (recovery.targetResults)
240
+ data.targetResults = recovery.targetResults.map((entry) => {
241
+ diagnostics.push(...entry.blockers.map((error) => diagnostic(error, 'error', { pluginId: entry.pluginId, target: entry.agent, scope: entry.scope })));
242
+ return projectTarget(entry);
243
+ });
244
+ if (recovery.remainingTargets)
245
+ data.remainingTargets = recovery.remainingTargets.map((entry) => ({ pluginId: entry.pluginId, target: entry.agent, scope: entry.scope }));
246
+ if (recovery.requestedTargets)
247
+ data.requestedTargets = recovery.requestedTargets.map((entry) => ({ pluginId: entry.pluginId, target: entry.agent, scope: entry.scope, delivery: entry.delivery }));
248
+ if (recovery.coverage)
249
+ data.coverage = { scopes: recovery.coverage.scopes, currentProject: recovery.coverage.scopes.includes('project'), otherProjects: 'unobserved' };
250
+ if (recovery.commandResults)
251
+ data.commandResults = commandResults(recovery.commandResults, diagnostics);
252
+ if (recovery.nativeToolChanges)
253
+ data.nativeToolChanges = recovery.nativeToolChanges.map((entry) => nativeChange(record(entry)));
254
+ if (r.apply)
255
+ data.apply = projectData(command, record(r.apply), diagnostics);
256
+ return data;
257
+ }
258
+ case 'plugin.config.schema':
259
+ case 'plugin.config.get':
260
+ case 'plugin.config.set':
261
+ case 'plugin.config.unset':
262
+ case 'plugin.config.reset':
263
+ case 'plugin.config.apply': {
264
+ const data = pick(r, ['configSchemaVersion', 'plugin', 'pluginName', 'pluginId', 'sourceId', 'sourceIdentity', 'scope', 'platform', 'schema', 'fields', 'key', 'configWrite', 'affectedFields', 'removedKey', 'existed', 'deleted', 'resetDisposition', 'quarantineBasename', 'updatedKeys', 'removedKeys', 'effective', 'otherProjectsMayRequireSync', 'staleRemovedKeys']);
265
+ if (typeof r.context === 'string')
266
+ data.context = r.context;
267
+ else if (r.context)
268
+ data.context = pick(record(r.context), ['context', 'projectRoot']);
269
+ if (r.apply)
270
+ data.apply = applyResult(r.apply, diagnostics);
271
+ mapField(data, 'schema', (entry) => pick(entry, ['source', 'platform', 'identity', 'pluginVersion', 'manifestDigest']));
272
+ if (command === 'plugin.config.schema' && data.fields)
273
+ data.fields = Object.fromEntries(Object.entries(record(data.fields)).map(([key, value]) => [key, configDefinition(record(value))]));
274
+ else
275
+ mapField(data, 'fields', configField);
276
+ for (const field of list(r.fields))
277
+ for (const entry of list(field.issues)) {
278
+ diagnostics.push(diagnostic({ ...entry, code: entry.code ?? entry.type ?? 'configInvalid' }, 'error', {
279
+ ...(typeof r.pluginId === 'string' ? { pluginId: r.pluginId } : {}), field: String(field.key),
280
+ }));
281
+ }
282
+ for (const entry of list(record(r.effective).issues))
283
+ diagnostics.push(diagnostic({ ...entry, code: entry.code ?? entry.type ?? 'configInvalid' }, 'error', {
284
+ ...(typeof r.pluginId === 'string' ? { pluginId: r.pluginId } : {}), ...(typeof entry.key === 'string' ? { field: entry.key } : {}),
285
+ }));
286
+ mapField(data, 'affectedFields', (entry) => pick(entry, ['key', 'title', 'kind', 'reserved', 'action', 'scope', 'valueState', 'stale']));
287
+ return data;
288
+ }
289
+ case 'dev.review.inspect':
290
+ case 'dev.review.prepare': {
291
+ const data = command === 'dev.review.inspect'
292
+ ? pick(r, ['view', 'target', 'sources', 'snapshot', 'skills', 'issues'])
293
+ : pick(r, ['target', 'sourceBindingPath', 'skills', 'issues']);
294
+ mapField(data, 'target', (entry) => pick(entry, ['kind', 'path']));
295
+ mapField(data, 'snapshot', (entry) => pick(entry, ['path', 'state']));
296
+ mapField(data, 'skills', reviewSkills);
297
+ mapField(data, 'issues', issue);
298
+ return data;
299
+ }
300
+ case 'dev.eval.prepare': return pick(r, ['suite', 'profile', 'platform', 'specPath', 'targetDigest', 'corpusDigest', 'sourceBindingPath', 'workspacePath']);
301
+ case 'dev.eval.check': {
302
+ const data = pick(r, ['providers', 'codex', 'credentials', 'permission', 'keychain', 'processManagement', 'cleanup']);
303
+ mapField(data, 'codex', (entry) => ({ ...pick(entry, ['requestedExecutable', 'resolvedExecutable']), runtimeConfig: pick(record(entry.runtimeConfig), ['model', 'modelProvider', 'credentialSource']) }));
304
+ mapField(data, 'credentials', (entry) => pick(entry, ['name', 'present']));
305
+ mapField(data, 'permission', (entry) => pick(entry, ['profile', 'status']));
306
+ mapField(data, 'keychain', (entry) => pick(entry, ['platform', 'status']));
307
+ mapField(data, 'processManagement', (entry) => pick(entry, ['managedAvailable', 'unmanagedAvailable', 'defaultMode']));
308
+ mapField(data, 'cleanup', (entry) => pick(entry, ['platform', 'supported', 'mechanism']));
309
+ return data;
310
+ }
311
+ case 'dev.skill.export': {
312
+ const data = pick(r, ['plugin', 'platform', 'scope', 'out', 'selectedSkills', 'requestedSkills', 'dependencies', 'configDigest', 'materializationDigest', 'outputDigest', 'sourceBindingPath']);
313
+ mapField(data, 'plugin', (entry) => pick(entry, ['id', 'sourceId', 'sourceIdentity', 'version']));
314
+ mapField(data, 'selectedSkills', (entry) => pick(entry, ['name', 'description', 'shortDescription', 'shortDescriptionSource', 'providerPluginId', 'providerDisplayName', 'relation', 'dynamic', 'filesDigest', 'configDigest']));
315
+ return data;
316
+ }
317
+ case 'dev.catalog.status': {
318
+ const data = pick(r, ['workspaceRoot', 'workspaceRootResolvedFrom', 'workspace', 'catalog', 'plugins', 'dependencyGraph', 'git', 'snapshot', 'issues']);
319
+ mapField(data, 'workspace', (entry) => pick(entry, ['root', 'resolvedFrom', 'valid', 'identity']));
320
+ mapField(data, 'catalog', (entry) => pick(entry, ['valid', 'version', 'channel', 'ownerName', 'ownerUrl', 'displayName']));
321
+ mapField(data, 'plugins', (entry) => pick(entry, ['name', 'version', 'dependencies', 'sourceValid']));
322
+ mapField(data, 'dependencyGraph', (entry) => pick(entry, ['valid', 'order']));
323
+ mapField(data, 'git', (entry) => pick(entry, ['checked', 'sourceHead', 'clean']));
324
+ mapField(data, 'snapshot', (entry) => pick(entry, ['path', 'state', 'valid', 'catalogVersion', 'snapshotDigest', 'sourceIdentityMatches']));
325
+ mapField(data, 'issues', issue);
326
+ return data;
327
+ }
328
+ case 'dev.catalog.publish.plan':
329
+ case 'dev.catalog.publish.apply': {
330
+ const data = pick(r, ['workspaceRoot', 'workspaceRootResolvedFrom', 'workspaceIdentity', 'catalogVersion', 'channel', 'remote', 'remoteResolvedFrom', 'remoteUrl', 'fetchUrl', 'pushUrl', 'branch', 'branchResolvedFrom', 'parent', 'tag', 'expectedCommit', 'sourceHead', 'pluginCount', 'snapshotDigest', 'planDigest', 'descriptor', 'state']);
331
+ mapField(data, 'descriptor', (entry) => ({ ...pick(entry, ['schemaVersion', 'workspaceIdentity', 'sourceHead', 'branch', 'parent', 'tag', 'snapshotDigest']), remote: pick(record(entry.remote), ['name', 'identityDigest']) }));
332
+ if (command === 'dev.catalog.publish.apply') {
333
+ Object.assign(data, pick(r, ['commit', 'reconciliation']));
334
+ Object.assign(data, pick(r, ['journalState', 'remoteWriteAttempted', 'remoteVerified']));
335
+ }
336
+ else
337
+ data.prepared = r.ok === true;
338
+ return data;
339
+ }
340
+ case 'dev.source.activate':
341
+ case 'dev.source.status':
342
+ case 'dev.source.deactivate': {
343
+ const data = command === 'dev.source.activate' ? pick(r, ['state', 'workspaceIdentity', 'snapshot', 'source', 'active'])
344
+ : command === 'dev.source.status' ? pick(r, ['ready', 'workspaceIdentity', 'snapshot', 'source', 'active', 'issues'])
345
+ : pick(r, ['state', 'workspaceIdentity', 'source', 'replacementPrimarySourceId', 'impact']);
346
+ mapField(data, 'snapshot', (entry) => pick(entry, ['action', 'digest', 'state', 'valid']));
347
+ mapField(data, 'source', (entry) => pick(entry, ['id', 'action', 'primary', 'exists', 'pathMatches', 'previousPrimary']));
348
+ mapField(data, 'active', (entry) => {
349
+ const result = pick(entry, ['ready', 'snapshotDigest', 'exists', 'digestMatchesSnapshot', 'compatibility']);
350
+ mapField(result, 'compatibility', compatibility);
351
+ return result;
352
+ });
353
+ mapField(data, 'issues', issue);
354
+ mapField(data, 'impact', sourceImpact);
355
+ return data;
356
+ }
357
+ case 'command.install':
358
+ case 'command.update':
359
+ case 'command.remove':
360
+ case 'command.list':
361
+ case 'command.show':
362
+ case 'command.package.sync':
363
+ case 'command.package.remove': {
364
+ const data = pick(r, ['commands', 'packages', 'changes', 'nativeToolChanges']);
365
+ mapField(data, 'commands', (entry) => {
366
+ const result = pick(entry, ['id', 'name', 'availability', 'resourceRoot', 'launch']);
367
+ const owner = record(entry.owner);
368
+ result.owner = { kind: owner.kind, ...(owner.producer ? { producer: producer(record(owner.producer)) } : {}) };
369
+ mapField(result, 'launch', (launch) => pick(launch, ['runner', 'entry', 'args', 'env', 'envFrom', 'cwd']));
370
+ diagnostics.push(...list(entry.errors).map((error) => diagnostic(error)));
371
+ result.blockerCodes = list(entry.errors).map((error) => error.code);
372
+ result.errors = list(entry.errors).map(issue);
373
+ return result;
374
+ });
375
+ mapField(data, 'packages', (entry) => {
376
+ diagnostics.push(...list(entry.errors).map((error) => diagnostic(error)));
377
+ return { ...pick(entry, ['id', 'availability', 'resourceRoot']), producer: producer(record(entry.producer)), sets: list(entry.sets).map((set) => pick(set, ['set', 'state', 'commandIds'])), errors: list(entry.errors).map(issue), blockerCodes: list(entry.errors).map((error) => error.code) };
378
+ });
379
+ mapField(data, 'changes', (entry) => pick(entry, ['kind', 'id', 'action']));
380
+ mapField(data, 'nativeToolChanges', nativeChange);
381
+ return data;
382
+ }
383
+ // These authoring tools return JSON DTOs, not runtime objects. Their paths are
384
+ // explicitly requested source/output artifacts and remain part of the contract.
385
+ case 'dev.plugin.create': return pick(r, ['pluginName', 'pluginRoot', 'workspaceRoot', 'workspaceRootResolvedFrom', 'files', 'created', 'version']);
386
+ case 'dev.skill.create': return pick(r, ['pluginName', 'skillName', 'skillDirectory', 'workspaceRoot', 'workspaceRootResolvedFrom', 'created', 'files']);
387
+ case 'dev.plugin.remove': {
388
+ const data = pick(r, ['workspaceRoot', 'workspaceRootResolvedFrom', 'baseCommit', 'plugin', 'removed']);
389
+ mapField(data, 'plugin', (entry) => pick(entry, ['name', 'version', 'root']));
390
+ return data;
391
+ }
392
+ case 'dev.plugin.status': {
393
+ const data = pick(r, ['policy', 'base', 'requestedBase', 'baseCommit', 'checkedPlugins', 'checks', 'workspaceRoot', 'workspaceRootResolvedFrom']);
394
+ mapField(data, 'base', (entry) => pick(entry, ['requested', 'commit']));
395
+ mapField(data, 'checks', (entry) => {
396
+ for (const error of Array.isArray(entry.errors) ? entry.errors : [])
397
+ diagnostics.push(diagnostic(error, 'error', { pluginId: String(entry.plugin) }));
398
+ return versionCheck(entry);
399
+ });
400
+ return data;
401
+ }
402
+ case 'dev.plugin.validate': {
403
+ const data = pick(r, ['profile', 'claudeSkillProfile', 'pluginDirectory', 'workspaceRoot', 'workspaceRootResolvedFrom', 'versionCheck', 'plugin', 'missingCapabilities', 'availableCapabilities']);
404
+ mapField(data, 'versionCheck', versionReport);
405
+ return data;
406
+ }
407
+ case 'dev.skill.validate': return pick(r, ['skillDirectory', 'frontmatterProfile', 'codexMetadata']);
408
+ case 'dev.plugin.build': return pick(r, ['workspaceRoot', 'workspaceRootResolvedFrom', 'pluginName', 'outputRoot', 'dependencies', 'digest']);
409
+ case 'dev.plugin.test': return pick(r, ['workspaceRoot', 'workspaceRootResolvedFrom', 'pluginName', 'exitCode']);
410
+ case 'dev.catalog.create': return pick(r, ['workspaceRoot', 'workspaceRootResolvedFrom', 'metadataPath', 'catalogVersion']);
411
+ case 'dev.catalog.version': return pick(r, ['workspaceRoot', 'workspaceRootResolvedFrom', 'catalogVersion', 'changed']);
412
+ case 'dev.catalog.build': return pick(r, ['workspaceRoot', 'workspaceRootResolvedFrom', 'outputRoot', 'catalogVersion', 'channel', 'pluginNames']);
413
+ case 'dev.catalog.validate': return pick(r, ['snapshotDirectory', 'catalogVersion', 'channel', 'snapshotDigest']);
414
+ default: throw new Error(`No public result projection is defined for ${command}.`);
415
+ }
416
+ }
417
+ const confirmationCodes = new Set(['confirmationRequired', 'catalogImpactConfirmationRequired', 'catalogSourceImpactConfirmationRequired', 'catalogSourceIdentityChangeConfirmationRequired', 'preApplyAuthorizationRequired', 'sharedNativeConfigApplyConfirmationRequired', 'nativeToolAuthorizationRequired', 'sourceRefreshConfirmationRequired']);
418
+ const blockedCodes = new Set([...confirmationCodes, 'operationReviewStale', 'reviewStale', 'catalogSourceUnavailable', 'catalogGenerationUnavailable', 'catalogGenerationSourceMissing', 'catalogGenerationIdentityMismatch', 'catalogGenerationReviewStale', 'catalogReplaceDamagedRequired', 'catalogGenerationActiveComparisonUnavailable', 'catalogLogicalIdentityChanged', 'catalogVersionConflict', 'catalogRollbackDetected', 'sourceMissing', 'sourceChanged', 'configSchemaUnavailable', 'schemaUnavailable', 'configUnavailable', 'projectRootUnavailable', 'awCapabilityUnsupported', 'commandNotFound', 'commandOwnerMismatch', 'commandIdentityConflict', 'commandResourceInvalid', 'commandBindingInvalid', 'managedSourceProtected', 'dependencyStillRequired', 'identityMismatch', 'catalogWorkspaceMissing', 'portableOutputConflict', 'portableUnsupported', 'requiredConfigMissing', 'portableSkillNameConflict', 'portableRuntimeImportMissing']);
419
+ function resultStatus(command, r, diagnostics, exitCode) {
420
+ const unsuccessful = r.ok === false || r.valid === false || exitCode !== 0;
421
+ if (command === 'source.status') {
422
+ const sources = list(r.sources), remote = list(r.remote);
423
+ const failed = sources.filter((entry) => entry.errorCode).length + remote.filter((entry) => entry.checked === false || entry.error).length;
424
+ if (failed)
425
+ return sources.some((entry) => !entry.errorCode) || remote.some((entry) => entry.checked === true) ? 'partial' : 'blocked';
426
+ return unsuccessful ? 'failed' : 'success';
427
+ }
428
+ if (command === 'cache.status' && unsuccessful)
429
+ return list(r.entries).some((entry) => entry.status !== 'error') ? 'partial' : 'failed';
430
+ if (command === 'cache.prune')
431
+ return r.overallState === 'partial' ? 'partial' : unsuccessful ? list(r.deleted).length ? 'partial' : 'failed' : 'success';
432
+ if (command === 'dev.review.inspect' && r.target !== null && Array.isArray(r.skills) && exitCode === 0)
433
+ return 'success';
434
+ if (command === 'dev.review.prepare' && unsuccessful && list(r.skills).some((entry) => entry.state === 'ready'))
435
+ return 'partial';
436
+ if (r.overallState === 'partial' || r.state === 'partial')
437
+ return 'partial';
438
+ if (!unsuccessful)
439
+ return 'success';
440
+ // A persisted config/preference, an attempted output, or publication uncertainty
441
+ // cannot be collapsed to an uncommitted failure.
442
+ if (r.configWrite === 'succeeded' || r.preferencesChanged === true || r.outputsMayHaveChanged === true || r.activeChanged === true || r.changed === true || r.removed === true || r.state === 'uncertain'
443
+ || list(r.changes).some((entry) => entry.action !== 'retained')
444
+ || list(r.targetResults).some((entry) => ['applied', 'partial', 'failed'].includes(String(entry.execution))))
445
+ return 'partial';
446
+ if ((command === 'command.list' || command === 'command.show') && (list(r.commands).length || list(r.packages).length))
447
+ return 'partial';
448
+ if (diagnostics.some((entry) => blockedCodes.has(entry.code)))
449
+ return 'blocked';
450
+ if (command.startsWith('target.') || command.startsWith('source.') || record(r.apply).state === 'unavailable')
451
+ return 'blocked';
452
+ return exitCode === 3 ? 'blocked' : 'failed';
453
+ }
454
+ function confirmationFor(command, r, yes, supplied, diagnostics) {
455
+ if (supplied && r.confirmation) {
456
+ const prepared = r.confirmation;
457
+ return { required: supplied.required || prepared.required, provided: supplied.provided || prepared.provided,
458
+ effects: [...new Map([...supplied.effects, ...prepared.effects].map((effect) => [JSON.stringify(effect), effect])).values()] };
459
+ }
460
+ if (supplied)
461
+ return supplied;
462
+ if (r.confirmation !== undefined)
463
+ return r.confirmation;
464
+ const missing = diagnostics.some((entry) => confirmationCodes.has(entry.code));
465
+ const sourceId = typeof r.sourceId === 'string' ? r.sourceId : typeof record(r.source).id === 'string' ? String(record(r.source).id) : undefined;
466
+ const pluginId = typeof r.pluginId === 'string' ? r.pluginId : typeof r.plugin === 'string' ? r.plugin : undefined;
467
+ if (command === 'source.sync' && r.impact) {
468
+ const impact = r.impact;
469
+ const required = impact.inventoryComplete === false || impact.affectedReferences?.length > 0 || impact.primaryChange !== null && impact.primaryChange !== undefined;
470
+ return { required, provided: yes, effects: required ? [{ code: 'changeSource', message: 'Activate the selected source version and affect its existing references.', subject: { sourceId }, impact: impact.inventoryComplete ? 'user-wide' : 'unknown' }] : [] };
471
+ }
472
+ if (command === 'cache.prune')
473
+ return r.dryRun === true ? { required: false, provided: yes, effects: [] }
474
+ : { required: true, provided: yes, effects: [{ code: 'removeOwnedOutput', message: 'Delete the selected reclaimable Catalog cache entries.', impact: 'user-wide' }] };
475
+ if (command === 'plugin.config.reset')
476
+ return { required: true, provided: yes, effects: [{ code: 'deletePluginConfig', message: 'Delete the selected plugin configuration overrides.', subject: { pluginId, scope: 'user' }, impact: 'user-wide' }] };
477
+ if (missing) {
478
+ const source = command.startsWith('source.') || command.startsWith('dev.source.');
479
+ const preApply = diagnostics.some((entry) => entry.code === 'preApplyConfirmationRequired' || entry.code === 'preApplyAuthorizationRequired');
480
+ return { required: true, provided: yes, effects: [{ code: source ? 'changeSource' : preApply ? 'runPreApply' : 'replaceSharedOutput',
481
+ message: source ? 'Change the selected Catalog source and its references.' : preApply ? 'Run the selected plugin preApply script.' : 'Change the selected shared output.',
482
+ subject: source ? { sourceId } : { pluginId, scope: 'user' }, impact: 'unknown' }] };
483
+ }
484
+ const ordinary = new Set(['source.add', 'target.set', 'target.exclude', 'target.include', 'dev.plugin.create', 'dev.skill.create', 'dev.plugin.build', 'dev.skill.export', 'dev.catalog.create', 'dev.catalog.version', 'dev.catalog.build', 'dev.catalog.publish.plan', 'dev.review.prepare', 'dev.eval.prepare', 'dev.plugin.requirements']);
485
+ if (ordinary.has(command) || command.startsWith('plugin.config.') && (!r.apply || record(r.apply).state === 'skipped'))
486
+ return { required: false, provided: yes, effects: [] };
487
+ // The handler owns prepared impact evidence. Absence is not evidence of no effects.
488
+ return null;
489
+ }
490
+ function publicationApplyAction(receipt, reason) {
491
+ if (typeof receipt.workspaceRoot !== 'string' || typeof receipt.remote !== 'string' || typeof receipt.branch !== 'string'
492
+ || typeof receipt.planDigest !== 'string' || !/^sha256:[0-9a-f]{64}$/u.test(receipt.planDigest))
493
+ return undefined;
494
+ return { kind: 'command', argv: ['aw', 'dev', 'catalog', 'publish', 'apply', '--workspace-root', receipt.workspaceRoot,
495
+ '--remote', receipt.remote, '--branch', receipt.branch, '--expected-plan-digest', receipt.planDigest], reason, requiresConfirmation: true };
496
+ }
497
+ export function projectReceipt(command, input, options = {}) {
498
+ if (!input || typeof input !== 'object' || Array.isArray(input))
499
+ throw new Error('The command returned an invalid result.');
500
+ const r = record(input);
501
+ if (r.schemaVersion === 1 && ['success', 'partial', 'blocked', 'failed'].includes(String(r.status)) && r.data && Array.isArray(r.diagnostics) && Array.isArray(r.nextActions))
502
+ return input;
503
+ const authorRoots = command.startsWith('dev.') && typeof r.workspaceRoot === 'string' ? [r.workspaceRoot] : [];
504
+ const subject = {
505
+ ...(typeof r.sourceId === 'string' ? { sourceId: r.sourceId } : {}),
506
+ ...(command.startsWith('dev.source.') && typeof record(r.source).id === 'string' ? { sourceId: String(record(r.source).id) } : {}),
507
+ ...(typeof r.pluginId === 'string' ? { pluginId: r.pluginId } : typeof record(r.plugin).id === 'string' ? { pluginId: String(record(r.plugin).id) } : {}),
508
+ ...(r.scope === 'user' || r.scope === 'project' ? { scope: r.scope } : {}),
509
+ };
510
+ const diagnostics = [...(Array.isArray(r.errors) ? r.errors : []), ...(Array.isArray(r.issues) ? r.issues : []), ...(Array.isArray(r.blockers) ? r.blockers : [])].map((entry) => diagnostic(entry, 'error', subject, authorRoots));
511
+ if (r.error || r.ok === false && r.message)
512
+ diagnostics.push(diagnostic({ code: r.code, message: r.error ?? r.message }, 'error', subject, authorRoots));
513
+ if (Array.isArray(r.warnings))
514
+ diagnostics.push(...r.warnings.map((entry) => diagnostic(entry, 'warning', subject, authorRoots)));
515
+ const data = projectData(command, r, diagnostics);
516
+ const capabilityFailure = list(r.errors).find((entry) => entry.code === 'awCapabilityUnsupported');
517
+ if (capabilityFailure)
518
+ data.compatibility = pick(capabilityFailure, ['missingCapabilities', 'availableCapabilities']);
519
+ if (command === 'self.check' && Array.isArray(r.missingCapabilities) && r.missingCapabilities.length) {
520
+ diagnostics.push(diagnostic({ code: 'awCapabilityUnsupported', message: 'The current AW executable does not support all required capabilities.' }));
521
+ }
522
+ let status = resultStatus(command, r, diagnostics, options.exitCode ?? 0);
523
+ if (isPublicWrite(command)) {
524
+ const confirmation = confirmationFor(command, r, options.yes === true, options.confirmation, diagnostics);
525
+ data.confirmation = confirmation;
526
+ if (confirmation?.required && !confirmation.provided && diagnostics.some((entry) => confirmationCodes.has(entry.code))) {
527
+ if (!diagnostics.some((entry) => entry.code === 'confirmationRequired'))
528
+ diagnostics.push(diagnostic({ code: 'confirmationRequired', message: 'Repeat the command with --yes to confirm the listed effects.' }));
529
+ if (status !== 'partial')
530
+ status = 'blocked';
531
+ }
532
+ }
533
+ const result = commandResult(command, data, { status, diagnostics: [...new Map(diagnostics.map((entry) => [JSON.stringify(entry), entry])).values()] });
534
+ if (status === 'success' && command === 'dev.catalog.publish.plan' && r.state === 'prepared') {
535
+ const action = publicationApplyAction(r, 'Apply this exact prepared publication after reviewing its target and digest.');
536
+ if (action)
537
+ result.nextActions.push(action);
538
+ }
539
+ if (status !== 'success') {
540
+ if (diagnostics.some((entry) => entry.code === 'catalogWorkspaceMissing'))
541
+ result.nextActions.push({ kind: 'command',
542
+ argv: ['aw', 'dev', 'catalog', 'create'], reason: 'Create a Catalog Workspace explicitly before running authoring commands.', requiresConfirmation: false });
543
+ if (command === 'dev.catalog.publish.apply' && typeof r.planDigest === 'string') {
544
+ const action = publicationApplyAction(r, 'Reconcile the same publication plan before attempting any different publication.');
545
+ if (action)
546
+ result.nextActions.push(action);
547
+ else
548
+ result.nextActions.push({ kind: 'manual', message: `Use the original workspace and remote selection to reconcile publication plan ${r.planDigest}. Review its current state before confirming apply.` });
549
+ }
550
+ if (command.startsWith('plugin.config.')) {
551
+ const apply = record(r.apply);
552
+ for (const entry of list(apply.commandResults)) {
553
+ const identity = record(entry.producer);
554
+ if (entry.state !== 'completed' && identity.kind === 'package' && typeof identity.sourceId === 'string'
555
+ && typeof identity.pluginName === 'string' && typeof identity.key === 'string' && (identity.scope === 'user' || identity.scope === 'project')) {
556
+ result.nextActions.push({ kind: 'command', argv: ['aw', 'command', 'package', 'sync', `${identity.sourceId}/${identity.pluginName}`, identity.key, '--scope', identity.scope], reason: 'Repair the affected command package after resolving its diagnostics.', requiresConfirmation: true });
557
+ }
558
+ }
559
+ for (const entry of list(apply.targetResults)) {
560
+ const target = record(entry.target);
561
+ if (entry.state !== 'completed' && (entry.state !== 'skipped' || entry.errorCode) && typeof target.pluginId === 'string' && typeof target.platform === 'string' && (target.scope === 'user' || target.scope === 'project')) {
562
+ result.nextActions.push({ kind: 'command', argv: ['aw', 'plugin', 'sync', target.pluginId, '--context', target.scope, '--target', target.platform], reason: 'Repair the affected deployment target after resolving its diagnostics.', requiresConfirmation: true });
563
+ }
564
+ }
565
+ }
566
+ if (command === 'source.status' || command === 'source.sync')
567
+ for (const entry of diagnostics)
568
+ if (entry.subject?.sourceId)
569
+ result.nextActions.push({ kind: 'command', argv: ['aw', 'source', 'status', entry.subject.sourceId], reason: 'Inspect the selected source before retrying a source change.', requiresConfirmation: false });
570
+ if (!result.nextActions.length)
571
+ result.nextActions.push({ kind: 'manual', message: status === 'partial' ? 'Review completed and incomplete results before retrying the operation.' : 'Resolve the reported diagnostics before retrying the operation.' });
572
+ }
573
+ return result;
574
+ }
575
+ //# sourceMappingURL=receipt-projection.js.map