@zq-silk/yui 0.15.3 → 0.15.6

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 (41) hide show
  1. package/dist/agent/managedRuntimeEnvironment.js +3 -0
  2. package/dist/cli.js +35 -127
  3. package/dist/commands/executionAuditCommands.js +6 -0
  4. package/dist/commands/taskContextCommand.js +4 -2
  5. package/dist/context/sessionBootstrapManifest.js +12 -21
  6. package/dist/controller/clientRuntime.js +1 -1
  7. package/dist/controller/fileSchedulerStoreAdapter.js +270 -162
  8. package/dist/controller/runtimeEventInbox.js +8 -0
  9. package/dist/controller/runtimeEventProcessor.js +31 -4
  10. package/dist/controller/runtimeHookTurnFence.js +101 -62
  11. package/dist/controller/runtimeLaunchCoordinator.js +38 -12
  12. package/dist/controller/runtimeObservationHook.js +17 -1
  13. package/dist/controller/structuredProviderObservation.js +39 -27
  14. package/dist/core/controllerClient.js +5 -0
  15. package/dist/core/controllerServer.js +7 -4
  16. package/dist/domain/agentResultTransport.js +2 -2
  17. package/dist/executor/agentExecutor.js +22 -38
  18. package/dist/executor/executorRegistry.js +16 -5
  19. package/dist/executor/fileRoleLaunchPlanner.js +22 -28
  20. package/dist/lifecycle/exactTurnTerminalization.js +3 -3
  21. package/dist/observability/executionAudit.js +12 -0
  22. package/dist/repository/executionLaneGitSnapshot.js +4 -3
  23. package/dist/repository/taskWorkspacePreparer.js +12 -4
  24. package/dist/review/taskFinalReviewContract.js +13 -32
  25. package/dist/runtime/agentError.js +299 -12
  26. package/dist/runtime/agentHost.js +419 -41
  27. package/dist/runtime/builtinAgentDrivers.js +5 -0
  28. package/dist/runtime/index.js +1 -1
  29. package/dist/runtime/ports.js +16 -2
  30. package/dist/runtime/providerRuntimeIdentity.js +34 -28
  31. package/dist/runtime/runtimeCoherence.js +91 -0
  32. package/dist/runtime/runtimeObservation.js +8 -5
  33. package/dist/runtime/structuredProviderHost.js +53 -44
  34. package/dist/runtime/tmuxAdapters.js +72 -43
  35. package/dist/scheduler/activeRoleTurnDelivery.js +59 -11
  36. package/dist/scheduler/leaderWakeupProcessor.js +61 -7
  37. package/dist/storage/sqliteSchema.js +9 -0
  38. package/dist/storage/storageVersions.js +1 -1
  39. package/dist/turn/turn.js +7 -1
  40. package/package.json +1 -1
  41. package/dist/runtime/exactControlPlane.js +0 -232
@@ -1,232 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { realpathSync } from "node:fs";
3
- import { resolve } from "node:path";
4
- import { callController as defaultCallController } from "../core/controllerClient.js";
5
- import { inspectStorageSchema } from "../storage/storageSchema.js";
6
- import { yuiVersionIdentity } from "../version.js";
7
- export const EXACT_CONTROL_ARGUMENT = "--yui-control";
8
- export const YUI_CONTROL_PLANE_DESCRIPTOR = "YUI_CONTROL_PLANE_DESCRIPTOR";
9
- export function createExactControlPlaneDescriptor(input) {
10
- const identity = validateVersionIdentity(input.identity ?? yuiVersionIdentity());
11
- return Object.freeze({
12
- schemaVersion: 1,
13
- kind: "yui-control-plane",
14
- executable: canonicalPath(input.executable),
15
- cliEntry: canonicalPath(input.cliEntry),
16
- yuiHome: canonicalPath(input.yuiHome),
17
- identity: Object.freeze({ ...identity }),
18
- ...(input.buildId === undefined ? {} : { buildId: input.buildId }),
19
- ...(input.activeReleaseDigest === undefined
20
- ? {}
21
- : { activeReleaseDigest: input.activeReleaseDigest })
22
- });
23
- }
24
- export function serializeExactDescriptor(descriptor) {
25
- return JSON.stringify(descriptor);
26
- }
27
- export function parseExactControlPlaneDescriptor(value) {
28
- const record = parseDescriptorRecord(value);
29
- assertDescriptorKind(record, "yui-control-plane");
30
- if (record.schemaVersion !== 1) {
31
- throw new Error("Exact control-plane descriptor schema version is invalid.");
32
- }
33
- return createExactControlPlaneDescriptor({
34
- executable: requireText(record.executable, "Control-plane executable"),
35
- cliEntry: requireText(record.cliEntry, "Control-plane CLI entry"),
36
- yuiHome: requireText(record.yuiHome, "Control-plane YUI_HOME"),
37
- identity: validateVersionIdentity(record.identity),
38
- ...(typeof record.buildId !== "string" ? {} : { buildId: record.buildId }),
39
- ...(typeof record.activeReleaseDigest !== "string"
40
- ? {}
41
- : { activeReleaseDigest: record.activeReleaseDigest })
42
- });
43
- }
44
- export function exactControlPlaneDigest(descriptor) {
45
- return createHash("sha256").update(serializeExactDescriptor(descriptor)).digest("hex");
46
- }
47
- export function extractExactControlArgument(args) {
48
- const later = args.indexOf(EXACT_CONTROL_ARGUMENT);
49
- if (later < 0)
50
- return { args: [...args] };
51
- if (later !== 0) {
52
- return {
53
- args: [...args],
54
- error: `${EXACT_CONTROL_ARGUMENT} must be the first CLI argument.`
55
- };
56
- }
57
- const digest = args[1];
58
- if (digest === undefined || !/^[a-f0-9]{64}$/u.test(digest)) {
59
- return {
60
- args: args.slice(2),
61
- error: "Exact control-plane digest is invalid."
62
- };
63
- }
64
- return { digest, args: args.slice(2) };
65
- }
66
- /**
67
- * One read-only gate shared by every managed Task control command. It verifies
68
- * the frozen executable/CLI/Home/digest, protocol and storage identity,
69
- * on-disk schema, and any live Controller before command routing may construct
70
- * a writable store. Package version alone may advance at the same managed path
71
- * so an existing Session can cross an explicitly compatible in-place update.
72
- */
73
- export async function assertExactControlPlanePreflight(input, options = {}) {
74
- const descriptor = parseExactControlPlaneDescriptor(input.serializedDescriptor);
75
- const frozenDigest = exactControlPlaneDigest(descriptor);
76
- const requestedDigest = requireDigest(input.digest);
77
- if (frozenDigest !== requestedDigest) {
78
- throw new Error("Exact control-plane invocation names another runtime than this Session's frozen "
79
- + `descriptor (requested ${requestedDigest}, Session ${frozenDigest}). `
80
- + "Yui no longer pins package identity into a Session entry point: invoke the "
81
- + "ordinary command for this Session, or start a new Session when the Session "
82
- + "itself must move to a different runtime.");
83
- }
84
- assertSamePath(descriptor.executable, input.actualExecutable, "Control-plane executable");
85
- assertSamePath(descriptor.cliEntry, input.actualCliEntry, "Control-plane CLI entry");
86
- assertSamePath(descriptor.yuiHome, input.actualHome, "Control-plane YUI_HOME");
87
- // A frozen descriptor can only assert what cannot legitimately change for a
88
- // Session: which Home it belongs to, and which installation launched it. The
89
- // protocol and storage numbers it also captured describe the world at launch
90
- // time, and Yui upgrades that world on purpose. Asking today's Home to still
91
- // match yesterday's snapshot would silence a healthy Session's callbacks the
92
- // moment a migration lands, so runtime coherence is proven against the
93
- // current CLI, Home, and Controller instead.
94
- await assertCompatibleControlPlanePreflight({ actualHome: descriptor.yuiHome }, options);
95
- return descriptor;
96
- }
97
- /**
98
- * Compatibility gate for an ordinary `yui` invocation inside a managed
99
- * Session. The Session Manifest and durable runtime state authenticate the
100
- * actor separately; this gate proves that the current CLI can safely share the
101
- * Home with its storage and Controller without pinning package/build identity.
102
- */
103
- export async function assertCompatibleControlPlanePreflight(input, options = {}) {
104
- const home = canonicalPath(input.actualHome);
105
- const identity = validateVersionIdentity(options.identity ?? yuiVersionIdentity());
106
- const storage = (options.inspectStorage ?? inspectStorageSchema)(home);
107
- if (storage.status !== "current") {
108
- throw new Error(`Managed control-plane storage is not current: ${storage.status}.`);
109
- }
110
- if (storage.currentVersion !== identity.storageVersion) {
111
- throw new Error("Managed control-plane storage version is incompatible "
112
- + `(expected ${identity.storageVersion}, found `
113
- + `${storage.currentVersion ?? "unknown"}).`);
114
- }
115
- if (options.checkController !== false) {
116
- const call = options.callController ?? defaultCallController;
117
- try {
118
- const status = await call(home, "controller.status", {});
119
- assertControllerContinuityIdentity(status, identity);
120
- }
121
- catch (error) {
122
- if (!isDefinitelyNotRunning(error))
123
- throw error;
124
- }
125
- }
126
- return identity;
127
- }
128
- export function assertControllerStatusIdentity(status, expected = yuiVersionIdentity()) {
129
- if (!isRecord(status) || status.running !== true) {
130
- throw new Error("Controller status does not describe a running Controller.");
131
- }
132
- assertControllerField(status.protocolVersion, expected.controllerProtocolVersion, "protocol");
133
- assertControllerField(status.version, expected.version, "version");
134
- assertControllerField(status.storageVersion, expected.storageVersion, "storage version");
135
- assertControllerField(status.minimumStorageVersion, expected.minimumStorageVersion, "minimum storage migration version");
136
- }
137
- function validateVersionIdentity(value) {
138
- if (!isRecord(value))
139
- throw new Error("Yui version identity is invalid.");
140
- const version = requireText(value.version, "Yui version");
141
- const controllerProtocolVersion = requireVersion(value.controllerProtocolVersion, "Controller protocol version");
142
- const storageVersion = requireVersion(value.storageVersion, "Storage version");
143
- const minimumStorageVersion = requireVersion(value.minimumStorageVersion, "Minimum storage migration version");
144
- if (minimumStorageVersion > storageVersion) {
145
- throw new Error("Minimum storage migration version cannot exceed the current storage version.");
146
- }
147
- return {
148
- version,
149
- controllerProtocolVersion,
150
- storageVersion,
151
- minimumStorageVersion
152
- };
153
- }
154
- function assertControllerContinuityIdentity(status, expected) {
155
- if (!isRecord(status) || status.running !== true) {
156
- throw new Error("Controller status does not describe a running Controller.");
157
- }
158
- if (typeof status.version !== "string" || status.version.trim().length === 0) {
159
- throw new Error("Controller version is invalid at the managed continuity gate.");
160
- }
161
- assertControllerField(status.protocolVersion, expected.controllerProtocolVersion, "protocol");
162
- assertControllerField(status.storageVersion, expected.storageVersion, "storage version");
163
- }
164
- function assertControllerField(actual, expected, label) {
165
- if (actual !== expected) {
166
- throw new Error(`Controller ${label} is incompatible with the exact control plane `
167
- + `(expected ${expected}, found ${typeof actual === "string" || typeof actual === "number" ? actual : "unknown"}). `
168
- + "Run controller restart through the matching exact control-plane invocation "
169
- + "before writing new Task records.");
170
- }
171
- }
172
- function assertSamePath(expected, actual, label) {
173
- const normalized = canonicalPath(actual);
174
- if (expected !== normalized) {
175
- throw new Error(`${label} does not match the frozen control plane (expected ${expected}, found ${normalized}).`);
176
- }
177
- }
178
- function parseDescriptorRecord(value) {
179
- let parsed;
180
- try {
181
- parsed = JSON.parse(requireText(value, "Exact descriptor"));
182
- }
183
- catch (error) {
184
- throw new Error("Exact descriptor is not valid JSON.", { cause: error });
185
- }
186
- if (!isRecord(parsed))
187
- throw new Error("Exact descriptor must be an object.");
188
- return parsed;
189
- }
190
- function assertDescriptorKind(value, expected) {
191
- if (value.kind !== expected) {
192
- throw new Error(`Exact descriptor kind is invalid: expected ${expected}, found `
193
- + `${typeof value.kind === "string" ? value.kind : "unknown"}.`);
194
- }
195
- }
196
- function requireText(value, label) {
197
- if (typeof value !== "string" || value.length === 0 || value.includes("\0")) {
198
- throw new Error(`${label} is invalid.`);
199
- }
200
- return value;
201
- }
202
- function requireDigest(value) {
203
- const digest = requireText(value, "Control-plane digest");
204
- if (!/^[a-f0-9]{64}$/u.test(digest)) {
205
- throw new Error("Control-plane digest is invalid.");
206
- }
207
- return digest;
208
- }
209
- function requireVersion(value, label) {
210
- if (!Number.isSafeInteger(value) || value < 1) {
211
- throw new Error(`${label} is invalid.`);
212
- }
213
- return value;
214
- }
215
- function canonicalPath(value) {
216
- const absolute = resolve(requireText(value, "Path"));
217
- try {
218
- return realpathSync(absolute);
219
- }
220
- catch {
221
- return absolute;
222
- }
223
- }
224
- function shellQuote(value) {
225
- return `'${value.replaceAll("'", "'\"'\"'")}'`;
226
- }
227
- function isRecord(value) {
228
- return typeof value === "object" && value !== null && !Array.isArray(value);
229
- }
230
- function isDefinitelyNotRunning(error) {
231
- return isRecord(error) && error.code === "CONTROLLER_NOT_RUNNING";
232
- }