@acryldev/agent-panel 0.0.0-stage → 0.1.1

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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -2
  3. package/client/describe.ts +101 -0
  4. package/client/driver-pick.ts +22 -0
  5. package/client/frame.ts +51 -0
  6. package/client/main.ts +707 -0
  7. package/client/markdown.ts +219 -0
  8. package/headless.ts +220 -0
  9. package/index.ts +523 -0
  10. package/launch.ts +67 -0
  11. package/lib/client/describe.ts +101 -0
  12. package/lib/client/driver-pick.ts +22 -0
  13. package/lib/client/frame.ts +51 -0
  14. package/lib/client/main.ts +707 -0
  15. package/lib/client/markdown.ts +219 -0
  16. package/lib/headless-B_RGxZFU.js +252 -0
  17. package/lib/headless-B_RGxZFU.js.map +1 -0
  18. package/lib/headless.js +2 -0
  19. package/lib/index.js +562 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/mount.js +25 -0
  22. package/lib/mount.js.map +1 -0
  23. package/lib/registry.js +13 -0
  24. package/lib/registry.js.map +1 -0
  25. package/lib/types/headless.d.ts +22 -0
  26. package/lib/types/index.d.ts +22 -0
  27. package/lib/types/launch.d.ts +18 -0
  28. package/lib/types/mount.d.ts +12 -0
  29. package/lib/types/registry.d.ts +10 -0
  30. package/lib/types/tsdown.config.d.ts +2 -0
  31. package/lib/types/visitors.d.ts +82 -0
  32. package/mount.ts +27 -0
  33. package/package.json +62 -3
  34. package/plugin.json +28 -0
  35. package/registry.ts +17 -0
  36. package/scripts/copy-assets.mjs +5 -0
  37. package/test/client-guards.test.ts +13 -0
  38. package/test/describe.test.ts +105 -0
  39. package/test/driver-pick.test.ts +24 -0
  40. package/test/frame.test.ts +35 -0
  41. package/test/launch.test.ts +90 -0
  42. package/test/markdown.test.ts +79 -0
  43. package/test/panel-client.test.ts +150 -0
  44. package/test/panel.test.ts +534 -0
  45. package/test/socket.test.ts +209 -0
  46. package/test/visitors.test.ts +112 -0
  47. package/test/why.test.ts +61 -0
  48. package/tsconfig.json +21 -0
  49. package/tsdown.config.ts +23 -0
  50. package/visitors.ts +231 -0
package/lib/mount.js ADDED
@@ -0,0 +1,25 @@
1
+ //#region mount.ts
2
+ /**
3
+ * A plugin's own route prefix under the app's mount. The app is served at the root of its own server `''`, or at the prefix a host serves it at (`/app` in
4
+ * the ACRYL frame); a plugin that mounts routes of its own (the panel, the PTY driver) takes that mount as config and derives its prefix from it, so its
5
+ * routes belong to the app wherever the app is served. The same rule `routerHttp.mount` applies.
6
+ */
7
+ function mountedPrefix(mount, path, plugin) {
8
+ if (mount === void 0 || mount === "") return path;
9
+ if (!/^\/[A-Za-z0-9._~\-/]*[A-Za-z0-9._~-]$/u.test(mount)) throw new TypeError(`${plugin}: the app's mount "${mount}" must be empty or an absolute path such as "/app"`);
10
+ return `${mount}${path}`;
11
+ }
12
+ /**
13
+ * The app's own mount, validated like {@link mountedPrefix}: empty at the root or the prefix a host serves the app at (`/app`). A plugin's routes are
14
+ * mounted at this path and keep only their own fixed path inside, so the frame's router (which prefixes a mount with the app's base) composes
15
+ * `/app` + `/api/agent-panel/panel.js` once, not twice.
16
+ */
17
+ function mountedBase(mount, plugin) {
18
+ if (mount === void 0 || mount === "") return "";
19
+ if (!/^\/[A-Za-z0-9._~\-/]*[A-Za-z0-9._~-]$/u.test(mount)) throw new TypeError(`${plugin}: the app's mount "${mount}" must be empty or an absolute path such as "/app"`);
20
+ return mount;
21
+ }
22
+ //#endregion
23
+ export { mountedBase, mountedPrefix };
24
+
25
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.js","names":[],"sources":["../mount.ts"],"sourcesContent":["/**\n * A plugin's own route prefix under the app's mount. The app is served at the root of its own server `''`, or at the prefix a host serves it at (`/app` in\n * the ACRYL frame); a plugin that mounts routes of its own (the panel, the PTY driver) takes that mount as config and derives its prefix from it, so its\n * routes belong to the app wherever the app is served. The same rule `routerHttp.mount` applies.\n */\nexport function mountedPrefix(mount: string | undefined, path: string, plugin: string): string {\n if (mount === undefined || mount === '') return path\n if (!/^\\/[A-Za-z0-9._~\\-/]*[A-Za-z0-9._~-]$/u.test(mount))\n throw new TypeError(\n `${plugin}: the app's mount \"${mount}\" must be empty or an absolute path such as \"/app\"`,\n )\n return `${mount}${path}`\n}\n\n/**\n * The app's own mount, validated like {@link mountedPrefix}: empty at the root or the prefix a host serves the app at (`/app`). A plugin's routes are\n * mounted at this path and keep only their own fixed path inside, so the frame's router (which prefixes a mount with the app's base) composes\n * `/app` + `/api/agent-panel/panel.js` once, not twice.\n */\nexport function mountedBase(mount: string | undefined, plugin: string): string {\n if (mount === undefined || mount === '') return ''\n if (!/^\\/[A-Za-z0-9._~\\-/]*[A-Za-z0-9._~-]$/u.test(mount))\n throw new TypeError(\n `${plugin}: the app's mount \"${mount}\" must be empty or an absolute path such as \"/app\"`,\n )\n return mount\n}\n"],"mappings":";;;;;;AAKA,SAAgB,cAAc,OAA2B,MAAc,QAAwB;CAC7F,IAAI,UAAU,KAAA,KAAa,UAAU,IAAI,OAAO;CAChD,IAAI,CAAC,yCAAyC,KAAK,KAAK,GACtD,MAAM,IAAI,UACR,GAAG,OAAO,qBAAqB,MAAM,mDACvC;CACF,OAAO,GAAG,QAAQ;AACpB;;;;;;AAOA,SAAgB,YAAY,OAA2B,QAAwB;CAC7E,IAAI,UAAU,KAAA,KAAa,UAAU,IAAI,OAAO;CAChD,IAAI,CAAC,yCAAyC,KAAK,KAAK,GACtD,MAAM,IAAI,UACR,GAAG,OAAO,qBAAqB,MAAM,mDACvC;CACF,OAAO;AACT"}
@@ -0,0 +1,13 @@
1
+ import { createDrivers } from "@acryldev/drivers";
2
+ //#region registry.ts
3
+ /** The `drivers` service of the agent panel: the registry (the `@acryldev/drivers` package, published as `acrylblends/drivers`) provided on a Cordis context, and the `ctx.drivers` type. */
4
+ /** Provide the registry on `ctx` (the panel does). */
5
+ function provideDrivers(ctx, authorized) {
6
+ const registry = createDrivers(authorized);
7
+ ctx.provide("drivers", registry);
8
+ return registry;
9
+ }
10
+ //#endregion
11
+ export { provideDrivers };
12
+
13
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../registry.ts"],"sourcesContent":["/** The `drivers` service of the agent panel: the registry (the `@acryldev/drivers` package, published as `acrylblends/drivers`) provided on a Cordis context, and the `ctx.drivers` type. */\n\nimport { createDrivers, type Drivers } from '@acryldev/drivers'\nimport type { Context } from '@deepseek-ai/cordis'\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n drivers: Drivers\n }\n}\n\n/** Provide the registry on `ctx` (the panel does). */\nexport function provideDrivers(ctx: Context, authorized: (headers: Headers) => boolean): Drivers {\n const registry = createDrivers(authorized)\n ;(ctx as Context).provide('drivers', registry)\n return registry\n}\n"],"mappings":";;;;AAYA,SAAgB,eAAe,KAAc,YAAoD;CAC/F,MAAM,WAAW,cAAc,UAAU;CACxC,IAAiB,QAAQ,WAAW,QAAQ;CAC7C,OAAO;AACT"}
@@ -0,0 +1,22 @@
1
+ import type { ChatDriver } from '@acryldev/drivers';
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ export type HeadlessName = 'claude' | 'codex' | 'pi';
4
+ /** The command line of each coding agent started headless in the app folder (the same ones the product test uses). */
5
+ export declare function command(driver: HeadlessName, message: string, root: string): {
6
+ file: string;
7
+ args: string[];
8
+ };
9
+ export declare function onPath(program: string): boolean;
10
+ /** Whether pi can reach DeepSeek: the key in the environment, or the one pi stored for itself when its owner logged in (`~/.pi/agent/auth.json`, a `deepseek` entry). */
11
+ export declare function piHasDeepseekKey(env?: NodeJS.ProcessEnv, home?: string): boolean;
12
+ /** The headless programs this machine can offer: installed (an executable on the PATH; a wrapper function around it is fine) and, for pi, able to reach its model. */
13
+ export declare function availableHeadless(wanted?: readonly HeadlessName[]): HeadlessName[];
14
+ /** The app's own agent as a chat driver: its tool calls, then its answer. Aborting the signal cancels the run. */
15
+ export declare function agentDriver(ctx: Context): ChatDriver;
16
+ /** A coding agent run headless in the app folder: its stdout is the answer, its stderr the tool lines. Aborting the signal ends the program. */
17
+ export declare function headlessDriver(name: HeadlessName, root: string): ChatDriver;
18
+ /**
19
+ * Why a driver name cannot be used to ask a question, in a sentence: it is a terminal (picked in the panel, not asked over `/ask`), it is a coding agent that is not installed or not
20
+ * able to start, or pi without a key to reach its model. Nothing when the name is not one of the headless agents.
21
+ */
22
+ export declare function whyNotChat(name: string, kind: 'chat' | 'terminal' | undefined): string | undefined;
@@ -0,0 +1,22 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import { type HeadlessName } from './headless.ts';
3
+ import { type AssistantLimits } from './visitors.ts';
4
+ export type { ChatDriver, ChatEvent, Driver, Drivers, TerminalDriver, TerminalSession, } from '@acryldev/drivers';
5
+ export declare const name = "agent-panel";
6
+ export declare const inject: string[];
7
+ export interface PanelConfig {
8
+ /** Headless coding agents to offer besides the app's own agent; default: the ones found on the machine. */
9
+ drivers?: readonly HeadlessName[];
10
+ /**
11
+ * The URL prefix the app is mounted at: empty on the app's own server, `/app` when the ACRYL frame hosts it (the same prefix `makeApp` and
12
+ * `routerHttp.mount` take). The panel's routes, script tag and client live under it, so they belong to the app and are served wherever it is.
13
+ */
14
+ mount?: string;
15
+ /** The Assistant: a production panel for the app's visitors, with the app's own agent only (no coding agent, no terminal). Runs with `NODE_ENV=production`. */
16
+ assistant?: boolean;
17
+ /** The Assistant's limits on what visitors may ask (`visitors.ts` has the defaults); the development panel has none but one run at a time. */
18
+ limits?: AssistantLimits;
19
+ }
20
+ /** Whether a request comes from the app's own page: a browser says so itself (`Sec-Fetch-Site: same-origin`), or the Origin is the Host. */
21
+ export declare function fromOwnPage(headers: Headers): boolean;
22
+ export declare function apply(ctx: Context, config?: PanelConfig): void;
@@ -0,0 +1,18 @@
1
+ export interface Launch {
2
+ readonly file: string;
3
+ readonly args: string[];
4
+ }
5
+ export interface LaunchDeps {
6
+ readonly platform?: NodeJS.Platform;
7
+ readonly env?: NodeJS.ProcessEnv;
8
+ readonly exists?: (path: string) => boolean;
9
+ readonly read?: (path: string) => string;
10
+ /** The Node that starts a shim's script (this process's). */
11
+ readonly execPath?: string;
12
+ }
13
+ /**
14
+ * @returns how to start `program` with `args`, or a sentence saying why it cannot be started here. A program that is not found is also a sentence.
15
+ */
16
+ export declare function resolveLaunch(program: string, args: readonly string[], deps?: LaunchDeps): Launch | {
17
+ readonly error: string;
18
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A plugin's own route prefix under the app's mount. The app is served at the root of its own server `''`, or at the prefix a host serves it at (`/app` in
3
+ * the ACRYL frame); a plugin that mounts routes of its own (the panel, the PTY driver) takes that mount as config and derives its prefix from it, so its
4
+ * routes belong to the app wherever the app is served. The same rule `routerHttp.mount` applies.
5
+ */
6
+ export declare function mountedPrefix(mount: string | undefined, path: string, plugin: string): string;
7
+ /**
8
+ * The app's own mount, validated like {@link mountedPrefix}: empty at the root or the prefix a host serves the app at (`/app`). A plugin's routes are
9
+ * mounted at this path and keep only their own fixed path inside, so the frame's router (which prefixes a mount with the app's base) composes
10
+ * `/app` + `/api/agent-panel/panel.js` once, not twice.
11
+ */
12
+ export declare function mountedBase(mount: string | undefined, plugin: string): string;
@@ -0,0 +1,10 @@
1
+ /** The `drivers` service of the agent panel: the registry (the `@acryldev/drivers` package, published as `acrylblends/drivers`) provided on a Cordis context, and the `ctx.drivers` type. */
2
+ import { type Drivers } from '@acryldev/drivers';
3
+ import type { Context } from '@deepseek-ai/cordis';
4
+ declare module '@deepseek-ai/cordis' {
5
+ interface Context {
6
+ drivers: Drivers;
7
+ }
8
+ }
9
+ /** Provide the registry on `ctx` (the panel does). */
10
+ export declare function provideDrivers(ctx: Context, authorized: (headers: Headers) => boolean): Drivers;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("tsdown").UserConfig;
2
+ export default _default;
@@ -0,0 +1,82 @@
1
+ /** The cookie that names a visitor of the Assistant. HttpOnly: the page's scripts never read it. */
2
+ export declare const VISITOR_COOKIE = "acryl-visitor";
3
+ /** The Assistant's limits; each one has a default. */
4
+ export interface AssistantLimits {
5
+ /** Questions one visitor may ask in an hour. */
6
+ readonly perVisitorPerHour?: number;
7
+ /** Questions all visitors together may ask in a day: every one of them spends the owner's model key. */
8
+ readonly perDay?: number;
9
+ /** Runs going at once, across visitors. */
10
+ readonly concurrent?: number;
11
+ /** Characters in one question. */
12
+ readonly messageLength?: number;
13
+ }
14
+ export declare const DEFAULT_LIMITS: Required<AssistantLimits>;
15
+ /** What a visitor's run must say about itself. */
16
+ export interface RunState {
17
+ readonly ended: boolean;
18
+ }
19
+ export interface Visitor<R extends RunState> {
20
+ readonly id: string;
21
+ readonly token: string;
22
+ /** The visitor in the audit: a short hash, never the cookie itself. */
23
+ readonly tag: string;
24
+ /** The visitor's latest run, going or ended (what a page that loads shows again). */
25
+ current: R | undefined;
26
+ /** When this visitor's asks of the last hour started. */
27
+ readonly asks: number[];
28
+ lastSeen: number;
29
+ }
30
+ /** Why an ask is refused, with the HTTP status to answer. */
31
+ export interface Refusal {
32
+ readonly error: string;
33
+ readonly status: 400 | 409 | 429 | 503;
34
+ }
35
+ export interface VisitorsOptions {
36
+ /** One visitor for every page (development); otherwise one per cookie (the Assistant). */
37
+ readonly shared: boolean;
38
+ readonly limits?: AssistantLimits;
39
+ readonly now?: () => number;
40
+ readonly capacity?: number;
41
+ }
42
+ /** The value of one cookie in a `Cookie` header. */
43
+ export declare function cookieValue(header: string | undefined | null, name: string): string | undefined;
44
+ /** Whether two secrets are the same, in constant time. */
45
+ export declare function sameSecret(presented: unknown, expected: string): boolean;
46
+ export declare class Visitors<R extends RunState> {
47
+ private readonly shared;
48
+ private readonly limits;
49
+ private readonly now;
50
+ private readonly capacity;
51
+ private readonly byId;
52
+ /** When every ask of the last day started, across visitors. */
53
+ private readonly day;
54
+ private readonly owner;
55
+ constructor(options: VisitorsOptions);
56
+ /** The visitor a request belongs to: the owner in development, else the one its cookie names; `undefined` when it names none this app knows. */
57
+ of(cookieHeader: string | undefined | null): Visitor<R> | undefined;
58
+ /**
59
+ * The visitor of a session request, made when the request names none. `setCookie` is the header to answer with, only for a new visitor: HttpOnly, SameSite=Strict, the whole
60
+ * app (`Path=/`), a day long, and Secure when the page came over https.
61
+ */
62
+ session(cookieHeader: string | undefined | null, secure: boolean): {
63
+ visitor: Visitor<R>;
64
+ setCookie?: string;
65
+ };
66
+ /** Whether `presented` is this visitor's token. */
67
+ accepts(visitor: Visitor<R> | undefined, presented: unknown): visitor is Visitor<R>;
68
+ /** Whether any visitor holds this token (a terminal driver checks a request with no other context). */
69
+ knows(cookieHeader: string | undefined | null, presented: unknown): boolean;
70
+ /** The question's length check, which comes before anything is counted. */
71
+ checkMessage(message: string): Refusal | undefined;
72
+ /**
73
+ * Whether this visitor may start a run now. The visitor's own run going is refused first (409); then, for the Assistant, the visitor's hour, the runs going at once and the
74
+ * day. An admitted ask is counted.
75
+ */
76
+ admit(visitor: Visitor<R>): Refusal | undefined;
77
+ /** How many visitors are kept (for tests and diagnostics). */
78
+ get size(): number;
79
+ private make;
80
+ /** Keep a new visitor; past the capacity, let go of the visitors seen longest ago that have no run going. */
81
+ private keep;
82
+ }
package/mount.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A plugin's own route prefix under the app's mount. The app is served at the root of its own server `''`, or at the prefix a host serves it at (`/app` in
3
+ * the ACRYL frame); a plugin that mounts routes of its own (the panel, the PTY driver) takes that mount as config and derives its prefix from it, so its
4
+ * routes belong to the app wherever the app is served. The same rule `routerHttp.mount` applies.
5
+ */
6
+ export function mountedPrefix(mount: string | undefined, path: string, plugin: string): string {
7
+ if (mount === undefined || mount === '') return path
8
+ if (!/^\/[A-Za-z0-9._~\-/]*[A-Za-z0-9._~-]$/u.test(mount))
9
+ throw new TypeError(
10
+ `${plugin}: the app's mount "${mount}" must be empty or an absolute path such as "/app"`,
11
+ )
12
+ return `${mount}${path}`
13
+ }
14
+
15
+ /**
16
+ * The app's own mount, validated like {@link mountedPrefix}: empty at the root or the prefix a host serves the app at (`/app`). A plugin's routes are
17
+ * mounted at this path and keep only their own fixed path inside, so the frame's router (which prefixes a mount with the app's base) composes
18
+ * `/app` + `/api/agent-panel/panel.js` once, not twice.
19
+ */
20
+ export function mountedBase(mount: string | undefined, plugin: string): string {
21
+ if (mount === undefined || mount === '') return ''
22
+ if (!/^\/[A-Za-z0-9._~\-/]*[A-Za-z0-9._~-]$/u.test(mount))
23
+ throw new TypeError(
24
+ `${plugin}: the app's mount "${mount}" must be empty or an absolute path such as "/app"`,
25
+ )
26
+ return mount
27
+ }
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@acryldev/agent-panel",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "A chat panel inside the running app: the person writes what they want, the app's own agent (or Claude Code, Codex or pi started in the app folder) builds it through the same door, and the page reloads when a plugin was installed, with no restart. Development only; opt-in with acrylblends add agent-panel.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/acryldev/acryl.git",
9
+ "directory": "plugins/agent-panel"
10
+ },
11
+ "homepage": "https://github.com/acryldev/acryl/tree/main/plugins/agent-panel#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/acryldev/acryl/issues"
14
+ },
15
+ "type": "module",
16
+ "engines": {
17
+ "node": "^22.19.0 || >=24.0.0"
18
+ },
19
+ "main": "./lib/index.js",
20
+ "types": "./lib/types/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./lib/types/index.d.ts",
24
+ "default": "./lib/index.js"
25
+ },
26
+ "./headless": {
27
+ "types": "./lib/types/headless.d.ts",
28
+ "default": "./lib/headless.js"
29
+ },
30
+ "./registry": {
31
+ "types": "./lib/types/registry.d.ts",
32
+ "default": "./lib/registry.js"
33
+ },
34
+ "./mount": {
35
+ "types": "./lib/types/mount.d.ts",
36
+ "default": "./lib/mount.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "dependencies": {
41
+ "@acryldev/agent": "0.1.1",
42
+ "@acryldev/extensions": "0.1.1",
43
+ "@acryldev/instance": "0.1.2",
44
+ "@acryldev/node-server": "0.1.1",
45
+ "@acryldev/router": "0.1.0",
46
+ "@acryldev/drivers": "0.1.1"
47
+ },
48
+ "peerDependencies": {
49
+ "@deepseek-ai/cordis": "^4.0.2"
50
+ },
51
+ "devDependencies": {
52
+ "@deepseek-ai/cordis": "4.0.4",
53
+ "@types/node": "^22.20.0",
54
+ "@acryldev/state": "0.1.0",
55
+ "jsdom": "29.1.1",
56
+ "@types/jsdom": "30.0.0",
57
+ "ws": "8.21.3",
58
+ "@types/ws": "8.18.2",
59
+ "typescript": "6.0.3",
60
+ "tsdown": "0.22.2"
61
+ },
62
+ "scripts": {
63
+ "build": "tsdown && tsc -p tsconfig.json --emitDeclarationOnly && node scripts/copy-assets.mjs"
64
+ }
6
65
  }
package/plugin.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "agent-panel",
3
+ "description": "A chat panel inside the running app: the person writes what they want, the app's own agent (or Claude Code, Codex or pi started in the app folder) builds it through the same door, and the page reloads when a plugin was installed, with no restart. Development only; opt-in with acrylblends add agent-panel.",
4
+ "requires": [
5
+ "drivers",
6
+ "router",
7
+ "node-server",
8
+ "agent",
9
+ "builder",
10
+ "extensions",
11
+ "sandbox",
12
+ "tasks",
13
+ "instance"
14
+ ],
15
+ "inject": ["router", "agent", "extensions", "appInstance"],
16
+ "provides": ["drivers"],
17
+ "dependencies": {
18
+ "@deepseek-ai/cordis": "4.0.4"
19
+ },
20
+ "mount": "add a row `- id: agent-panel` / `name: agent-panel` to blend.yaml BEFORE the `routes` row (its middleware adds one script tag to every HTML page the routes after it answer) and register it in src/app.ts: 'agent-panel': panel; open the app in a browser and use the button at the corner of the page",
21
+ "gitignore": [".acryl/"],
22
+ "entries": {
23
+ "": "index.ts",
24
+ "/headless": "headless.ts",
25
+ "/registry": "registry.ts",
26
+ "/mount": "mount.ts"
27
+ }
28
+ }
package/registry.ts ADDED
@@ -0,0 +1,17 @@
1
+ /** The `drivers` service of the agent panel: the registry (the `@acryldev/drivers` package, published as `acrylblends/drivers`) provided on a Cordis context, and the `ctx.drivers` type. */
2
+
3
+ import { createDrivers, type Drivers } from '@acryldev/drivers'
4
+ import type { Context } from '@deepseek-ai/cordis'
5
+
6
+ declare module '@deepseek-ai/cordis' {
7
+ interface Context {
8
+ drivers: Drivers
9
+ }
10
+ }
11
+
12
+ /** Provide the registry on `ctx` (the panel does). */
13
+ export function provideDrivers(ctx: Context, authorized: (headers: Headers) => boolean): Drivers {
14
+ const registry = createDrivers(authorized)
15
+ ;(ctx as Context).provide('drivers', registry)
16
+ return registry
17
+ }
@@ -0,0 +1,5 @@
1
+ import { cpSync } from 'node:fs'
2
+
3
+ cpSync(new URL('../client', import.meta.url), new URL('../lib/client', import.meta.url), {
4
+ recursive: true,
5
+ })
@@ -0,0 +1,13 @@
1
+ // The panel's send guards: a submit that cannot send says why in the panel's log instead of returning silently. The frame gate saw the silent path once
2
+ // (empty log, enabled Send, no run); these are the reasons it could have been, named.
3
+ import assert from 'node:assert/strict'
4
+ import { test } from 'node:test'
5
+ import { sendRefusal } from '../client/main.ts'
6
+
7
+ test('a submit with nothing typed, or while a run is going, is refused with a reason the panel shows', () => {
8
+ assert.equal(sendRefusal('', false), 'empty')
9
+ assert.equal(sendRefusal(' ', false), 'empty')
10
+ assert.equal(sendRefusal('', true), 'empty')
11
+ assert.equal(sendRefusal('add 2 3', true), 'busy')
12
+ assert.equal(sendRefusal('add 2 3', false), undefined)
13
+ })
@@ -0,0 +1,105 @@
1
+ import assert from 'node:assert/strict'
2
+ import { test } from 'node:test'
3
+ import { describePageStep, describeTool } from '../client/describe.ts'
4
+
5
+ test("a coding agent's command is shown as the command, its bookkeeping is not shown", () => {
6
+ assert.equal(
7
+ describeTool({
8
+ tool: 'codex',
9
+ info: "exec\n/bin/zsh -lc 'npm test' in /private/tmp/work/app\n",
10
+ }),
11
+ 'codex: $ npm test',
12
+ )
13
+ assert.equal(
14
+ describeTool({
15
+ tool: 'codex',
16
+ info: 'exec\n/bin/zsh -lc "./.acryl/bin/acryl act click --ref 7.15 --json" in /private/tmp/work/app\n',
17
+ }),
18
+ 'codex: $ ./.acryl/bin/acryl act click --ref 7.15 --json',
19
+ )
20
+ for (const info of [
21
+ 'hook: PreToolUse\nhook: PreToolUse\n',
22
+ 'hook: PostToolUse Completed\n',
23
+ 'tokens used\n28,838\n',
24
+ '',
25
+ ' succeeded in 16ms:\n{"ok":true}\n',
26
+ ])
27
+ assert.equal(describeTool({ tool: 'codex', info }), undefined, JSON.stringify(info))
28
+ assert.equal(
29
+ describeTool({ tool: 'codex', info: ' exited 1 in 40ms:\nboom\n' }),
30
+ 'codex: exited 1 in 40ms',
31
+ )
32
+ })
33
+
34
+ test("a coding agent's own sentence is shown, clipped", () => {
35
+ assert.equal(
36
+ describeTool({ tool: 'claude', info: 'Reading plugins/board/index.ts' }),
37
+ 'claude: Reading plugins/board/index.ts',
38
+ )
39
+ const long = describeTool({ tool: 'pi', info: 'x'.repeat(500) }) ?? ''
40
+ assert.ok(long.length <= 'pi: '.length + 160, String(long.length))
41
+ assert.ok(long.endsWith('…'))
42
+ })
43
+
44
+ test("the app's own agent: the tool and a short form of its arguments, and a failure with its reason", () => {
45
+ assert.equal(describeTool({ tool: 'door_look', input: {}, result: 'Page: Demo' }), 'door_look')
46
+ assert.equal(
47
+ describeTool({ tool: 'door_act', input: { op: 'click', ref: '3.1' }, result: 'done' }),
48
+ 'door_act {"op":"click","ref":"3.1"}',
49
+ )
50
+ assert.equal(
51
+ describeTool({ tool: 'door_act', input: {}, error: 'invalid: a call needs an op' }),
52
+ 'door_act failed: invalid: a call needs an op',
53
+ )
54
+ })
55
+
56
+ test("the Assistant's steps say what it did on the page, named as the page names it, and leave out its looks", () => {
57
+ const act = (input: Record<string, unknown>, result?: unknown) =>
58
+ describePageStep({ tool: 'door_act', input, ...(result === undefined ? {} : { result }) })
59
+ assert.equal(describePageStep({ tool: 'door_look', input: {}, result: 'Page: Board' }), undefined)
60
+ assert.equal(
61
+ describePageStep({ tool: 'door_look', input: {}, error: 'no page' }),
62
+ 'ui.look() failed',
63
+ )
64
+ assert.equal(
65
+ act({ op: 'click', ref: '1.6' }, { ok: true, target: { role: 'link', name: 'My tasks' } }),
66
+ 'ui.open("My tasks")',
67
+ )
68
+ assert.equal(act({ op: 'navigate', path: '/my-tasks' }, { ok: true }), 'ui.open("/my-tasks")')
69
+ assert.equal(
70
+ act(
71
+ { op: 'select', ref: '3.10', option: 'This week' },
72
+ { ok: true, target: { role: 'combobox', name: 'Due' } },
73
+ ),
74
+ 'ui.fill("Due", "This week")',
75
+ )
76
+ assert.equal(
77
+ act(
78
+ { op: 'type', ref: '4.2', text: 'Book the venue' },
79
+ { ok: true, target: { role: 'textbox', name: 'Title' } },
80
+ ),
81
+ 'ui.fill("Title", "Book the venue")',
82
+ )
83
+ assert.equal(
84
+ act({ op: 'click', ref: '5.1' }, { ok: true, target: { role: 'button', name: 'Save' } }),
85
+ 'ui.click("Save")',
86
+ )
87
+ // No name from the page: the ref stands in; a failed act says so.
88
+ assert.equal(
89
+ describePageStep({ tool: 'door_act', input: { op: 'click', ref: '5.1' }, error: 'stale-ref' }),
90
+ 'ui.click(5.1) failed',
91
+ )
92
+ assert.equal(act({ op: 'press', key: 'Enter' }, { ok: true }), 'ui.press("Enter")')
93
+ // The door's chat tool answers in text; the target is read from it.
94
+ assert.equal(
95
+ act(
96
+ { op: 'select', ref: '1.11', option: 'This week' },
97
+ 'done: combobox "Due" (selected This week); look again before the next act',
98
+ ),
99
+ 'ui.fill("Due", "This week")',
100
+ )
101
+ assert.equal(
102
+ act({ op: 'click', ref: '1.6' }, 'done: link "My tasks"; look again before the next act'),
103
+ 'ui.open("My tasks")',
104
+ )
105
+ })
@@ -0,0 +1,24 @@
1
+ // The guard behind the panel's choose(): a terminal that finishes loading after the person picked another driver
2
+ // must not apply. The gate proves the whole switch; this pins the rule choose() consults.
3
+ import assert from 'node:assert/strict'
4
+ import { test } from 'node:test'
5
+ import { createPickGeneration } from '../client/driver-pick.ts'
6
+
7
+ test('a stale terminal pick never applies after a newer pick', () => {
8
+ const picks = createPickGeneration()
9
+ const terminal = picks.begin()
10
+ const agent = picks.begin()
11
+ assert.equal(picks.isCurrent(terminal), false)
12
+ assert.equal(picks.isCurrent(agent), true)
13
+ // A third pick invalidates the second the same way.
14
+ const third = picks.begin()
15
+ assert.equal(picks.isCurrent(agent), false)
16
+ assert.equal(picks.isCurrent(third), true)
17
+ })
18
+
19
+ test('the first pick is current until another begins', () => {
20
+ const picks = createPickGeneration()
21
+ const first = picks.begin()
22
+ assert.equal(picks.isCurrent(first), true)
23
+ assert.equal(picks.isCurrent(first - 1), false)
24
+ })
@@ -0,0 +1,35 @@
1
+ import assert from 'node:assert/strict'
2
+ import { describe, test } from 'node:test'
3
+ import { FRAME_VIEW_KEY, frameViewOf, panelVariant, panelVisible } from '../client/frame.ts'
4
+
5
+ /** The frame's view as the app page reads it: the panel is hidden in Build and follows production in Preview. */
6
+ describe('the frame view a page reads', () => {
7
+ const handle = { mode: 'build' as const }
8
+
9
+ test('is the handle a same-origin parent publishes, and nothing at the top window or under a cross-origin parent', () => {
10
+ assert.equal(frameViewOf({ parent: { [FRAME_VIEW_KEY]: handle } } as unknown as Window), handle)
11
+ const top: { parent: unknown } = { parent: undefined }
12
+ top.parent = top
13
+ assert.equal(frameViewOf(top as unknown as Window), undefined)
14
+ const crossOrigin = {
15
+ get parent(): unknown {
16
+ throw new Error('cross-origin')
17
+ },
18
+ }
19
+ assert.equal(frameViewOf(crossOrigin as unknown as Window), undefined)
20
+ })
21
+
22
+ test('takes the Assistant variant only where production has it', () => {
23
+ assert.equal(panelVariant({ assistant: true }, undefined), true)
24
+ assert.equal(panelVariant({ assistantInProduction: true }, handle), true)
25
+ assert.equal(panelVariant({ assistantInProduction: true }, undefined), false)
26
+ assert.equal(panelVariant({}, handle), false)
27
+ })
28
+
29
+ test('shows the panel on a direct page, and in the frame only in Preview as the Assistant', () => {
30
+ assert.equal(panelVisible(undefined, false), true)
31
+ assert.equal(panelVisible(handle, true), false)
32
+ assert.equal(panelVisible({ mode: 'preview' }, false), false)
33
+ assert.equal(panelVisible({ mode: 'preview' }, true), true)
34
+ })
35
+ })