@acryldev/agent-panel 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/client/describe.ts +101 -0
- package/client/driver-pick.ts +22 -0
- package/client/frame.ts +51 -0
- package/client/main.ts +707 -0
- package/client/markdown.ts +219 -0
- package/headless.ts +220 -0
- package/index.ts +523 -0
- package/launch.ts +67 -0
- package/lib/client/describe.ts +101 -0
- package/lib/client/driver-pick.ts +22 -0
- package/lib/client/frame.ts +51 -0
- package/lib/client/main.ts +707 -0
- package/lib/client/markdown.ts +219 -0
- package/lib/headless-B_RGxZFU.js +252 -0
- package/lib/headless-B_RGxZFU.js.map +1 -0
- package/lib/headless.js +2 -0
- package/lib/index.js +562 -0
- package/lib/index.js.map +1 -0
- package/lib/mount.js +25 -0
- package/lib/mount.js.map +1 -0
- package/lib/registry.js +13 -0
- package/lib/registry.js.map +1 -0
- package/lib/types/headless.d.ts +22 -0
- package/lib/types/index.d.ts +22 -0
- package/lib/types/launch.d.ts +18 -0
- package/lib/types/mount.d.ts +12 -0
- package/lib/types/registry.d.ts +10 -0
- package/lib/types/tsdown.config.d.ts +2 -0
- package/lib/types/visitors.d.ts +82 -0
- package/mount.ts +27 -0
- package/package.json +62 -3
- package/plugin.json +28 -0
- package/registry.ts +17 -0
- package/scripts/copy-assets.mjs +5 -0
- package/test/client-guards.test.ts +13 -0
- package/test/describe.test.ts +105 -0
- package/test/driver-pick.test.ts +24 -0
- package/test/frame.test.ts +35 -0
- package/test/launch.test.ts +90 -0
- package/test/markdown.test.ts +79 -0
- package/test/panel-client.test.ts +150 -0
- package/test/panel.test.ts +534 -0
- package/test/socket.test.ts +209 -0
- package/test/visitors.test.ts +112 -0
- package/test/why.test.ts +61 -0
- package/tsconfig.json +21 -0
- package/tsdown.config.ts +23 -0
- package/visitors.ts +231 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 acrylblends
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// One line for a tool event of the panel's conversation: what the tool is doing, not only its name. A coding agent started in the folder reports its own log (`{ tool: 'codex', info }`):
|
|
2
|
+
// its bookkeeping is dropped and its command or sentence is kept. The app's own agent reports a call (`{ tool, input, result | error }`): the name and a short form of the arguments.
|
|
3
|
+
|
|
4
|
+
const MAX = 160
|
|
5
|
+
|
|
6
|
+
const clip = (text: string): string => (text.length > MAX ? `${text.slice(0, MAX - 1)}…` : text)
|
|
7
|
+
|
|
8
|
+
/** A shell command as the agent's log writes it: `/bin/zsh -lc 'npm test' in /path/to/app` becomes `npm test`. */
|
|
9
|
+
function commandOf(line: string): string {
|
|
10
|
+
const withoutCwd = line.replace(/ in \/\S+\s*$/u, '')
|
|
11
|
+
const wrapped = /^(?:\/\S*\/)?(?:ba|z|da)?sh -l?c (['"])([\s\S]*)\1$/u.exec(withoutCwd.trim())
|
|
12
|
+
return wrapped?.[2] ?? withoutCwd.trim()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @returns the line to show, or `undefined` when the event says nothing worth a line (a hook ran, a token count). */
|
|
16
|
+
export function describeTool(data: Record<string, unknown>): string | undefined {
|
|
17
|
+
const tool = String(data.tool ?? '')
|
|
18
|
+
if (typeof data.info === 'string') {
|
|
19
|
+
const lines = data.info
|
|
20
|
+
.split('\n')
|
|
21
|
+
.map((line) => line.trim())
|
|
22
|
+
.filter(
|
|
23
|
+
(line) =>
|
|
24
|
+
line !== '' &&
|
|
25
|
+
!/^hook:/u.test(line) &&
|
|
26
|
+
!/^tokens used/u.test(line) &&
|
|
27
|
+
!/^[\d,]+$/u.test(line),
|
|
28
|
+
)
|
|
29
|
+
if (lines.length === 0) return undefined
|
|
30
|
+
const [first = '', second = ''] = lines
|
|
31
|
+
if (first === 'exec') return second === '' ? undefined : `${tool}: $ ${clip(commandOf(second))}`
|
|
32
|
+
// The output of a command that ran: only a failure is worth a line.
|
|
33
|
+
if (/^succeeded in /u.test(first)) return undefined
|
|
34
|
+
if (/^exited \d+/u.test(first)) return `${tool}: ${clip(first.replace(/:$/u, ''))}`
|
|
35
|
+
return `${tool}: ${clip(lines.join(' '))}`
|
|
36
|
+
}
|
|
37
|
+
const input =
|
|
38
|
+
data.input === undefined ||
|
|
39
|
+
(typeof data.input === 'object' && data.input !== null && Object.keys(data.input).length === 0)
|
|
40
|
+
? ''
|
|
41
|
+
: ` ${clip(JSON.stringify(data.input))}`
|
|
42
|
+
const failed = data.error ? ` failed: ${clip(String(data.error))}` : ''
|
|
43
|
+
return `${tool}${input}${failed}`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** What an act touched, from its result: the door's chat tool answers `done: link "My tasks" (detail); look again before the next act`, its verb `{ target }`. */
|
|
47
|
+
function targetOf(result: unknown): { role?: string; name?: string } {
|
|
48
|
+
if (typeof result === 'string') {
|
|
49
|
+
const match = /^done: (\S+) "(.*)"(?: \(.*\))?; look again/u.exec(result)
|
|
50
|
+
return match === null ? {} : { role: match[1], name: match[2] }
|
|
51
|
+
}
|
|
52
|
+
if (typeof result !== 'object' || result === null) return {}
|
|
53
|
+
const target = (result as { target?: unknown }).target
|
|
54
|
+
if (typeof target !== 'object' || target === null) return {}
|
|
55
|
+
const { role, name } = target as { role?: unknown; name?: unknown }
|
|
56
|
+
return {
|
|
57
|
+
...(typeof role === 'string' ? { role } : {}),
|
|
58
|
+
...(typeof name === 'string' ? { name } : {}),
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The Assistant's step on the page, as the person reads it under the answer: what it did, named the way the page names it. `ui.open("My tasks")`,
|
|
64
|
+
* `ui.fill("Due", "This week")`, `ui.click("Save")`, `ui.press("Enter")`. A look changes nothing, so it is left out unless it failed. The control's name comes from the
|
|
65
|
+
* act's result (the page says what it acted on); the ref is the fallback.
|
|
66
|
+
*/
|
|
67
|
+
export function describePageStep(data: Record<string, unknown>): string | undefined {
|
|
68
|
+
const failed = data.error ? ' failed' : ''
|
|
69
|
+
if (data.tool === 'door_look') return failed === '' ? undefined : 'ui.look() failed'
|
|
70
|
+
if (data.tool !== 'door_act') return describeTool(data)
|
|
71
|
+
const input = (typeof data.input === 'object' && data.input !== null ? data.input : {}) as Record<
|
|
72
|
+
string,
|
|
73
|
+
unknown
|
|
74
|
+
>
|
|
75
|
+
const target = targetOf(data.result)
|
|
76
|
+
const quoted = (value: unknown): string => JSON.stringify(clip(String(value ?? '')))
|
|
77
|
+
const op = typeof input.op === 'string' ? input.op : 'act'
|
|
78
|
+
const named =
|
|
79
|
+
typeof target.name === 'string' && target.name !== ''
|
|
80
|
+
? quoted(target.name)
|
|
81
|
+
: typeof input.ref === 'string'
|
|
82
|
+
? input.ref
|
|
83
|
+
: undefined
|
|
84
|
+
const [verb, args]: [string, readonly (string | undefined)[]] =
|
|
85
|
+
op === 'navigate'
|
|
86
|
+
? ['open', [quoted(input.path)]]
|
|
87
|
+
: op === 'click' && target.role === 'link'
|
|
88
|
+
? ['open', [named]]
|
|
89
|
+
: op === 'type'
|
|
90
|
+
? ['fill', [named, quoted(input.text)]]
|
|
91
|
+
: op === 'select'
|
|
92
|
+
? ['fill', [named, quoted(input.option)]]
|
|
93
|
+
: op === 'press'
|
|
94
|
+
? ['press', [quoted(input.key)]]
|
|
95
|
+
: op === 'scroll'
|
|
96
|
+
? ['scroll', [input.direction === undefined ? undefined : quoted(input.direction)]]
|
|
97
|
+
: op === 'wait'
|
|
98
|
+
? ['wait', [quoted(input.text ?? input.name)]]
|
|
99
|
+
: [op, [named]]
|
|
100
|
+
return `ui.${verb}(${args.filter((arg) => arg !== undefined).join(', ')})${failed}`
|
|
101
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which driver pick a finished terminal open may apply to. `choose()` can be in flight when the person picks
|
|
3
|
+
* another driver (the panel also restores a remembered terminal at start), and only the latest pick may win: a
|
|
4
|
+
* stale terminal must not replace the form the person chose.
|
|
5
|
+
*/
|
|
6
|
+
export interface PickGeneration {
|
|
7
|
+
/** Start a pick and return the token its result is settled with. */
|
|
8
|
+
begin(): number
|
|
9
|
+
/** True only while `generation` is still the latest pick. */
|
|
10
|
+
isCurrent(generation: number): boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createPickGeneration(): PickGeneration {
|
|
14
|
+
let generation = 0
|
|
15
|
+
return {
|
|
16
|
+
begin: () => {
|
|
17
|
+
generation += 1
|
|
18
|
+
return generation
|
|
19
|
+
},
|
|
20
|
+
isCurrent: (candidate) => candidate === generation,
|
|
21
|
+
}
|
|
22
|
+
}
|
package/client/frame.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ACRYL frame's view as the app page sees it (plugins/blends-frame/src/client/frame-view.ts): the frame's canvas hides the app's own build-time
|
|
3
|
+
* controls in Build and shows what production shows in Preview. The page is same-origin with the frame, so it reads the handle the frame publishes on
|
|
4
|
+
* its window through `window.parent`; a page opened directly has no such parent and keeps its own behavior.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const FRAME_VIEW_KEY: symbol = Symbol.for('acryl.frame.view')
|
|
8
|
+
export const FRAME_MODE_EVENT = 'acryl:frame-mode'
|
|
9
|
+
|
|
10
|
+
/** What the app page reads from `window.parent[FRAME_VIEW_KEY]`. */
|
|
11
|
+
export interface FrameViewHandle {
|
|
12
|
+
readonly mode: 'build' | 'preview'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The frame's view handle when this page runs in the frame's canvas.
|
|
17
|
+
* @param win - the page's window.
|
|
18
|
+
* @returns the handle, or undefined when the page is the top window or its parent is cross-origin.
|
|
19
|
+
*/
|
|
20
|
+
export function frameViewOf(win: Window = window): FrameViewHandle | undefined {
|
|
21
|
+
try {
|
|
22
|
+
if (win.parent === win) return undefined
|
|
23
|
+
return (win.parent as unknown as Record<symbol, FrameViewHandle | undefined>)[FRAME_VIEW_KEY]
|
|
24
|
+
} catch {
|
|
25
|
+
return undefined
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether the panel is the production Assistant: the Host itself is the Assistant, or the app's production environment names it (ACRYL_ASSISTANT=on)
|
|
31
|
+
* and the page runs in the frame, whose Preview shows the app as production would.
|
|
32
|
+
* @param session - the panel's session from its Host.
|
|
33
|
+
* @param frame - the frame's view handle, if any.
|
|
34
|
+
*/
|
|
35
|
+
export function panelVariant(
|
|
36
|
+
session: { readonly assistant?: boolean; readonly assistantInProduction?: boolean },
|
|
37
|
+
frame: FrameViewHandle | undefined,
|
|
38
|
+
): boolean {
|
|
39
|
+
if (session.assistant === true) return true
|
|
40
|
+
return frame !== undefined && session.assistantInProduction === true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether the panel shows at all: on a page opened directly, yes; in the frame, only in Preview, and only as the Assistant. Build is the builder's
|
|
45
|
+
* screen, where the app's own panel has no place over the canvas.
|
|
46
|
+
* @param frame - the frame's view handle, if any.
|
|
47
|
+
* @param assistant - whether this panel is the production Assistant (see {@link panelVariant}).
|
|
48
|
+
*/
|
|
49
|
+
export function panelVisible(frame: FrameViewHandle | undefined, assistant: boolean): boolean {
|
|
50
|
+
return frame === undefined || (frame.mode === 'preview' && assistant)
|
|
51
|
+
}
|