acryl 0.1.17 → 0.1.19

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.
package/lib/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { randomUUID } from "node:crypto";
3
- import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
4
- import { SessionId } from "@deepseek-ai/dsh-session";
5
3
  import { existsSync, writeFileSync } from "node:fs";
6
4
  import { dirname, join, relative, resolve } from "node:path";
7
5
  import { fileURLToPath } from "node:url";
6
+ import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
7
+ import { SessionId } from "@deepseek-ai/dsh-session";
8
8
  import { DEFAULT_PROFILE_BUNDLES, boot, composeEntries, healProfilesModuleFallback, initProfile, loadProfile, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
9
+ import { defineTool } from "@deepseek-ai/dsh-tools";
9
10
  import { execFile, spawn } from "node:child_process";
10
11
  import { diffLines } from "diff";
11
12
  import { Container, Editor, HStack, Key, KeybindingsManager, ProcessTerminal, ScrollView, TUI_KEYBINDINGS, Text, TuiAltScreen, VStack, matchesKey, setKeybindings, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
@@ -90,6 +91,55 @@ function parseAcrylArgs(args) {
90
91
  process.stdout, process.stderr;
91
92
  //#endregion
92
93
  //#region ../acryl-harness-runtime/lib/index.mjs
94
+ const shippedPresetsDir = join(resolve(dirname(fileURLToPath(import.meta.url)), "../.."), "deepseek-harness", "packages", "preset", "agent-presets", "presets");
95
+ const authorizationCapabilityPatches = [{
96
+ id: "system-prompt",
97
+ name: "@deepseek-ai/dsh-system-prompt",
98
+ config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
99
+ }, { insert: [
100
+ {
101
+ id: "agent-presets",
102
+ name: "@deepseek-ai/dsh-agent-presets",
103
+ config: {
104
+ default: "standard",
105
+ roots: existsSync(shippedPresetsDir) ? [{
106
+ path: shippedPresetsDir,
107
+ trust: "system"
108
+ }] : [],
109
+ includeShippedRoot: false,
110
+ includeUserRoot: true
111
+ }
112
+ },
113
+ {
114
+ id: "session-stats",
115
+ name: "@deepseek-ai/dsh-session-stats"
116
+ },
117
+ {
118
+ id: "authorization",
119
+ name: "@deepseek-ai/dsh-authorization"
120
+ }
121
+ ] }];
122
+ const NON_TUI_SHARED_ROW_IDS = /* @__PURE__ */ new Set(["authorization"]);
123
+ function selectNonTuiCapabilityPatches(patches) {
124
+ return patches.flatMap((patch) => {
125
+ if (!("insert" in patch) || !Array.isArray(patch.insert)) return [];
126
+ const insert = patch.insert.filter((row) => NON_TUI_SHARED_ROW_IDS.has(row.id));
127
+ return insert.length === 0 ? [] : [{ insert }];
128
+ });
129
+ }
130
+ const ACRYL_CODING_CAPABILITIES = [{
131
+ id: "authorization",
132
+ surfaces: [
133
+ "tui",
134
+ "web",
135
+ "desktop"
136
+ ],
137
+ loaderPatches: authorizationCapabilityPatches
138
+ }];
139
+ function createAcrylCodingCapabilityPatches(surfaces) {
140
+ const includeSharedCodingRows = surfaces.has("tui");
141
+ return structuredClone(ACRYL_CODING_CAPABILITIES.filter((capability) => capability.surfaces.some((surface) => surfaces.has(surface))).flatMap((capability) => includeSharedCodingRows ? capability.loaderPatches : selectNonTuiCapabilityPatches(capability.loaderPatches)));
142
+ }
93
143
  function contentText(content) {
94
144
  return content.filter((block) => {
95
145
  return block.type === "text" && typeof block.text === "string";
@@ -289,36 +339,71 @@ function createAcrylSessionBridge(ctx, options) {
289
339
  }
290
340
  });
291
341
  }
342
+ /** Canonical tool name exposed to the model. */
343
+ const TOOL_NAME = "acryl_workspace_status";
344
+ /** Read the ACRYL workspace/profile context the agent is running under. */
345
+ function readWorkspaceContext() {
346
+ return {
347
+ cwd: process.cwd(),
348
+ dshHome: process.env.DSH_HOME ?? "",
349
+ profile: process.env.ACRYL_PROFILE ?? "",
350
+ surface: process.env.ACRYL_SURFACE ?? ""
351
+ };
352
+ }
353
+ /** Render one line of the model-facing text from the canonical context value. */
354
+ function fmt(label, value, prefix) {
355
+ return `${prefix} ${label}: ${value}`;
356
+ }
357
+ /** Register the `acryl_workspace_status` tool on `ctx.tools`. Returns a disposer. */
358
+ function installAcrylWorkspaceStatusTool(ctx) {
359
+ const tool = defineTool({
360
+ name: TOOL_NAME,
361
+ description: "Report the ACRYL workspace context the agent is operating in: current working directory, DSH home, active ACRYL profile, and presentation surface. Use it to confirm which project/profile a session is bound to before acting.",
362
+ parameters: {},
363
+ output: {
364
+ schema: {
365
+ type: "object",
366
+ additionalProperties: false,
367
+ properties: {
368
+ cwd: {
369
+ type: "string",
370
+ required: true
371
+ },
372
+ dshHome: {
373
+ type: "string",
374
+ required: true
375
+ },
376
+ profile: {
377
+ type: "string",
378
+ required: true
379
+ },
380
+ surface: {
381
+ type: "string",
382
+ required: true
383
+ }
384
+ }
385
+ },
386
+ render(_args, value) {
387
+ const v = value;
388
+ return [{
389
+ type: "text",
390
+ text: ["ACRYL workspace context:", ...[
391
+ fmt("cwd", v.cwd, "-"),
392
+ fmt("dshHome", v.dshHome || "<unset>", "-"),
393
+ fmt("profile", v.profile || "<default>", "-"),
394
+ fmt("surface", v.surface || "<tui>", "-")
395
+ ]].join("\n")
396
+ }];
397
+ }
398
+ },
399
+ async execute(_args, _exec) {
400
+ return readWorkspaceContext();
401
+ }
402
+ });
403
+ return ctx.tools.register(tool);
404
+ }
292
405
  const dshInstallAnchor = createRequire(import.meta.url).resolve("@deepseek-ai/dsh/package.json");
293
406
  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
- {
301
- id: "agent-presets",
302
- name: "@deepseek-ai/dsh-agent-presets",
303
- config: {
304
- default: "standard",
305
- roots: existsSync(shippedPresetsDir) ? [{
306
- path: shippedPresetsDir,
307
- trust: "system"
308
- }] : [],
309
- includeShippedRoot: false,
310
- includeUserRoot: true
311
- }
312
- },
313
- {
314
- id: "session-stats",
315
- name: "@deepseek-ai/dsh-session-stats"
316
- },
317
- {
318
- id: "authorization",
319
- name: "@deepseek-ai/dsh-authorization"
320
- }
321
- ] }];
322
407
  /** Boot one normal pinned-Harness ACRYL profile in a single Cordis root. */
323
408
  async function bootAcrylHarnessProfile(options) {
324
409
  if (options.profile.trim() === "") throw new Error("ACRYL Harness profile must not be empty");
@@ -329,11 +414,12 @@ async function bootAcrylHarnessProfile(options) {
329
414
  writeFileSync(rootConfig, profileRoot);
330
415
  const patches = structuredClone([
331
416
  ...profile.layers.flatMap((layer) => layer.patches),
332
- ...ACRYL_RUNTIME_ROWS,
417
+ ...createAcrylCodingCapabilityPatches(/* @__PURE__ */ new Set(["tui"])),
333
418
  ...profile.patches
334
419
  ]);
335
420
  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");
336
421
  const ctx = await boot("acryl", rootConfig, patches, options.prepare);
422
+ if (ctx.tools) installAcrylWorkspaceStatusTool(ctx);
337
423
  let disposed = false;
338
424
  return Object.freeze({
339
425
  ctx,