acryl 0.1.13 → 0.1.14

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 (53) hide show
  1. package/lib/bin.js +325 -4
  2. package/lib/bin.js.map +1 -1
  3. package/lib/index.js +256 -3
  4. package/lib/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/lib/types/bin.d.ts +0 -4
  7. package/lib/types/cli/grammar.d.ts +0 -10
  8. package/lib/types/cli/node-launcher.d.ts +0 -9
  9. package/lib/types/cli/run.d.ts +0 -32
  10. package/lib/types/host/direct.d.ts +0 -18
  11. package/lib/types/index.d.ts +0 -3
  12. package/lib/types/markdown.d.ts +0 -28
  13. package/lib/types/render.d.ts +0 -78
  14. package/lib/types/sessionId.d.ts +0 -12
  15. package/lib/types/tui/CustomEditor.d.ts +0 -51
  16. package/lib/types/tui/Spinner.d.ts +0 -18
  17. package/lib/types/tui/TuiApp.d.ts +0 -64
  18. package/lib/types/tui/actions.d.ts +0 -85
  19. package/lib/types/tui/agentPresets/AgentPresetsOverlay.d.ts +0 -19
  20. package/lib/types/tui/agentPresets/types.d.ts +0 -18
  21. package/lib/types/tui/bannerText.d.ts +0 -19
  22. package/lib/types/tui/commands.d.ts +0 -54
  23. package/lib/types/tui/context/ContextOverlay.d.ts +0 -17
  24. package/lib/types/tui/fileIndex.d.ts +0 -17
  25. package/lib/types/tui/fileMention.d.ts +0 -31
  26. package/lib/types/tui/interaction/ApprovalOverlay.d.ts +0 -18
  27. package/lib/types/tui/interaction/QuestionOverlay.d.ts +0 -26
  28. package/lib/types/tui/interaction/types.d.ts +0 -36
  29. package/lib/types/tui/liveText.d.ts +0 -60
  30. package/lib/types/tui/logoArt.generated.d.ts +0 -9
  31. package/lib/types/tui/miniTextField.d.ts +0 -20
  32. package/lib/types/tui/modelProfile/ModelProfileOverlay.d.ts +0 -48
  33. package/lib/types/tui/modelProfile/types.d.ts +0 -63
  34. package/lib/types/tui/piTheme.d.ts +0 -10
  35. package/lib/types/tui/plugins/PluginsOverlay.d.ts +0 -22
  36. package/lib/types/tui/plugins/types.d.ts +0 -18
  37. package/lib/types/tui/promptAutocomplete.d.ts +0 -29
  38. package/lib/types/tui/statsFormat.d.ts +0 -89
  39. package/lib/types/tui/store.d.ts +0 -246
  40. package/lib/types/tui/text.d.ts +0 -21
  41. package/lib/types/tui/theme.d.ts +0 -35
  42. package/lib/types/tui/toolCards/ToolCardsOverlay.d.ts +0 -33
  43. package/lib/types/tui/trajectory/TrajectoryDetail.d.ts +0 -13
  44. package/lib/types/tui/trajectory/TrajectoryLedger.d.ts +0 -9
  45. package/lib/types/tui/trajectory/TrajectoryOverlay.d.ts +0 -39
  46. package/lib/types/tui/trajectory/detail.d.ts +0 -10
  47. package/lib/types/tui/trajectory/layout.d.ts +0 -16
  48. package/lib/types/tui/trajectory/types.d.ts +0 -74
  49. package/lib/types/tui-app/session.d.ts +0 -21
  50. package/lib/types/version.d.ts +0 -2
  51. package/lib/types/yly/yly-frames.generated.d.ts +0 -18
  52. package/lib/types/yly/yly-pet.d.ts +0 -46
  53. package/lib/types/yly/yly-programs.d.ts +0 -41
package/lib/index.js CHANGED
@@ -1,15 +1,17 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { randomUUID } from "node:crypto";
3
- import { bootAcrylHarnessProfile, createAcrylSessionBridge } from "acryl-harness-runtime";
4
3
  import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
4
+ import { SessionId } from "@deepseek-ai/dsh-session";
5
+ import { existsSync, writeFileSync } from "node:fs";
6
+ import { dirname, join, relative, resolve } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+ import { DEFAULT_PROFILE_BUNDLES, boot, composeEntries, healProfilesModuleFallback, initProfile, loadProfile, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
5
9
  import { diffLines } from "diff";
6
10
  import { Container, Editor, HStack, Key, KeybindingsManager, ProcessTerminal, ScrollView, TUI_KEYBINDINGS, Text, TuiAltScreen, VStack, matchesKey, setKeybindings, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
7
11
  import { spawn } from "node:child_process";
8
12
  import { readdir } from "node:fs/promises";
9
- import { join, relative } from "node:path";
10
13
  import { ManualCompactionError } from "@deepseek-ai/dsh-compaction";
11
14
  import { GoalError } from "@deepseek-ai/dsh-goal";
12
- import { SessionId } from "@deepseek-ai/dsh-session";
13
15
  //#region src/cli/grammar.ts
14
16
  const HOST_COMMANDS = /* @__PURE__ */ new Set([
15
17
  "tui",
@@ -85,6 +87,257 @@ function parseAcrylArgs(args) {
85
87
  ...resumeSessionId === void 0 ? {} : { resumeSessionId }
86
88
  };
87
89
  }
90
+ process.stdout, process.stderr;
91
+ //#endregion
92
+ //#region ../acryl-harness-runtime/lib/index.mjs
93
+ function contentText(content) {
94
+ return content.filter((block) => {
95
+ return block.type === "text" && typeof block.text === "string";
96
+ }).map((block) => block.text).join("");
97
+ }
98
+ function transcript(events) {
99
+ const items = [];
100
+ for (const event of events) {
101
+ if (event.type === "user/message" && event.data.source.kind === "user") {
102
+ const text = contentText(event.data.content);
103
+ if (text !== "") items.push(Object.freeze({
104
+ id: `event-${event.seq}`,
105
+ author: "user",
106
+ text
107
+ }));
108
+ }
109
+ if (event.type === "assistant/message") {
110
+ const text = contentText(event.data.message.content);
111
+ if (text !== "") items.push(Object.freeze({
112
+ id: `event-${event.seq}`,
113
+ author: "assistant",
114
+ text
115
+ }));
116
+ }
117
+ }
118
+ return Object.freeze(items);
119
+ }
120
+ function tools(events) {
121
+ const current = /* @__PURE__ */ new Map();
122
+ for (const event of events) {
123
+ if (event.type === "tool/call") current.set(event.data.callId, Object.freeze({
124
+ callId: event.data.callId,
125
+ name: event.data.name,
126
+ status: "running"
127
+ }));
128
+ if (event.type === "tool/result") {
129
+ const callId = event.data.message.source.callId;
130
+ const existing = current.get(callId);
131
+ if (existing !== void 0) current.set(callId, Object.freeze({
132
+ ...existing,
133
+ status: "succeeded"
134
+ }));
135
+ }
136
+ }
137
+ return Object.freeze([...current.values()]);
138
+ }
139
+ function status(agent) {
140
+ return agent.status === "running" ? "running" : "idle";
141
+ }
142
+ /**
143
+ * Runtime-owned adapter over one native DSH agent/session. It creates or resumes
144
+ * the native agent and derives every presentation value from its durable log.
145
+ */
146
+ function createAcrylSessionBridge(ctx, options) {
147
+ const handles = /* @__PURE__ */ new Map();
148
+ const subscribers = /* @__PURE__ */ new Map();
149
+ const eventListeners = /* @__PURE__ */ new Map();
150
+ let disposed = false;
151
+ const notify = (sessionId) => {
152
+ const listeners = subscribers.get(sessionId);
153
+ if (listeners === void 0) return;
154
+ snapshot(sessionId).then((next) => {
155
+ for (const listener of listeners) try {
156
+ listener(next);
157
+ } catch {}
158
+ });
159
+ };
160
+ const offSessionEvent = ctx.on("session/event", (session, event) => {
161
+ if (!handles.has(session.id)) return;
162
+ notify(session.id);
163
+ const listeners = eventListeners.get(session.id);
164
+ if (listeners === void 0) return;
165
+ for (const listener of listeners) try {
166
+ listener(event);
167
+ } catch {}
168
+ });
169
+ const snapshot = async (sessionId) => {
170
+ const agent = agentFor(sessionId);
171
+ return Object.freeze({
172
+ profile: options.profile,
173
+ generationId: options.generationId,
174
+ attachment: options.attachment,
175
+ sessionId: agent.id,
176
+ agentStatus: status(agent),
177
+ transcript: transcript(agent.session.events),
178
+ tools: tools(agent.session.events)
179
+ });
180
+ };
181
+ const agentFor = (sessionId) => {
182
+ if (disposed) throw new Error("ACRYL session bridge is disposed");
183
+ const handle = handles.get(sessionId);
184
+ if (handle === void 0) throw new Error(`ACRYL session ${sessionId} is not active`);
185
+ return handle.agent;
186
+ };
187
+ return Object.freeze({
188
+ async open(resumeSessionId) {
189
+ if (disposed) throw new Error("ACRYL session bridge is disposed");
190
+ if (handles.size !== 0) throw new Error("ACRYL session bridge already has an active session");
191
+ const defaultModel = ctx.get("agentDefaultModel");
192
+ if (defaultModel === void 0) throw new Error("ACRYL profile has no default agent model");
193
+ const selection = defaultModel.currentSelection();
194
+ const handle = resumeSessionId === void 0 ? await ctx.agents.create({
195
+ sessionId: SessionId(`acryl-session-${crypto.randomUUID()}`),
196
+ meta: { cwd: options.cwd },
197
+ agentOptions: {
198
+ provider: selection.provider,
199
+ model: selection.model
200
+ }
201
+ }) : await ctx.agents.resume({
202
+ resumeSessionId: SessionId(resumeSessionId),
203
+ agentOptions: {
204
+ provider: selection.provider,
205
+ model: selection.model
206
+ }
207
+ });
208
+ handles.set(handle.agent.id, handle);
209
+ return handle.agent.id;
210
+ },
211
+ snapshot,
212
+ events(sessionId) {
213
+ return agentFor(sessionId).session.events;
214
+ },
215
+ async subscribe(sessionId, listener, _onError) {
216
+ agentFor(sessionId);
217
+ const listeners = subscribers.get(sessionId) ?? /* @__PURE__ */ new Set();
218
+ subscribers.set(sessionId, listeners);
219
+ listeners.add(listener);
220
+ try {
221
+ listener(await snapshot(sessionId));
222
+ } catch {}
223
+ let active = true;
224
+ return Object.freeze({
225
+ whenError() {
226
+ return new Promise(() => {});
227
+ },
228
+ async dispose() {
229
+ if (!active) return;
230
+ active = false;
231
+ listeners.delete(listener);
232
+ if (listeners.size === 0) subscribers.delete(sessionId);
233
+ }
234
+ });
235
+ },
236
+ async subscribeEvents(sessionId, listener) {
237
+ agentFor(sessionId);
238
+ const listeners = eventListeners.get(sessionId) ?? /* @__PURE__ */ new Set();
239
+ eventListeners.set(sessionId, listeners);
240
+ listeners.add(listener);
241
+ let active = true;
242
+ return Object.freeze({ async dispose() {
243
+ if (!active) return;
244
+ active = false;
245
+ listeners.delete(listener);
246
+ if (listeners.size === 0) eventListeners.delete(sessionId);
247
+ } });
248
+ },
249
+ async submitPrompt(input) {
250
+ const agent = agentFor(input.sessionId);
251
+ if (input.text.trim() === "") throw new Error("ACRYL prompt must not be empty");
252
+ const accepted = new Promise((resolve) => {
253
+ const off = ctx.on("session/event", (session, event) => {
254
+ if (session !== agent.session || event.type !== "user/message") return;
255
+ off();
256
+ resolve();
257
+ });
258
+ });
259
+ agent.followup(createUserMessage({
260
+ content: [{
261
+ type: "text",
262
+ text: input.text
263
+ }],
264
+ source: { kind: "user" }
265
+ }));
266
+ await accepted;
267
+ },
268
+ async cancel(sessionId) {
269
+ agentFor(sessionId).cancel({ kind: "user" });
270
+ },
271
+ async dispose() {
272
+ if (disposed) return;
273
+ disposed = true;
274
+ offSessionEvent();
275
+ subscribers.clear();
276
+ eventListeners.clear();
277
+ const activeHandles = [...handles.values()];
278
+ handles.clear();
279
+ const sessions = ctx.get("sessions");
280
+ for (const handle of activeHandles) {
281
+ try {
282
+ await handle.agent.whenIdle();
283
+ } catch {}
284
+ try {
285
+ await sessions?.flush(handle.agent.session);
286
+ } catch {}
287
+ }
288
+ await Promise.all(activeHandles.map((handle) => handle.dispose()));
289
+ }
290
+ });
291
+ }
292
+ const dshInstallAnchor = createRequire(import.meta.url).resolve("@deepseek-ai/dsh/package.json");
293
+ const profileRoot = "[]\n";
294
+ const shippedPresetsDir = join(resolve(dirname(fileURLToPath(import.meta.url)), "../.."), "deepseek-harness", "packages", "preset", "agent-presets", "presets");
295
+ const ACRYL_RUNTIME_ROWS = [{
296
+ id: "system-prompt",
297
+ name: "@deepseek-ai/dsh-system-prompt",
298
+ config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
299
+ }, { insert: [{
300
+ id: "agent-presets",
301
+ name: "@deepseek-ai/dsh-agent-presets",
302
+ config: {
303
+ default: "standard",
304
+ roots: existsSync(shippedPresetsDir) ? [{
305
+ path: shippedPresetsDir,
306
+ trust: "system"
307
+ }] : [],
308
+ includeShippedRoot: false,
309
+ includeUserRoot: true
310
+ }
311
+ }, {
312
+ id: "session-stats",
313
+ name: "@deepseek-ai/dsh-session-stats"
314
+ }] }];
315
+ /** Boot one normal pinned-Harness ACRYL profile in a single Cordis root. */
316
+ async function bootAcrylHarnessProfile(options) {
317
+ if (options.profile.trim() === "") throw new Error("ACRYL Harness profile must not be empty");
318
+ initProfile(resolveProfileDir(options.profile), DEFAULT_PROFILE_BUNDLES);
319
+ healProfilesModuleFallback(dshInstallAnchor);
320
+ const profile = loadProfile("acryl", options.profile, dshInstallAnchor);
321
+ const rootConfig = join(profile.dir, "cordis.yml");
322
+ writeFileSync(rootConfig, profileRoot);
323
+ const patches = structuredClone([
324
+ ...profile.layers.flatMap((layer) => layer.patches),
325
+ ...ACRYL_RUNTIME_ROWS,
326
+ ...profile.patches
327
+ ]);
328
+ if (composeEntries([patches]).find((entry) => entry.id === "hmr")?.disabled !== true && !process.execArgv.includes("--expose-internals")) throw new Error("ACRYL profile enables Cordis HMR and must be launched with Node --expose-internals");
329
+ const ctx = await boot("acryl", rootConfig, patches, options.prepare);
330
+ let disposed = false;
331
+ return Object.freeze({
332
+ ctx,
333
+ profileDirectory: profile.dir,
334
+ async dispose() {
335
+ if (disposed) return;
336
+ disposed = true;
337
+ await ctx.fiber.dispose();
338
+ }
339
+ });
340
+ }
88
341
  //#endregion
89
342
  //#region src/host/direct.ts
90
343
  /** Start one normal local Harness runtime for this terminal surface. */