afyx-engineering-kit 0.1.0-alpha.7 → 0.1.0-alpha.8

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 (55) hide show
  1. package/.afyx-source-revision +1 -1
  2. package/afyx-context/src/budget.js +39 -153
  3. package/afyx-context/src/documentation.js +116 -0
  4. package/afyx-context/src/index.js +2 -0
  5. package/afyx-context/src/memory.js +122 -229
  6. package/afyx-context/src/usage.js +91 -0
  7. package/afyx-forge/src/cli.js +14 -1
  8. package/afyx-forge/src/index.js +3 -0
  9. package/afyx-forge/src/workflow-refiner.js +48 -15
  10. package/afyx-forge/src/workflow.js +226 -0
  11. package/afyx-graph/engine/release/RELEASE-MANIFEST.json +16 -6
  12. package/afyx-graph/engine/release/SHA256SUMS +4 -2
  13. package/afyx-graph/engine/release/afyx-graph-darwin-arm64.tar.gz +0 -0
  14. package/afyx-graph/engine/release/afyx-graph-darwin-x64.tar.gz +0 -0
  15. package/afyx-graph/engine/release/afyx-graph-linux-x64.tar.gz +0 -0
  16. package/afyx-graph/engine/release/afyx-graph-win32-x64.zip +0 -0
  17. package/bin/afyx-engineering-kit.mjs +14 -6
  18. package/install.ps1 +52 -6
  19. package/install.sh +11 -7
  20. package/package.json +3 -1
  21. package/scripts/afyx-capability-orchestrator.mjs +159 -41
  22. package/scripts/afyx-graph-artifact.mjs +1 -1
  23. package/scripts/afyx-graph-targets.mjs +8 -0
  24. package/scripts/afyx-host-adapters.mjs +52 -0
  25. package/scripts/afyx-host-bridge-lifecycle.mjs +4 -0
  26. package/scripts/afyx-host-bridge.mjs +25 -0
  27. package/scripts/afyx-install-backend.mjs +34 -13
  28. package/scripts/afyx-install-contract.mjs +5 -2
  29. package/scripts/afyx-install-progress.mjs +88 -0
  30. package/scripts/afyx-installer-environment.mjs +150 -0
  31. package/scripts/afyx-local-link-ownership.mjs +16 -0
  32. package/scripts/afyx-midnight-circuit.mjs +322 -79
  33. package/scripts/afyx-modular-integration.mjs +3 -0
  34. package/scripts/afyx-modular-runtime.mjs +3 -0
  35. package/scripts/afyx-native-execution.mjs +168 -0
  36. package/scripts/afyx-native-github.mjs +155 -0
  37. package/scripts/afyx-npm-installer.mjs +56 -28
  38. package/scripts/afyx-provider-inventory.mjs +6 -3
  39. package/scripts/afyx-security-auditor.mjs +61 -64
  40. package/scripts/afyx-skill-catalog.mjs +83 -0
  41. package/scripts/afyx-skill-engineering.mjs +2 -0
  42. package/scripts/afyx-universal-runtime.mjs +74 -12
  43. package/scripts/install-afyx-graph.sh +4 -4
  44. package/scripts/lib/AfyxInstallerProgress.psm1 +11 -0
  45. package/scripts/lib/AfyxSkillLifecycle.psm1 +42 -6
  46. package/scripts/lib/afyx-installer-progress.sh +30 -0
  47. package/scripts/link-global-dev.ps1 +10 -3
  48. package/scripts/link-global-dev.sh +10 -8
  49. package/scripts/prepare-g6-package.mjs +13 -28
  50. package/scripts/resolve-git-release-artifacts.mjs +5 -4
  51. package/scripts/stage-npm-release.mjs +3 -1
  52. package/scripts/validate-release-zip-graph.mjs +2 -2
  53. package/uninstall.ps1 +2 -0
  54. package/verify.ps1 +7 -1
  55. package/verify.sh +5 -3
@@ -0,0 +1,226 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { evaluateVerifiedTaskCompletion } from './workflow-refiner.js';
3
+
4
+ export const FORGE_WORKFLOW_CONTRACT = 'afyx-forge-workflow/v1';
5
+ const ID = /^[a-z][a-z0-9-]{0,63}$/;
6
+ const hash = (value) => createHash('sha256').update(value).digest('hex');
7
+ const plain = (value) => value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype;
8
+ let mutationTail = Promise.resolve();
9
+ async function serialMutation(action, signal) {
10
+ const previous = mutationTail;
11
+ let release;
12
+ const held = new Promise((resolve) => { release = resolve; });
13
+ mutationTail = previous.catch(() => {}).then(() => held);
14
+ try {
15
+ await previous.catch(() => {});
16
+ if (signal.aborted) throw new Error('WORKFLOW_ABORTED');
17
+ return await action();
18
+ } finally { release(); }
19
+ }
20
+ const profiles = Object.freeze([
21
+ ['general', 'software-engineer', ['direct-source']], ['erp', 'erp-technical-specialist', ['odoo-engineering', 'afyx-graph']],
22
+ ['security', 'cybersecurity-devsecops', ['afyx-security-auditor']], ['data', 'database-administrator', ['afyx-graph']],
23
+ ['architecture', 'solutions-architect', ['afyx-graph']], ['platform', 'site-reliability-engineer', ['native-execution']],
24
+ ]);
25
+
26
+ /** Profile metadata references AFYX-owned Expert roles; it grants no tool permission. */
27
+ export function createForgeProfiles({ domain, availableCapabilities = [] } = {}) {
28
+ if (domain !== undefined && !profiles.some(([name]) => name === domain)) throw new Error('UNKNOWN_DOMAIN');
29
+ if (!Array.isArray(availableCapabilities) || availableCapabilities.some((item) => typeof item !== 'string')) throw new Error('INVALID_CAPABILITIES');
30
+ return profiles.filter(([name]) => domain === undefined || name === domain).map(([name, role, capabilities]) => ({
31
+ contract: 'afyx-forge-profile/v1', domain: name, role, owner: 'afyx-forge', knowledgeOwner: 'afyx-engineering-expert',
32
+ roleReference: `references/${role}.md`, capabilities: [...capabilities],
33
+ availableCapabilities: capabilities.filter((capability) => capability === 'direct-source' || availableCapabilities.includes(capability)),
34
+ authorization: 'TRUSTED_HOST_REQUIRED',
35
+ }));
36
+ }
37
+ function bounded(value, fallback, max) {
38
+ const selected = value ?? fallback;
39
+ if (!Number.isSafeInteger(selected) || selected < 1 || selected > max) throw new Error('INVALID_BUDGET');
40
+ return selected;
41
+ }
42
+ function copyPlainData(value, stack = new Set(), depth = 0, budget = { items: 0 }) {
43
+ if (++budget.items > 8192 || depth > 16) throw new Error('PLAN_LIMIT');
44
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') return value;
45
+ if (typeof value === 'number' && Number.isFinite(value)) return value;
46
+ if (!value || typeof value !== 'object' || (!Array.isArray(value) && !plain(value)) || stack.has(value)) throw new Error('PLAIN_PLAN_REQUIRED');
47
+ const descriptors = Object.getOwnPropertyDescriptors(value);
48
+ const keys = Reflect.ownKeys(descriptors);
49
+ if (keys.some((key) => typeof key !== 'string' || ['toJSON', '__proto__', 'constructor', 'prototype'].includes(key))) throw new Error('PLAIN_PLAN_REQUIRED');
50
+ stack.add(value);
51
+ let result;
52
+ if (Array.isArray(value)) {
53
+ const length = descriptors.length.value;
54
+ if (length > 1024 || keys.length !== length + 1) throw new Error('PLAIN_PLAN_REQUIRED');
55
+ result = []; Object.setPrototypeOf(result, null);
56
+ for (let index = 0; index < length; index++) {
57
+ const descriptor = descriptors[index];
58
+ if (!descriptor || !Object.hasOwn(descriptor, 'value') || !descriptor.enumerable) throw new Error('PLAIN_PLAN_REQUIRED');
59
+ result.push?.(); // Arrays have no inherited methods in the plain-data snapshot.
60
+ result[index] = copyPlainData(descriptor.value, stack, depth + 1, budget);
61
+ }
62
+ } else {
63
+ result = Object.create(null);
64
+ for (const key of keys) {
65
+ const descriptor = descriptors[key];
66
+ if (!Object.hasOwn(descriptor, 'value') || !descriptor.enumerable) throw new Error('PLAIN_PLAN_REQUIRED');
67
+ result[key] = copyPlainData(descriptor.value, stack, depth + 1, budget);
68
+ }
69
+ }
70
+ stack.delete(value);
71
+ return result;
72
+ }
73
+ function normalizePlan(plan) {
74
+ const serialized = JSON.stringify(copyPlainData(plan));
75
+ if (!serialized || Buffer.byteLength(serialized) > 65_536) throw new Error('PLAN_LIMIT');
76
+ const copy = JSON.parse(serialized);
77
+ if (!plain(copy) || copy.contract !== FORGE_WORKFLOW_CONTRACT || !ID.test(copy.id)
78
+ || !Array.isArray(copy.steps) || !copy.steps.length || copy.steps.length > 64
79
+ || Object.keys(copy).some((key) => !['contract', 'id', 'steps', 'acceptanceCriteria'].includes(key))) throw new Error('INVALID_PLAN');
80
+ const ids = new Set();
81
+ for (const step of copy.steps) {
82
+ if (!plain(step) || !ID.test(step.id) || ids.has(step.id) || !ID.test(step.capability)
83
+ || Object.keys(step).some((key) => !['id', 'capability', 'dependsOn', 'input', 'effect'].includes(key))
84
+ || !Array.isArray(step.dependsOn) || step.dependsOn.some((dep) => !ID.test(dep))
85
+ || new Set(step.dependsOn).size !== step.dependsOn.length
86
+ || (step.effect !== undefined && !['read', 'mutation'].includes(step.effect))) throw new Error('INVALID_STEP');
87
+ ids.add(step.id);
88
+ }
89
+ const reachable = new Set();
90
+ while (reachable.size < copy.steps.length) {
91
+ const ready = copy.steps.filter((step) => !reachable.has(step.id) && step.dependsOn.every((id) => reachable.has(id)));
92
+ if (!ready.length) throw new Error('MISSING_DEPENDENCY_OR_CYCLE');
93
+ for (const step of ready) reachable.add(step.id);
94
+ }
95
+ return { plan: copy, digest: hash(serialized) };
96
+ }
97
+
98
+ /** Forge owns scheduling; the trusted host supplies capability adapters and authorization. */
99
+ export async function executeForgeWorkflow(input, options = {}) {
100
+ const { plan, digest } = normalizePlan(input);
101
+ const { adapters = {}, authorize, checkpoint, verifyCheckpoint, saveCheckpoint, signal } = options;
102
+ const limits = { maxCalls: bounded(options.budget?.maxCalls, 64, 256),
103
+ maxElapsedMs: bounded(options.budget?.maxElapsedMs, 30_000, 300_000), maxParallel: bounded(options.budget?.maxParallel, 2, 2) };
104
+ const definitions = new Map();
105
+ for (const step of plan.steps) {
106
+ const descriptor = Object.hasOwn(adapters, step.capability) ? adapters[step.capability] : null;
107
+ if (!descriptor || typeof descriptor.execute !== 'function' || !['read', 'mutation'].includes(descriptor.effect)
108
+ || (descriptor.privileged !== undefined && typeof descriptor.privileged !== 'boolean')
109
+ || (step.effect !== undefined && step.effect !== descriptor.effect)) throw new Error('TRUSTED_ADAPTER_REQUIRED');
110
+ definitions.set(step.id, Object.freeze({ execute: descriptor.execute, effect: descriptor.effect, privileged: descriptor.privileged === true }));
111
+ }
112
+ const state = new Map(plan.steps.map((step) => [step.id, 'PENDING']));
113
+ const receipts = []; const completed = new Set();
114
+ if (checkpoint !== undefined) {
115
+ let approved = false;
116
+ try { approved = typeof verifyCheckpoint === 'function' && verifyCheckpoint(checkpoint, Object.freeze({ planDigest: digest })) === true; } catch { /* fail closed */ }
117
+ if (!approved || checkpoint.contract !== 'afyx-forge-checkpoint/v1' || checkpoint.planDigest !== digest
118
+ || !Array.isArray(checkpoint.completed) || checkpoint.completed.some((id) => !state.has(id))
119
+ || new Set(checkpoint.completed).size !== checkpoint.completed.length) throw new Error('UNVERIFIED_CHECKPOINT');
120
+ for (const id of checkpoint.completed) completed.add(id);
121
+ if (plan.steps.some((step) => completed.has(step.id) && step.dependsOn.some((id) => !completed.has(id)))) throw new Error('INVALID_CHECKPOINT_DEPENDENCIES');
122
+ for (const id of completed) state.set(id, 'COMPLETED');
123
+ }
124
+ const snapshot = () => Object.freeze({ contract: 'afyx-forge-checkpoint/v1', planDigest: digest,
125
+ completed: Object.freeze(plan.steps.filter((step) => completed.has(step.id)).map((step) => step.id)) });
126
+ const started = performance.now(); let calls = 0; let stopped = null;
127
+ const controller = new AbortController();
128
+ const abort = () => { stopped ??= 'CANCELLED'; controller.abort(); };
129
+ signal?.addEventListener('abort', abort, { once: true });
130
+ if (signal?.aborted) abort();
131
+ async function run(step) {
132
+ const adapter = definitions.get(step.id);
133
+ const proposal = Object.freeze({ workflowId: plan.id, planDigest: digest, stepId: step.id,
134
+ capability: step.capability, effect: adapter.effect, privileged: adapter.privileged });
135
+ if (adapter.effect === 'mutation' || adapter.privileged) {
136
+ try { if (typeof authorize !== 'function' || authorize(proposal) !== true) return { stepId: step.id, status: 'DENIED' }; }
137
+ catch { return { stepId: step.id, status: 'DENIED' }; }
138
+ }
139
+ if (controller.signal.aborted) return { stepId: step.id, status: 'CANCELLED' };
140
+ const remaining = limits.maxElapsedMs - (performance.now() - started);
141
+ if (remaining <= 0) return { stepId: step.id, status: 'TIMEOUT' };
142
+ let timer; let onStepAbort;
143
+ try {
144
+ const invoke = () => {
145
+ if (controller.signal.aborted) throw new Error('WORKFLOW_ABORTED');
146
+ let consumed = false;
147
+ const action = () => {
148
+ if (consumed) throw new Error('STEP_ALREADY_INVOKED');
149
+ consumed = true; calls++;
150
+ return adapter.execute(step.input ?? {}, { signal: controller.signal, proposal });
151
+ };
152
+ return adapter.effect === 'mutation' && typeof options.runExclusive === 'function'
153
+ ? Promise.resolve(options.runExclusive(proposal, action, { signal: controller.signal })).then((result) => {
154
+ if (!consumed) throw new Error('HOST_LOCK_DID_NOT_EXECUTE');
155
+ return result;
156
+ }) : action();
157
+ };
158
+ const result = await Promise.race([
159
+ adapter.effect === 'mutation' ? serialMutation(invoke, controller.signal) : Promise.resolve().then(invoke),
160
+ new Promise((_, reject) => { timer = setTimeout(() => { controller.abort(); reject(new Error('WORKFLOW_TIMEOUT')); }, remaining); }),
161
+ new Promise((_, reject) => {
162
+ onStepAbort = () => reject(new Error('WORKFLOW_ABORTED'));
163
+ controller.signal.addEventListener('abort', onStepAbort, { once: true });
164
+ }),
165
+ ]);
166
+ if (!result || !['SUCCESS', 'PASS', 'EXECUTED'].includes(result.status)) return { stepId: step.id, status: 'FAILED' };
167
+ const encoded = JSON.stringify(result);
168
+ if (!encoded || Buffer.byteLength(encoded) > 1_048_576) return { stepId: step.id, status: 'INVALID_RESULT' };
169
+ return { stepId: step.id, status: 'COMPLETED', resultDigest: hash(encoded) };
170
+ } catch { return { stepId: step.id, status: stopped ? 'CANCELLED' : controller.signal.aborted ? 'TIMEOUT' : 'FAILED' }; }
171
+ finally { clearTimeout(timer); if (onStepAbort) controller.signal.removeEventListener('abort', onStepAbort); }
172
+ }
173
+ try {
174
+ while (completed.size < plan.steps.length && !stopped) {
175
+ if (controller.signal.aborted) { stopped = 'CANCELLED'; break; }
176
+ if (calls >= limits.maxCalls || performance.now() - started >= limits.maxElapsedMs) { stopped = 'BUDGET_EXHAUSTED'; break; }
177
+ const ready = plan.steps.filter((step) => state.get(step.id) === 'PENDING' && step.dependsOn.every((id) => completed.has(id)));
178
+ const batch = [];
179
+ for (const step of ready) {
180
+ const mutation = definitions.get(step.id).effect === 'mutation';
181
+ if (mutation && batch.length) break;
182
+ batch.push(step);
183
+ if (mutation || batch.length >= limits.maxParallel || batch.length >= limits.maxCalls - calls) break;
184
+ }
185
+ if (!batch.length) { stopped = 'DEPENDENCY_BLOCKED'; break; }
186
+ for (const step of batch) state.set(step.id, 'RUNNING');
187
+ const outcomes = await Promise.all(batch.map(async (step) => {
188
+ const outcome = await run(step);
189
+ if (outcome.status !== 'COMPLETED') { stopped ??= outcome.status; controller.abort(); }
190
+ return outcome;
191
+ }));
192
+ for (const outcome of outcomes) {
193
+ receipts.push(Object.freeze(outcome)); state.set(outcome.stepId, outcome.status);
194
+ if (outcome.status === 'COMPLETED') {
195
+ completed.add(outcome.stepId);
196
+ if (saveCheckpoint) {
197
+ let saveTimer; let onSaveAbort;
198
+ try {
199
+ const remaining = limits.maxElapsedMs - (performance.now() - started);
200
+ if (remaining <= 0) throw new Error('CHECKPOINT_TIMEOUT');
201
+ await Promise.race([saveCheckpoint(snapshot(), { signal: controller.signal }),
202
+ new Promise((_, reject) => { saveTimer = setTimeout(() => reject(new Error('CHECKPOINT_TIMEOUT')), remaining); }),
203
+ new Promise((_, reject) => {
204
+ onSaveAbort = () => reject(new Error('WORKFLOW_ABORTED'));
205
+ controller.signal.addEventListener('abort', onSaveAbort, { once: true });
206
+ if (controller.signal.aborted) onSaveAbort();
207
+ })]);
208
+ }
209
+ catch { stopped ??= 'CHECKPOINT_SAVE_FAILED_REVIEW_REQUIRED'; }
210
+ finally { clearTimeout(saveTimer); if (onSaveAbort) controller.signal.removeEventListener('abort', onSaveAbort); }
211
+ }
212
+ } else stopped ??= outcome.status;
213
+ }
214
+ if (stopped) controller.abort();
215
+ }
216
+ } finally { signal?.removeEventListener('abort', abort); }
217
+ const acceptance = plan.acceptanceCriteria === undefined ? null : evaluateVerifiedTaskCompletion(plan.acceptanceCriteria,
218
+ options.evidence ?? [], { sourceRevision: options.sourceRevision, verifyEvidence: options.verifyEvidence });
219
+ const successful = !stopped && completed.size === plan.steps.length;
220
+ return Object.freeze({ contract: FORGE_WORKFLOW_CONTRACT, workflowId: plan.id, planDigest: digest,
221
+ status: successful ? acceptance && !acceptance.isComplete ? 'UNVERIFIED' : 'SUCCESS' : 'STOPPED',
222
+ reason: stopped ?? (acceptance && !acceptance.isComplete ? 'ACCEPTANCE_UNVERIFIED' : 'COMPLETED'),
223
+ calls, durationMs: performance.now() - started, mutationIsolation: typeof options.runExclusive === 'function' ? 'TRUSTED_HOST_LOCK_CALLBACK' : 'PROCESS_LOCAL',
224
+ checkpoint: snapshot(), receipts: Object.freeze(receipts),
225
+ steps: Object.freeze(plan.steps.map((step) => Object.freeze({ id: step.id, status: state.get(step.id) }))), acceptance });
226
+ }
@@ -1,21 +1,31 @@
1
1
  {
2
- "schema": 1,
2
+ "schema": 2,
3
3
  "product": "Afyx Graph",
4
4
  "product_version": "1.0.0",
5
5
  "release_tag": "afyx-graph-v1.0.0",
6
- "source_revision": "251f73a8f91cd7b9194a2bd730966c1d92f86da0",
6
+ "source_revision": "57cfcf2c7b7a48d1c5bbba03fe97af98b71ac5bd",
7
7
  "integrity_claim": "sha256",
8
8
  "publisher_authenticity": "requires-independent-attestation",
9
9
  "artifacts": [
10
+ {
11
+ "file": "afyx-graph-win32-x64.zip",
12
+ "target": "win32-x64",
13
+ "sha256": "b5b298f0bc2ba91361a46c0a7a38bd23bacf2e640c3dac05188fc09cbd44e688"
14
+ },
10
15
  {
11
16
  "file": "afyx-graph-linux-x64.tar.gz",
12
17
  "target": "linux-x64",
13
- "sha256": "5c657a46f86652d9f32f1b8045c60a41ab8c6f2bc46aeb55a943db1b65ea0b83"
18
+ "sha256": "533f85c5878d8720e46041696fb3b9752e626a7ffdf811b76e604f85d843aa57"
14
19
  },
15
20
  {
16
- "file": "afyx-graph-win32-x64.zip",
17
- "target": "win32-x64",
18
- "sha256": "720878c50518e4650a529cd6a766d4c8cdec173863799b8ea9c966c36601bd25"
21
+ "file": "afyx-graph-darwin-arm64.tar.gz",
22
+ "target": "darwin-arm64",
23
+ "sha256": "41a2161a0925f202bbfc2136d3f7c6d8cf8138c7dcaffaa1a2c4b2afd750e1ed"
24
+ },
25
+ {
26
+ "file": "afyx-graph-darwin-x64.tar.gz",
27
+ "target": "darwin-x64",
28
+ "sha256": "a04fd24623fdc53e9f9ae136ce1d1be3e01a36e02886bd055a97d7999c876f64"
19
29
  }
20
30
  ]
21
31
  }
@@ -1,2 +1,4 @@
1
- 5c657a46f86652d9f32f1b8045c60a41ab8c6f2bc46aeb55a943db1b65ea0b83 afyx-graph-linux-x64.tar.gz
2
- 720878c50518e4650a529cd6a766d4c8cdec173863799b8ea9c966c36601bd25 afyx-graph-win32-x64.zip
1
+ b5b298f0bc2ba91361a46c0a7a38bd23bacf2e640c3dac05188fc09cbd44e688 afyx-graph-win32-x64.zip
2
+ 533f85c5878d8720e46041696fb3b9752e626a7ffdf811b76e604f85d843aa57 afyx-graph-linux-x64.tar.gz
3
+ 41a2161a0925f202bbfc2136d3f7c6d8cf8138c7dcaffaa1a2c4b2afd750e1ed afyx-graph-darwin-arm64.tar.gz
4
+ a04fd24623fdc53e9f9ae136ce1d1be3e01a36e02886bd055a97d7999c876f64 afyx-graph-darwin-x64.tar.gz
@@ -12,7 +12,7 @@ import {
12
12
  buildSubprocessCall,
13
13
  executeSubprocess,
14
14
  } from '../scripts/afyx-npm-installer.mjs';
15
- import { runMidnightCircuit, terminalMode } from '../scripts/afyx-midnight-circuit.mjs';
15
+ import { runMidnightCircuit, terminalMode, recordInstallerDiagnostic } from '../scripts/afyx-midnight-circuit.mjs';
16
16
 
17
17
  function verifyNodeRuntime() {
18
18
  const version = process.versions.node;
@@ -45,7 +45,7 @@ async function main() {
45
45
  process.exit(1);
46
46
  }
47
47
 
48
- let finish;
48
+ let finish, onOutput, startProgress;
49
49
  if (parsed.command === 'install') {
50
50
  const mode = terminalMode({ requested: parsed.options.ui || 'auto' });
51
51
  const hasSelections = parsed.options.preset || parsed.options.provider || parsed.options.providerScope ||
@@ -53,20 +53,26 @@ async function main() {
53
53
  if (parsed.options.ui === 'tui' && (hasSelections || parsed.options.nonInteractive || parsed.options.dryRun || parsed.options.validateOnly)) {
54
54
  throw new Error('--ui tui runs the interactive installer; remove scripted selection/preview flags or use --ui plain.');
55
55
  }
56
- if (mode === 'tui' && !hasSelections &&
56
+ if ((mode === 'tui' || (process.stdin.isTTY && process.stdout.isTTY && !process.env.CI)) && !hasSelections &&
57
57
  !parsed.options.nonInteractive && !parsed.options.dryRun && !parsed.options.validateOnly) {
58
- const selection = await runMidnightCircuit({ options: parsed.options });
58
+ const selection = await runMidnightCircuit({ options: parsed.options, plain: mode === 'plain' });
59
59
  if (!selection) { console.log('Installation canceled without changes.'); return; }
60
60
  finish = selection.finish;
61
+ onOutput = selection.onOutput;
62
+ startProgress = selection.startProgress;
61
63
  Object.assign(parsed.options, selection);
62
64
  delete parsed.options.finish;
65
+ delete parsed.options.onOutput;
66
+ delete parsed.options.startProgress;
63
67
  }
64
68
  }
65
69
  const callInfo = buildSubprocessCall(parsed.command, parsed.options);
70
+ if (finish) callInfo.env = { ...callInfo.env, AFYX_INSTALL_UI_OWNER: 'node', AFYX_INSTALL_PROGRESS: '1', NO_COLOR: '1', AFYX_PLAIN_OUTPUT: '1' };
66
71
  if (parsed.options.ui === 'plain') callInfo.env = { ...callInfo.env, NO_COLOR: '1' };
67
72
 
68
73
  try {
69
- const exitCode = await executeSubprocess(callInfo);
74
+ if (startProgress) startProgress();
75
+ const exitCode = await executeSubprocess(callInfo, { onOutput });
70
76
  const finalCode = finish ? await finish(exitCode) : exitCode;
71
77
  process.exit(finalCode);
72
78
  } catch (err) {
@@ -77,6 +83,8 @@ async function main() {
77
83
  }
78
84
 
79
85
  main().catch((err) => {
80
- console.error('Fatal CLI execution error:', err);
86
+ const diagnostic = recordInstallerDiagnostic(err);
87
+ console.error(`Installer error: ${String(err.message || err).split('\n')[0]}\nDiagnostic log: ${diagnostic}`);
88
+ if (process.stdout.isTTY && !process.env.NO_COLOR && process.env.TERM !== 'dumb') process.stdout.write('\x1b[0m\x1b[?25h');
81
89
  process.exit(1);
82
90
  });
package/install.ps1 CHANGED
@@ -33,8 +33,25 @@ param(
33
33
 
34
34
  Set-StrictMode -Version Latest
35
35
  $ErrorActionPreference = 'Stop'
36
+ Import-Module (Join-Path $PSScriptRoot 'scripts\lib\AfyxTerminal.psm1') -Force
37
+
38
+ # Bare interactive entrypoints share the Node UX. Explicit native script options
39
+ # and noninteractive automation retain their existing backend contract.
40
+ if ($PSBoundParameters.Count -eq 0 -and -not $env:CI -and $env:AFYX_INSTALL_UI_OWNER -ne 'node' -and
41
+ (Test-AfyxInteractiveTerminal)) {
42
+ $interactiveNode = Get-Command node -ErrorAction SilentlyContinue
43
+ if ($interactiveNode) {
44
+ & $interactiveNode.Source (Join-Path $PSScriptRoot 'bin\afyx-engineering-kit.mjs') install
45
+ exit $LASTEXITCODE
46
+ }
47
+ }
36
48
 
37
49
  $packageRoot = $PSScriptRoot
50
+ Import-Module (Join-Path $packageRoot 'scripts\lib\AfyxInstallerProgress.psm1') -Force
51
+ if ($env:AFYX_INSTALL_UI_OWNER -eq 'node') { [Console]::OutputEncoding = [Text.UTF8Encoding]::new($false) }
52
+ if ($ComponentAction.Count) {
53
+ $ComponentAction = @($ComponentAction | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ })
54
+ }
38
55
  if (($PlanJson -or $ExpectedPlan) -and -not $Preset) { throw 'Structured planning requires an explicit preset.' }
39
56
  if ($CustomComponent.Count) {
40
57
  $CustomComponent = @($CustomComponent | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ })
@@ -66,7 +83,6 @@ if ($InstallUsageTracker -and $SkipUsageTracker) { throw '-InstallUsageTracker a
66
83
  Import-Module (Join-Path $packageRoot 'scripts\lib\AfyxComponents.psm1') -Force
67
84
  Import-Module (Join-Path $packageRoot 'scripts\lib\AfyxPlatform.psm1') -Force
68
85
  Import-Module (Join-Path $packageRoot 'scripts\lib\AfyxSkillLifecycle.psm1') -Force -DisableNameChecking
69
- Import-Module (Join-Path $packageRoot 'scripts\lib\AfyxTerminal.psm1') -Force
70
86
  $terminal = New-AfyxTerminalContext
71
87
  $providerRegistry = @(Get-AfyxProviderRegistry)
72
88
  $providerIds = @($providerRegistry | ForEach-Object { [string]$_.provider })
@@ -414,6 +430,8 @@ function Read-InstallChoice([string]$Label) {
414
430
  function Install-ManagedSkillSafely([string]$Component, [string]$Name, [string]$Source, [string]$Target, [bool]$ReplaceExisting, [string]$InstallRoot = $SkillsRoot, [bool]$AuthorizeRepair = $false) {
415
431
  if ((Test-Path -LiteralPath $Target) -and -not $ReplaceExisting) { return 'skipped' }
416
432
  if ($WhatIfPreference) { Write-Host "WhatIf: would stage and install $Name at $Target"; return 'planned' }
433
+ $progressOperation = "skill:$Component`:$([guid]::NewGuid().ToString('N'))"
434
+ Write-AfyxInstallerProgress -OperationId $progressOperation -ComponentId $Component -Phase install -State running -Message "Installing $Name"
417
435
  Assert-AfyxSkillTarget -SkillsRoot $InstallRoot -Target $Target
418
436
  $parent = Split-Path -Parent $Target
419
437
  New-Item -ItemType Directory -Force -Path $parent | Out-Null
@@ -424,6 +442,10 @@ function Install-ManagedSkillSafely([string]$Component, [string]$Name, [string]$
424
442
  $planRepair = $controlPlan -and @($controlPlan.Components | Where-Object { $_.Id -eq $Component -and $_.Repair -eq 'REPAIR' }).Count -eq 1
425
443
  $authorized = $Force -or $componentActions.ContainsKey($Component) -or $planRepair -or $AuthorizeRepair
426
444
  Install-AfyxSkillTransaction -SkillsRoot $InstallRoot -Component $Component -Name $Name -Stage $stage -Target $Target -Owner afyx -Version (Get-AfyxSkillVersion -Directory $Source) -AuthorizeUnproven:$authorized
445
+ Write-AfyxInstallerProgress -OperationId $progressOperation -ComponentId $Component -Phase install -State completed -Message "Installed $Name; final verification pending"
446
+ } catch {
447
+ Write-AfyxInstallerProgress -OperationId $progressOperation -ComponentId $Component -Phase install -State failed -Message "Installation failed: $Name; inspect diagnostic logs"
448
+ throw
427
449
  } finally {
428
450
  if (Test-Path -LiteralPath $stage) { Remove-Item -LiteralPath $stage -Recurse -Force -ErrorAction SilentlyContinue }
429
451
  }
@@ -477,7 +499,10 @@ if ($PlanJson -or $ExpectedPlan) {
477
499
  $item = @($controlPlan.Components | Where-Object { $_.Id -eq $id })[0]
478
500
  $planRows += [ordered]@{
479
501
  id = $id; name = [string]$component.name; type = [string]$component.type
480
- currentState = [string]$state.State; desired = [bool]$item.Desired
502
+ currentState = [string]$state.State
503
+ # Match Resolve-ComponentAction: the Codex-only toolset is not a
504
+ # desired install when no Codex provider was selected or it is OFF.
505
+ desired = [bool]$item.Desired -and ($id -ne 'codex-usage-tracking' -or ('codex' -in $Provider -and -not $SkipUsageTracker))
481
506
  backendAction = [string]$actionDecisions[$id]; target = [string]$state.Path
482
507
  ownership = [string]$item.ActualOwnership; version = [string]$state.Version
483
508
  availableVersion = Get-AvailableVersion $id
@@ -819,11 +844,30 @@ function Invoke-AfyxInstallStage {
819
844
  [Parameter(Mandatory)][string]$Stage,
820
845
  [string]$Description = ''
821
846
  )
847
+ $progressComponent = switch ($Stage) {
848
+ 'Afyx Graph' { 'afyx-graph' }
849
+ 'Afyx Context Engine' { 'afyx-context' }
850
+ 'Afyx Forge Core' { 'afyx-forge' }
851
+ 'Usage Tracking' { 'codex-usage-tracking' }
852
+ default { '' }
853
+ }
854
+ $progressId = "runtime:$([guid]::NewGuid().ToString('N'))"
855
+ $progressPhase = if ($Description -match '^(update|repair|install)\b') { $Matches[1] } else { 'install' }
856
+ $reportProgress = { param([string]$state)
857
+ if ($env:AFYX_INSTALL_PROGRESS -eq '1') {
858
+ Write-AfyxInstallerProgress -OperationId $progressId -ComponentId $progressComponent -Phase $progressPhase -State $state -Message "$Stage - $Description"
859
+ }
860
+ }
861
+ & $reportProgress running
822
862
  if (-not $wizardMode -or -not $terminal.Ansi) {
823
- $output = & $Action 2>&1
824
- $success = [bool]$?
825
- $output | Out-Host
826
- return $success
863
+ try {
864
+ $global:LASTEXITCODE = 0
865
+ $output = & $Action 2>&1
866
+ $success = [bool]$? -and ($LASTEXITCODE -eq 0 -or $LASTEXITCODE -eq $null)
867
+ $output | Out-Host
868
+ & $reportProgress $(if ($success) { 'completed' } else { 'failed' })
869
+ return $success
870
+ } catch { & $reportProgress failed; throw }
827
871
  }
828
872
  $logRoot = Join-Path $AfyxInstallRoot 'logs'
829
873
  New-Item -ItemType Directory -Path $logRoot -Force | Out-Null
@@ -848,10 +892,12 @@ function Invoke-AfyxInstallStage {
848
892
  )
849
893
  $tailSummary = if ($lastLogLines.Count) { $lastLogLines[-1] } else { '' }
850
894
  $diagMsg = if ($failure) { $failure.Exception.Message } elseif ($tailSummary) { $tailSummary } else { "Process exited with code $LASTEXITCODE" }
895
+ & $reportProgress failed
851
896
  Write-AfyxStatus -Status FAILED -Name $Stage -Detail "$diagMsg; log: $logFile" -Terminal $terminal
852
897
  if ($failure) { throw $failure }
853
898
  else { throw "$Stage failed: $diagMsg (log: $logFile)" }
854
899
  } else {
900
+ & $reportProgress completed
855
901
  Write-AfyxStatus -Status HEALTHY -Name $Stage -Detail "completed successfully" -Terminal $terminal
856
902
  }
857
903
  return $success
package/install.sh CHANGED
@@ -2,7 +2,11 @@
2
2
  set -euo pipefail
3
3
 
4
4
  PACKAGE_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
5
+ if [[ $# -eq 0 && -t 0 && -t 1 && -z "${CI:-}" && "${AFYX_INSTALL_UI_OWNER:-}" != node ]] && command -v node >/dev/null 2>&1; then
6
+ exec node "$PACKAGE_ROOT/bin/afyx-engineering-kit.mjs" install
7
+ fi
5
8
  BUNDLED_EFFICIENT="$PACKAGE_ROOT/skills/efficient-coding"
9
+ source "$PACKAGE_ROOT/scripts/lib/afyx-installer-progress.sh"
6
10
  BUNDLED_ODOO="$PACKAGE_ROOT/skills/odoo-engineering"
7
11
  BUNDLED_EXPERT="$PACKAGE_ROOT/skills/afyx-engineering-expert"
8
12
  skills_root="${CODEX_SKILLS_ROOT:-$HOME/.agents/skills}"
@@ -542,13 +546,13 @@ efficient_result=skipped
542
546
  odoo_result=skipped
543
547
  expert_result=skipped
544
548
  if [[ "$efficient_action" == adopt ]]; then efficient_result="$(adopt_legacy_skill efficient-coding 'Efficient Coding' "$efficient_target")"
545
- elif [[ "$efficient_action" != skip ]]; then efficient_result="$(safe_skill_install efficient-coding 'Efficient Coding' "$BUNDLED_EFFICIENT" "$efficient_target" "$([[ "$efficient_action" == install ]] && printf false || printf true)")"; fi
549
+ elif [[ "$efficient_action" != skip ]]; then efficient_result="$(afyx_run_install_operation efficient-coding install "Installing efficient-coding" safe_skill_install efficient-coding 'Efficient Coding' "$BUNDLED_EFFICIENT" "$efficient_target" "$([[ "$efficient_action" == install ]] && printf false || printf true)")"; fi
546
550
  if [[ "$odoo_action" == adopt ]]; then odoo_result="$(adopt_legacy_skill odoo-engineering 'Odoo Engineering' "$odoo_target")"
547
- elif [[ "$odoo_action" != skip ]]; then odoo_result="$(safe_skill_install odoo-engineering 'Odoo Engineering' "$BUNDLED_ODOO" "$odoo_target" "$([[ "$odoo_action" == install ]] && printf false || printf true)")"; fi
551
+ elif [[ "$odoo_action" != skip ]]; then odoo_result="$(afyx_run_install_operation odoo-engineering install "Installing odoo-engineering" safe_skill_install odoo-engineering 'Odoo Engineering' "$BUNDLED_ODOO" "$odoo_target" "$([[ "$odoo_action" == install ]] && printf false || printf true)")"; fi
548
552
  if [[ "$expert_action" == adopt ]]; then
549
553
  printf 'Afyx Engineering Expert has no trusted legacy provenance and cannot be adopted.\n' >&2
550
554
  exit 1
551
- elif [[ "$expert_action" != skip ]]; then expert_result="$(safe_skill_install afyx-engineering-expert 'Afyx Engineering Expert' "$BUNDLED_EXPERT" "$expert_target" "$([[ "$expert_action" == install ]] && printf false || printf true)")"; fi
555
+ elif [[ "$expert_action" != skip ]]; then expert_result="$(afyx_run_install_operation afyx-engineering-expert install "Installing afyx-engineering-expert" safe_skill_install afyx-engineering-expert 'Afyx Engineering Expert' "$BUNDLED_EXPERT" "$expert_target" "$([[ "$expert_action" == install ]] && printf false || printf true)")"; fi
552
556
 
553
557
  replicate_provider_skill() {
554
558
  local id="$1" label="$2" source="$3" action="$4" root target replace result
@@ -568,7 +572,7 @@ replicate_provider_skill() {
568
572
  replace=true ;;
569
573
  *) printf 'Refusing to replace %s at provider skill root %s because ownership is %s.\n' "$label" "$root" "$AFYX_OWNERSHIP_STATE" >&2; exit 1 ;;
570
574
  esac
571
- result="$(safe_skill_install "$id" "$label" "$source" "$target" "$replace")"
575
+ result="$(afyx_run_install_operation "$id" install "Installing $label for provider" safe_skill_install "$id" "$label" "$source" "$target" "$replace")"
572
576
  printf '%s [%s]: %s\n' "$label" "$root" "$result"
573
577
  done
574
578
  }
@@ -587,7 +591,7 @@ if [[ "$graph_action" != skip ]]; then
587
591
  "$allow_dirty_source" && graph_args+=(--allow-dirty-source)
588
592
  if "$skip_graph_mcp" || "$skip_provider_configuration" || [[ ",$provider_list," != *,codex,* ]]; then graph_args+=(--skip-mcp); else graph_args+=(--configure-mcp); fi
589
593
  "$dry_run" && graph_args+=(--validate-only)
590
- bash "$PACKAGE_ROOT/scripts/install-afyx-graph.sh" "${graph_args[@]}"
594
+ afyx_run_install_operation afyx-graph "$graph_action" 'Preparing Afyx Graph runtime' bash "$PACKAGE_ROOT/scripts/install-afyx-graph.sh" "${graph_args[@]}"
591
595
  graph_result="$graph_action"
592
596
  fi
593
597
 
@@ -625,7 +629,7 @@ if [[ "$context_action" != skip ]]; then
625
629
  [[ "$context_action" == update ]] && context_args+=(--update)
626
630
  [[ "$context_action" == repair ]] && context_args+=(--repair)
627
631
  "$dry_run" && context_args+=(--validate-only)
628
- bash "$PACKAGE_ROOT/scripts/install-afyx-context.sh" "${context_args[@]}"
632
+ afyx_run_install_operation afyx-context "$context_action" 'Preparing Afyx Context runtime' bash "$PACKAGE_ROOT/scripts/install-afyx-context.sh" "${context_args[@]}"
629
633
  context_result="$context_action"
630
634
  fi
631
635
 
@@ -668,7 +672,7 @@ if [[ "$forge_action" != skip ]]; then
668
672
  [[ "$forge_action" == update ]] && forge_args+=(--update)
669
673
  [[ "$forge_action" == repair ]] && forge_args+=(--repair)
670
674
  "$dry_run" && forge_args+=(--validate-only)
671
- bash "$PACKAGE_ROOT/scripts/install-afyx-forge.sh" "${forge_args[@]}"
675
+ afyx_run_install_operation afyx-forge "$forge_action" 'Preparing Afyx Forge runtime' bash "$PACKAGE_ROOT/scripts/install-afyx-forge.sh" "${forge_args[@]}"
672
676
  forge_result="$forge_action"
673
677
  fi
674
678
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "afyx-engineering-kit",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.8",
4
4
  "description": "Universal cross-platform CLI installer and lifecycle manager for AFYX Engineering Kit",
5
5
  "type": "module",
6
6
  "main": "./bin/afyx-engineering-kit.mjs",
@@ -32,6 +32,8 @@
32
32
  "afyx-graph/afyx-graph.json",
33
33
  "afyx-graph/engine/release/afyx-graph-win32-x64.zip",
34
34
  "afyx-graph/engine/release/afyx-graph-linux-x64.tar.gz",
35
+ "afyx-graph/engine/release/afyx-graph-darwin-arm64.tar.gz",
36
+ "afyx-graph/engine/release/afyx-graph-darwin-x64.tar.gz",
35
37
  "afyx-graph/engine/release/SHA256SUMS",
36
38
  "afyx-graph/engine/release/RELEASE-MANIFEST.json",
37
39
  "afyx-graph/engine/scripts/distribution-product.json",