@zq-silk/yui 0.2.0 → 0.4.2

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 (208) hide show
  1. package/ARCHITECTURE.md +603 -133
  2. package/README.md +806 -31
  3. package/dist/agent/agent.js +2 -1
  4. package/dist/agent/argumentPolicy.js +3 -1
  5. package/dist/agent/launchEnvironment.js +106 -0
  6. package/dist/agent/managedRuntimeEnvironment.js +34 -0
  7. package/dist/brief/taskBrief.js +11 -1
  8. package/dist/cli/agentConfigurationPicker.js +287 -0
  9. package/dist/cli/commandCatalog.js +488 -60
  10. package/dist/cli/completion.js +146 -22
  11. package/dist/cli/helpRenderer.js +3 -1
  12. package/dist/cli/interactionCandidates.js +53 -15
  13. package/dist/cli/interactionPolicy.js +267 -30
  14. package/dist/cli/interactiveSelection.js +6 -2
  15. package/dist/cli/invocationRouter.js +5 -1
  16. package/dist/cli/operatorWizard.js +87 -0
  17. package/dist/cli/roleOptionCatalog.js +1 -0
  18. package/dist/cli/roleWizard.js +185 -21
  19. package/dist/cli/updateCommand.js +62 -19
  20. package/dist/cli/updateOrchestrator.js +539 -0
  21. package/dist/cli/updatePorts.js +1119 -0
  22. package/dist/cli/upgradeCommand.js +112 -0
  23. package/dist/cli.js +1420 -86
  24. package/dist/commands/agentCommands.js +146 -3
  25. package/dist/commands/configCommands.js +126 -0
  26. package/dist/commands/controllerCommands.js +365 -0
  27. package/dist/commands/globalRoleCommands.js +168 -126
  28. package/dist/commands/jobCommands.js +18 -8
  29. package/dist/commands/operatorCommands.js +159 -9
  30. package/dist/commands/profileCommands.js +203 -0
  31. package/dist/commands/projectCommands.js +650 -0
  32. package/dist/commands/roleConfiguration.js +85 -24
  33. package/dist/commands/roleRuntimeGuard.js +12 -0
  34. package/dist/commands/roleSkillValidation.js +47 -0
  35. package/dist/commands/taskActor.js +127 -0
  36. package/dist/commands/taskCommands.js +4201 -313
  37. package/dist/commands/taskCompletionGate.js +131 -0
  38. package/dist/commands/taskContextCommand.js +244 -30
  39. package/dist/commands/taskInputCommands.js +177 -59
  40. package/dist/commands/taskIntegrationCommands.js +303 -0
  41. package/dist/commands/taskOverviewCommand.js +363 -0
  42. package/dist/commands/taskRoleRuntimeStatus.js +125 -19
  43. package/dist/commands/textInput.js +15 -0
  44. package/dist/completion/completionInstaller.js +26 -22
  45. package/dist/config/yuiConfig.js +4 -3
  46. package/dist/context/dispatchContext.js +90 -38
  47. package/dist/context/roleSessionContext.js +119 -0
  48. package/dist/controller/claudeLifecycleHook.js +203 -0
  49. package/dist/controller/clientRuntime.js +408 -56
  50. package/dist/controller/codexLifecycleHook.js +108 -0
  51. package/dist/controller/controller.js +1089 -32
  52. package/dist/controller/domainIdentity.js +505 -0
  53. package/dist/controller/ephemeralResourceReaper.js +131 -0
  54. package/dist/controller/fileSchedulerStoreAdapter.js +2153 -103
  55. package/dist/controller/providerHookRunFence.js +127 -0
  56. package/dist/controller/resourceCleanupLinux.js +286 -0
  57. package/dist/controller/resourceInventory.js +531 -0
  58. package/dist/controller/resourceInventoryLinux.js +610 -0
  59. package/dist/controller/runtime.js +629 -10
  60. package/dist/controller/runtimeEventInbox.js +564 -0
  61. package/dist/controller/runtimeEventProcessor.js +248 -0
  62. package/dist/controller/runtimeLaunchCoordinator.js +477 -0
  63. package/dist/controller/sessionNotify.js +121 -78
  64. package/dist/coordination/deadlineScheduler.js +15 -0
  65. package/dist/coordination/mailboxScheduler.js +108 -0
  66. package/dist/coordination/workMailbox.js +329 -0
  67. package/dist/coordination/workMailboxQueue.js +86 -0
  68. package/dist/core/controllerClient.js +19 -5
  69. package/dist/core/controllerEndpoint.js +37 -0
  70. package/dist/core/controllerServer.js +218 -10
  71. package/dist/core/protocol.js +6 -2
  72. package/dist/decision/decision.js +2 -1
  73. package/dist/doctor/doctor.js +681 -32
  74. package/dist/domain/validation.js +53 -0
  75. package/dist/errors/cliError.js +5 -3
  76. package/dist/event/taskEvent.js +7 -3
  77. package/dist/execution/codexThreadNaming.js +160 -0
  78. package/dist/execution/executionGroup.js +579 -0
  79. package/dist/executor/agentAdapter.js +255 -40
  80. package/dist/executor/agentConfigurationCatalog.js +326 -0
  81. package/dist/executor/agentConfigurationProbe.js +506 -0
  82. package/dist/executor/agentExecutor.js +625 -10
  83. package/dist/executor/codexConfigConflict.js +290 -0
  84. package/dist/executor/effectiveLaunch.js +340 -0
  85. package/dist/executor/executorRegistry.js +238 -36
  86. package/dist/executor/fileRoleLaunchPlanner.js +550 -40
  87. package/dist/executor/turnCompletion.js +126 -0
  88. package/dist/input/inputRequest.js +30 -9
  89. package/dist/integration/changeSet.js +36 -0
  90. package/dist/integration/checkResult.js +24 -0
  91. package/dist/integration/gitIntegrationService.js +695 -0
  92. package/dist/integration/integrationAttempt.js +142 -0
  93. package/dist/interaction/operatorPresentation.js +96 -0
  94. package/dist/lifecycle/canonicalLifecycleEvent.js +342 -0
  95. package/dist/lifecycle/exactRunTerminalization.js +572 -0
  96. package/dist/lifecycle/providerLifecycleMapping.js +190 -0
  97. package/dist/lifecycle/taskRoleSessionReset.js +124 -0
  98. package/dist/message/message.js +23 -7
  99. package/dist/milestone/milestone.js +2 -1
  100. package/dist/operator/operatorSessionHistory.js +124 -0
  101. package/dist/output/agentConfigurationPresentation.js +43 -0
  102. package/dist/output/rolePresentation.js +34 -10
  103. package/dist/output/terminal.js +8 -0
  104. package/dist/output/timePresentation.js +55 -0
  105. package/dist/profile/agentProfile.js +128 -0
  106. package/dist/repository/gitWorkspace.js +578 -24
  107. package/dist/repository/project.js +213 -0
  108. package/dist/repository/taskWorkspaceCoordinator.js +392 -0
  109. package/dist/repository/taskWorkspacePreparer.js +1688 -191
  110. package/dist/review/reviewConfig.js +11 -0
  111. package/dist/review/reviewRound.js +399 -0
  112. package/dist/review/taskFinalReviewContract.js +90 -0
  113. package/dist/role/role.js +124 -23
  114. package/dist/run/agentRun.js +155 -12
  115. package/dist/run/runIdentity.js +82 -0
  116. package/dist/runtime/exactControlPlane.js +472 -0
  117. package/dist/runtime/index.js +8 -0
  118. package/dist/runtime/lifecycleReservation.js +38 -0
  119. package/dist/runtime/ports.js +11 -0
  120. package/dist/runtime/preallocatedNativeSession.js +13 -0
  121. package/dist/runtime/promptEnvelope.js +30 -0
  122. package/dist/runtime/runtimeBinding.js +31 -0
  123. package/dist/runtime/runtimeOwner.js +14 -0
  124. package/dist/runtime/sessionLaunchRequest.js +62 -0
  125. package/dist/runtime/sessionTitle.js +54 -0
  126. package/dist/runtime/taskRuntimeIsolation.js +643 -0
  127. package/dist/runtime/tmuxAdapters.js +315 -0
  128. package/dist/runtime/turnCompletion.js +3 -0
  129. package/dist/runtime/validation.js +23 -0
  130. package/dist/scheduler/activeRoleRunDelivery.js +342 -32
  131. package/dist/scheduler/activeTaskProgress.js +63 -0
  132. package/dist/scheduler/leaderFailure.js +2 -1
  133. package/dist/scheduler/leaderWakeupProcessor.js +307 -66
  134. package/dist/scheduler/operatorInputNotificationProcessor.js +109 -46
  135. package/dist/scheduler/operatorNotification.js +44 -2
  136. package/dist/scheduler/ports.js +28 -1
  137. package/dist/scheduler/roleRunLiveness.js +131 -25
  138. package/dist/scheduler/roleRunStall.js +951 -0
  139. package/dist/scheduler/taskExecutionProjection.js +544 -0
  140. package/dist/scheduler/wakeupQueue.js +3 -0
  141. package/dist/setup/setupCommand.js +302 -52
  142. package/dist/storage/compatibleTaskStore.js +102 -0
  143. package/dist/storage/migration/baseline.js +78 -0
  144. package/dist/storage/migration/classifier.js +51 -0
  145. package/dist/storage/migration/compatibleCodec.js +53 -0
  146. package/dist/storage/migration/engine.js +147 -0
  147. package/dist/storage/migration/index.js +33 -0
  148. package/dist/storage/migration/planner.js +154 -0
  149. package/dist/storage/migration/productionRegistry.js +486 -0
  150. package/dist/storage/migration/registry.js +169 -0
  151. package/dist/storage/migration/report.js +54 -0
  152. package/dist/storage/migration/types.js +31 -0
  153. package/dist/storage/storageSchema.js +147 -123
  154. package/dist/storage/storageVersions.js +11 -0
  155. package/dist/storage/taskStore.js +1793 -197
  156. package/dist/storage/upgrade/homeClassification.js +156 -0
  157. package/dist/storage/upgrade/homeMigrationTarget.js +595 -0
  158. package/dist/storage/upgrade/offlineUpgradeInventory.js +315 -0
  159. package/dist/storage/upgrade/productionMigrationRegistry.js +6 -0
  160. package/dist/storage/upgrade/recordVersionScan.js +176 -0
  161. package/dist/storage/upgrade/recordVersions.js +159 -0
  162. package/dist/storage/upgrade/switchProgress.js +80 -0
  163. package/dist/storage/upgrade/upgradeOrchestrator.js +948 -0
  164. package/dist/storage/upgrade/upgradeReceipt.js +161 -0
  165. package/dist/storage/upgradeCoordination.js +186 -0
  166. package/dist/storage/upgradeFence.js +366 -0
  167. package/dist/task/task.js +132 -26
  168. package/dist/task/taskRecordReference.js +66 -0
  169. package/dist/tmux/commandExecutor.js +75 -2
  170. package/dist/tmux/tmuxManager.js +747 -49
  171. package/dist/version.js +23 -0
  172. package/dist/web/assets/assetManifest.js +62 -0
  173. package/dist/web/assets/client/app.js +631 -0
  174. package/dist/web/assets/client/components.js +605 -0
  175. package/dist/web/assets/client/dom.js +14 -0
  176. package/dist/web/assets/client/format.js +28 -0
  177. package/dist/web/assets/client/i18n.js +494 -0
  178. package/dist/web/assets/client/markdown.js +114 -0
  179. package/dist/web/assets/client/theme.js +32 -0
  180. package/dist/web/assets/client/view.js +458 -0
  181. package/dist/web/assets/fontData.js +12 -0
  182. package/dist/web/assets/fonts.js +12 -0
  183. package/dist/web/assets/shell.js +114 -0
  184. package/dist/web/assets/styles/cards.js +135 -0
  185. package/dist/web/assets/styles/layout.js +47 -0
  186. package/dist/web/assets/styles/markdown.js +29 -0
  187. package/dist/web/assets/styles/responsive.js +39 -0
  188. package/dist/web/assets/styles/tokens.js +101 -0
  189. package/dist/web/assets/styles/widgets.js +147 -0
  190. package/dist/web/tmuxWebTerminal.js +158 -0
  191. package/dist/web/webServer.js +463 -0
  192. package/dist/web/webSnapshot.js +148 -0
  193. package/dist/workItem/workItem.js +642 -23
  194. package/dist/workspace/gitChangeSetCapture.js +86 -0
  195. package/dist/workspace/workItemChangeSetManager.js +445 -0
  196. package/dist/worktree/managedWorkspace.js +202 -0
  197. package/docs/task-local-identity.md +62 -0
  198. package/i18n/README.zh-CN.md +406 -31
  199. package/package.json +10 -2
  200. package/skills/yui-leader/SKILL.md +601 -39
  201. package/skills/yui-operator/SKILL.md +255 -34
  202. package/skills/yui-reviewer/SKILL.md +57 -0
  203. package/skills/yui-worker/SKILL.md +214 -17
  204. package/dist/commands/repositoryCommands.js +0 -86
  205. package/dist/operator/operatorContext.js +0 -66
  206. package/dist/repository/repository.js +0 -55
  207. package/dist/scheduler/archivedTaskRuntime.js +0 -12
  208. package/dist/worktree/roleWorkspace.js +0 -62
@@ -0,0 +1,53 @@
1
+ export function requireIdentity(value, label) {
2
+ const normalized = requireText(value, label);
3
+ if ([".", "..", "__proto__", "prototype", "constructor"].includes(normalized)
4
+ || /[\/\\\0]/u.test(normalized)) {
5
+ throw new Error(`${label} is invalid.`);
6
+ }
7
+ return normalized;
8
+ }
9
+ export function requireText(value, label) {
10
+ if (typeof value !== "string" || value.includes("\0")) {
11
+ throw new Error(`${label} is invalid.`);
12
+ }
13
+ const normalized = value.trim();
14
+ if (normalized.length === 0)
15
+ throw new Error(`${label} is required.`);
16
+ return normalized;
17
+ }
18
+ export function optionalText(value, label) {
19
+ return value === undefined ? undefined : requireText(value, label);
20
+ }
21
+ export function requireTimestamp(value, label) {
22
+ if (typeof value !== "string" || !Number.isFinite(Date.parse(value))) {
23
+ throw new Error(`${label} must be an ISO timestamp.`);
24
+ }
25
+ return value;
26
+ }
27
+ export function requirePositiveInteger(value, label) {
28
+ if (!Number.isSafeInteger(value) || value < 1) {
29
+ throw new Error(`${label} must be a positive integer.`);
30
+ }
31
+ return value;
32
+ }
33
+ export function normalizedUniqueText(values, label) {
34
+ if (!Array.isArray(values))
35
+ throw new Error(`${label} must be an array.`);
36
+ const normalized = values.map((value) => requireText(value, label));
37
+ if (new Set(normalized).size !== normalized.length) {
38
+ throw new Error(`${label} must be unique.`);
39
+ }
40
+ return Object.freeze(normalized);
41
+ }
42
+ export function normalizedUniqueIdentities(values, label) {
43
+ if (!Array.isArray(values))
44
+ throw new Error(`${label} must be an array.`);
45
+ const normalized = values.map((value) => requireIdentity(value, label));
46
+ if (new Set(normalized).size !== normalized.length) {
47
+ throw new Error(`${label} must be unique.`);
48
+ }
49
+ return Object.freeze(normalized);
50
+ }
51
+ export function cloneJson(value) {
52
+ return JSON.parse(JSON.stringify(value));
53
+ }
@@ -9,17 +9,19 @@ const EXIT_CODES = {
9
9
  export class CliError extends Error {
10
10
  code;
11
11
  helpText;
12
+ details;
12
13
  exitCode;
13
- constructor(code, message, helpText) {
14
+ constructor(code, message, helpText, details = {}) {
14
15
  super(message);
15
16
  this.code = code;
16
17
  this.helpText = helpText;
18
+ this.details = details;
17
19
  this.name = "CliError";
18
20
  this.exitCode = EXIT_CODES[code];
19
21
  }
20
22
  }
21
- export function usageError(message, helpText) {
22
- return new CliError("USAGE_ERROR", message, helpText);
23
+ export function usageError(message, helpText, details = {}) {
24
+ return new CliError("USAGE_ERROR", message, helpText, details);
23
25
  }
24
26
  export function taskNotFound(id) {
25
27
  return new CliError("TASK_NOT_FOUND", `Task not found: ${id}`);
@@ -1,11 +1,15 @@
1
- export function createTaskEvent(id, type, payload, now) {
2
- return {
3
- schemaVersion: 1,
1
+ import { validateTaskRecordReference } from "../task/taskRecordReference.js";
2
+ export function createTaskEvent(id, taskId, type, payload, now) {
3
+ const event = {
4
+ schemaVersion: 2,
4
5
  id: requireText(id, "Task event id"),
6
+ taskId: requireText(taskId, "Task event Task id"),
5
7
  type: requireText(type, "Task event type"),
6
8
  payload: normalizePayload(payload),
7
9
  createdAt: now.toISOString()
8
10
  };
11
+ validateTaskRecordReference({ taskId: event.taskId, localId: event.id }, "event");
12
+ return event;
9
13
  }
10
14
  /**
11
15
  * Builds the next Event history without mutating or replacing an existing entry.
@@ -0,0 +1,160 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createInterface } from "node:readline";
3
+ import { YUI_VERSION } from "../version.js";
4
+ const DEFAULT_TIMEOUT_MS = 1_000;
5
+ export async function setCodexThreadName(request) {
6
+ const timeoutMs = threadNameTimeout(request.timeoutMs);
7
+ const client = await CodexNamingClient.start(request.command, request.environment, request.baseArgs ?? [], timeoutMs);
8
+ try {
9
+ await withTimeout(client.request("thread/name/set", {
10
+ threadId: requiredText(request.threadId, "Codex thread id"),
11
+ name: requiredThreadName(request.name)
12
+ }), timeoutMs, "Timed out setting Codex thread name.");
13
+ }
14
+ finally {
15
+ client.close();
16
+ }
17
+ }
18
+ class CodexNamingClient {
19
+ child;
20
+ #pending = new Map();
21
+ #stderr = [];
22
+ #nextId = 1;
23
+ #closed = false;
24
+ constructor(child) {
25
+ this.child = child;
26
+ const output = createInterface({ input: child.stdout });
27
+ output.on("line", (line) => { this.#receive(line); });
28
+ child.stderr.setEncoding("utf8");
29
+ child.stderr.on("data", (chunk) => {
30
+ this.#stderr.push(chunk);
31
+ if (this.#stderr.join("").length > 16_384)
32
+ this.#stderr.shift();
33
+ });
34
+ child.on("error", (error) => { this.#failAll(error); });
35
+ child.on("exit", (code, signal) => {
36
+ if (this.#closed)
37
+ return;
38
+ const detail = this.#stderr.join("").trim();
39
+ this.#failAll(new Error(`Codex App Server exited (${code ?? signal ?? "unknown"})${detail.length === 0 ? "" : `: ${detail}`}`));
40
+ });
41
+ }
42
+ static async start(command, environment, baseArgs, timeoutMs) {
43
+ const client = new CodexNamingClient(spawn(command, [...baseArgs, "app-server", "--stdio"], { env: environment, stdio: ["pipe", "pipe", "pipe"] }));
44
+ try {
45
+ await withTimeout(client.request("initialize", {
46
+ clientInfo: { name: "yui", title: "Yui", version: YUI_VERSION },
47
+ capabilities: {
48
+ experimentalApi: true,
49
+ requestAttestation: false
50
+ }
51
+ }), timeoutMs, "Timed out initializing Codex App Server for thread naming.");
52
+ client.notify("initialized", {});
53
+ return client;
54
+ }
55
+ catch (error) {
56
+ client.close();
57
+ throw error;
58
+ }
59
+ }
60
+ request(method, params) {
61
+ if (this.#closed)
62
+ return Promise.reject(new Error("Codex App Server is closed."));
63
+ const id = this.#nextId++;
64
+ return new Promise((resolve, reject) => {
65
+ this.#pending.set(id, { resolve, reject });
66
+ this.#write({ id, method, params });
67
+ });
68
+ }
69
+ notify(method, params) {
70
+ this.#write({ method, params });
71
+ }
72
+ close() {
73
+ if (this.#closed)
74
+ return;
75
+ this.#closed = true;
76
+ this.child.kill("SIGTERM");
77
+ this.#failAll(new Error("Codex App Server closed."));
78
+ }
79
+ #write(value) {
80
+ this.child.stdin.write(`${JSON.stringify(value)}\n`);
81
+ }
82
+ #receive(line) {
83
+ let message;
84
+ try {
85
+ message = object(JSON.parse(line), "Codex App Server message");
86
+ }
87
+ catch (error) {
88
+ this.#failAll(error instanceof Error ? error : new Error(String(error)));
89
+ return;
90
+ }
91
+ if (typeof message.id !== "number")
92
+ return;
93
+ const pending = this.#pending.get(message.id);
94
+ if (pending === undefined) {
95
+ if (typeof message.method === "string") {
96
+ this.#write({
97
+ id: message.id,
98
+ error: { code: -32601, message: `Unsupported App Server request: ${message.method}` }
99
+ });
100
+ }
101
+ return;
102
+ }
103
+ this.#pending.delete(message.id);
104
+ if (message.error !== undefined) {
105
+ const error = object(message.error, "Codex App Server error");
106
+ pending.reject(new Error(typeof error.message === "string" ? error.message : "Codex App Server request failed."));
107
+ }
108
+ else {
109
+ pending.resolve(object(message.result, "Codex App Server result"));
110
+ }
111
+ }
112
+ #failAll(error) {
113
+ for (const pending of this.#pending.values())
114
+ pending.reject(error);
115
+ this.#pending.clear();
116
+ }
117
+ }
118
+ function object(value, label) {
119
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
120
+ throw new Error(`${label} is invalid.`);
121
+ }
122
+ return value;
123
+ }
124
+ function requiredText(value, label) {
125
+ if (typeof value !== "string" || value.trim().length === 0) {
126
+ throw new Error(`${label} is invalid.`);
127
+ }
128
+ return value;
129
+ }
130
+ function requiredThreadName(value) {
131
+ if (typeof value !== "string" || value.includes("\0")) {
132
+ throw new Error("Codex thread name is invalid.");
133
+ }
134
+ const normalized = value.trim();
135
+ if (normalized.length === 0 || normalized.length > 1_024) {
136
+ throw new Error("Codex thread name is invalid.");
137
+ }
138
+ return normalized;
139
+ }
140
+ function threadNameTimeout(value) {
141
+ if (value === undefined)
142
+ return DEFAULT_TIMEOUT_MS;
143
+ if (!Number.isInteger(value) || Number(value) < 1 || Number(value) > 10_000) {
144
+ throw new Error("Codex thread name timeout is invalid.");
145
+ }
146
+ return Number(value);
147
+ }
148
+ async function withTimeout(promise, timeoutMs, message) {
149
+ let timer;
150
+ const timeout = new Promise((_resolve, reject) => {
151
+ timer = setTimeout(() => { reject(new Error(message)); }, timeoutMs);
152
+ });
153
+ try {
154
+ return await Promise.race([promise, timeout]);
155
+ }
156
+ finally {
157
+ if (timer !== undefined)
158
+ clearTimeout(timer);
159
+ }
160
+ }