@acryldev/harness-runtime 0.0.0-stage → 0.2.12
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 +49 -0
- package/README.md +14 -2
- package/lib/index.mjs +5693 -0
- package/lib/index.mjs.map +1 -0
- package/lib/types/acryl-home.d.ts +81 -0
- package/lib/types/app/new-app.d.ts +65 -0
- package/lib/types/app/start-source.d.ts +47 -0
- package/lib/types/blueprint/blueprint.d.ts +74 -0
- package/lib/types/blueprint/brand-identity.d.ts +26 -0
- package/lib/types/blueprint/compose.d.ts +53 -0
- package/lib/types/blueprint/definition.d.ts +22 -0
- package/lib/types/blueprint/index.d.ts +7 -0
- package/lib/types/blueprint/manifest.d.ts +35 -0
- package/lib/types/blueprint/selection.d.ts +19 -0
- package/lib/types/cli-market-install.d.ts +97 -0
- package/lib/types/cli-market-plugins.d.ts +81 -0
- package/lib/types/coding-capabilities.d.ts +29 -0
- package/lib/types/durable-message.d.ts +18 -0
- package/lib/types/engine-dsh.d.ts +181 -0
- package/lib/types/engine-files.d.ts +8 -0
- package/lib/types/engine-host.d.ts +32 -0
- package/lib/types/engine-tools.d.ts +11 -0
- package/lib/types/index.d.ts +67 -0
- package/lib/types/instance/announce-self.d.ts +38 -0
- package/lib/types/instance/app-instance.d.ts +125 -0
- package/lib/types/instance/index.d.ts +6 -0
- package/lib/types/instance/offline-lock.d.ts +29 -0
- package/lib/types/instance/online-secret.d.ts +29 -0
- package/lib/types/instance/registry.d.ts +26 -0
- package/lib/types/instance/select.d.ts +43 -0
- package/lib/types/module-hooks.d.ts +19 -0
- package/lib/types/module-resolution.d.ts +31 -0
- package/lib/types/package-overlay.d.ts +41 -0
- package/lib/types/pinned-pnpm.d.ts +15 -0
- package/lib/types/plugin-acryl-workspace-status.d.ts +24 -0
- package/lib/types/plugin-doctor.d.ts +49 -0
- package/lib/types/plugin-lifecycle-state.d.ts +92 -0
- package/lib/types/plugin-lifecycle.d.ts +87 -0
- package/lib/types/profile-layout.d.ts +17 -0
- package/lib/types/profile-owner.d.ts +25 -0
- package/lib/types/profile-repair/backup.d.ts +37 -0
- package/lib/types/profile-repair/findings.d.ts +29 -0
- package/lib/types/profile-repair/index.d.ts +9 -0
- package/lib/types/profile-repair/inspector.d.ts +11 -0
- package/lib/types/profile-repair/repair.d.ts +38 -0
- package/lib/types/profile-resolution/moved-framework.d.ts +21 -0
- package/lib/types/profile-resolution/resolver.d.ts +41 -0
- package/lib/types/profile-resolution/service.d.ts +22 -0
- package/lib/types/prompt-budget.d.ts +44 -0
- package/lib/types/session-bridge.d.ts +57 -0
- package/lib/types/session-log-exporter.d.ts +31 -0
- package/lib/types/system-prompt-capture.d.ts +29 -0
- package/lib/types/web-favicon-data.d.ts +5 -0
- package/lib/types/web-favicon.d.ts +23 -0
- package/lib/types/web-market-install.d.ts +114 -0
- package/lib/types/web-market-plugins.d.ts +106 -0
- package/lib/types/web-port.d.ts +15 -0
- package/package.json +211 -3
- package/src/acryl-home.ts +103 -0
- package/src/app/new-app.ts +239 -0
- package/src/app/start-source.ts +110 -0
- package/src/blueprint/blueprint.ts +141 -0
- package/src/blueprint/brand-identity.ts +75 -0
- package/src/blueprint/compose.ts +222 -0
- package/src/blueprint/definition.ts +92 -0
- package/src/blueprint/index.ts +20 -0
- package/src/blueprint/manifest.ts +145 -0
- package/src/blueprint/selection.ts +74 -0
- package/src/cli-market-install.ts +181 -0
- package/src/cli-market-plugins.ts +176 -0
- package/src/coding-capabilities.ts +61 -0
- package/src/durable-message.ts +23 -0
- package/src/engine-dsh.ts +856 -0
- package/src/engine-files.ts +9 -0
- package/src/engine-host.ts +128 -0
- package/src/engine-tools.ts +26 -0
- package/src/index.ts +436 -0
- package/src/instance/announce-self.ts +88 -0
- package/src/instance/app-instance.ts +240 -0
- package/src/instance/index.ts +45 -0
- package/src/instance/offline-lock.ts +71 -0
- package/src/instance/online-secret.ts +55 -0
- package/src/instance/registry.ts +53 -0
- package/src/instance/select.ts +134 -0
- package/src/module-hooks.ts +41 -0
- package/src/module-resolution.ts +187 -0
- package/src/package-overlay.ts +160 -0
- package/src/pinned-pnpm.ts +67 -0
- package/src/plugin-acryl-workspace-status.ts +99 -0
- package/src/plugin-doctor.ts +141 -0
- package/src/plugin-lifecycle-state.ts +347 -0
- package/src/plugin-lifecycle.ts +223 -0
- package/src/profile-layout.ts +97 -0
- package/src/profile-owner.ts +52 -0
- package/src/profile-repair/backup.ts +119 -0
- package/src/profile-repair/findings.ts +43 -0
- package/src/profile-repair/index.ts +10 -0
- package/src/profile-repair/inspector.ts +156 -0
- package/src/profile-repair/repair.ts +137 -0
- package/src/profile-resolution/moved-framework.ts +64 -0
- package/src/profile-resolution/resolver.ts +876 -0
- package/src/profile-resolution/service.ts +99 -0
- package/src/prompt-budget.ts +118 -0
- package/src/session-bridge.ts +350 -0
- package/src/session-log-exporter.ts +68 -0
- package/src/system-prompt-capture.ts +99 -0
- package/src/web-favicon-data.ts +6 -0
- package/src/web-favicon.ts +43 -0
- package/src/web-market-install.ts +206 -0
- package/src/web-market-plugins.ts +215 -0
- package/src/web-port.ts +39 -0
- package/tests/account-callback.spec.ts +173 -0
- package/tests/acryl-home.spec.ts +39 -0
- package/tests/agent-self-hosting.spec.ts +101 -0
- package/tests/announce-self.spec.ts +84 -0
- package/tests/app-lifecycle.spec.ts +99 -0
- package/tests/blank-blueprint.spec.ts +110 -0
- package/tests/blueprint-definition.spec.ts +128 -0
- package/tests/blueprint.spec.ts +138 -0
- package/tests/bulkhead.spec.ts +187 -0
- package/tests/coding-vocabulary.spec.ts +15 -0
- package/tests/dump-system-prompt.spec.ts +65 -0
- package/tests/e2e-real-model.spec.ts +71 -0
- package/tests/e2e-restart-real-model.spec.ts +77 -0
- package/tests/engine-dsh.spec.ts +340 -0
- package/tests/engine-host-mount-root-include.spec.ts +118 -0
- package/tests/engine-host.spec.ts +176 -0
- package/tests/engine-optional.spec.ts +81 -0
- package/tests/extension-examples.spec.ts +261 -0
- package/tests/hooks-thread-stack.ts +27 -0
- package/tests/instance-patches.spec.ts +25 -0
- package/tests/instance.spec.ts +235 -0
- package/tests/live/community-plugins.spec.ts +83 -0
- package/tests/module-hooks.spec.ts +35 -0
- package/tests/module-resolution.spec.ts +265 -0
- package/tests/moved-framework.spec.ts +61 -0
- package/tests/new-app.spec.ts +132 -0
- package/tests/organizer-growth.spec.ts +117 -0
- package/tests/pinned-pnpm.spec.ts +34 -0
- package/tests/plugin-acryl-workspace-status.spec.ts +63 -0
- package/tests/plugin-context.spec.ts +640 -0
- package/tests/plugin-doctor.spec.ts +183 -0
- package/tests/plugin-enablement-one-store.spec.ts +130 -0
- package/tests/plugin-lifecycle-state.spec.ts +169 -0
- package/tests/profile-layout.spec.ts +58 -0
- package/tests/profile-owner.spec.ts +38 -0
- package/tests/profile-repair/profile-repair.spec.ts +231 -0
- package/tests/profile-resolution-port.spec.ts +30 -0
- package/tests/profile-resolution-service.spec.ts +273 -0
- package/tests/profile-resolution-swap.spec.ts +69 -0
- package/tests/profile-resolution.spec.ts +2535 -0
- package/tests/profile.spec.ts +70 -0
- package/tests/project-registry.spec.ts +81 -0
- package/tests/prompt-budget.spec.ts +58 -0
- package/tests/real-home-guard.spec.ts +178 -0
- package/tests/session-bridge.spec.ts +316 -0
- package/tests/start-source.spec.ts +65 -0
- package/tests/system-prompt-shape.spec.ts +95 -0
- package/tests/three-levels.spec.ts +84 -0
- package/tests/tool-gateway.spec.ts +116 -0
- package/tests/tool-schemas.spec.ts +41 -0
- package/tests/web-favicon.spec.ts +42 -0
- package/tests/web-port.spec.ts +38 -0
- package/tests/web-startup-hold.spec.ts +79 -0
- package/tsconfig.json +24 -0
- package/tsdown.config.ts +2 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bulkheads (spec 036, "Self-containment"). Two guarantees, tested where they could break:
|
|
3
|
+
*
|
|
4
|
+
* 1. Architecture: no code outside the selector (`src/instance/select.ts`) decides where an app lives. Reading ACRYL_HOME, DSH_HOME, ACRYL_WEB_PORT,
|
|
5
|
+
* ACRYL_WEB_HOST, ACRYL_WEB_TRUSTED_HOSTS, ACRYL_INSTANCE or ACRYL_LOCAL_PRODUCT_NAME, or calling `homedir()`, anywhere else is how a run fell back to a shared home and blanked another app.
|
|
6
|
+
* 2. Behavior: two apps booted on real engines at the same time share no file, profile, port or service value.
|
|
7
|
+
*/
|
|
8
|
+
import { readdirSync, readFileSync, realpathSync, statSync, writeFileSync, mkdirSync } from 'node:fs'
|
|
9
|
+
import { mkdtemp, rm } from 'node:fs/promises'
|
|
10
|
+
import { tmpdir } from 'node:os'
|
|
11
|
+
import { join, relative, sep } from 'node:path'
|
|
12
|
+
import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
13
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
14
|
+
import { createWebEngineDefinition } from '../src/engine-dsh.ts'
|
|
15
|
+
import { createAcrylEngineHost } from '../src/engine-host.ts'
|
|
16
|
+
import type { AppInstance } from '../src/instance/index.ts'
|
|
17
|
+
import { fileURLToPath } from 'node:url'
|
|
18
|
+
import { inBlendApp } from '../../../scripts/lib/blend-apps.mjs'
|
|
19
|
+
import { codingCapabilities } from '@acryldev/coding-capabilities'
|
|
20
|
+
|
|
21
|
+
const repo = realpathSync(fileURLToPath(new URL('../../..', import.meta.url)))
|
|
22
|
+
|
|
23
|
+
/** Source roots of everything ACRYL ships or launches with. */
|
|
24
|
+
const ROOTS = ['runtime', 'apps', 'plugins', 'scripts']
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The only places allowed to look at the OS home or the placement variables, each with its reason. Anything else is a hidden Singleton.
|
|
28
|
+
*/
|
|
29
|
+
const ALLOWED: Readonly<Record<string, string>> = {
|
|
30
|
+
'runtime/harness-runtime/src/instance/select.ts': 'the selector: the one place an app instance is chosen',
|
|
31
|
+
// The framework's selector for Blend apps (personHome, acrylRoot: ~/.acryl, moved by ACRYL_HOME for isolated runs), the counterpart of
|
|
32
|
+
// src/instance/select.ts outside ACRYL's runtime; framework/scripts/lib/bulkhead.test.mjs owns its rule. One file, one reason: every other
|
|
33
|
+
// library plugin stays under this scan.
|
|
34
|
+
'plugins/instance/home.ts': 'the framework\'s instance home selector for Blend apps, the counterpart of src/instance/select.ts outside ACRYL\'s runtime',
|
|
35
|
+
'plugins/workspace/src/pty/service.ts': 'a terminal starts in the user\'s own home folder when the cwd is gone; not ACRYL state',
|
|
36
|
+
'plugins/launcher-desktop/blend/host/index.ts': 'the launcher Blend runs outside ACRYL\'s runtime (no appInstance); its home is ~/.acryl, the one home of every ACRYL app',
|
|
37
|
+
'scripts/graft-deepscan.mjs': 'a repository indexing tool; not part of any app',
|
|
38
|
+
'scripts/real-home-guard.mjs': 'the gate\'s auditor: it must know the OS user\'s real homes to prove no test changed one; it only reads them, and it is not part of any app',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const AMBIENT = [
|
|
42
|
+
{ name: 'homedir()', pattern: /\bhomedir\(\)/u },
|
|
43
|
+
{ name: 'a placement variable read', pattern: /\benv(?:\.|\[['"])(ACRYL_HOME|DSH_HOME|ACRYL_WEB_PORT|ACRYL_WEB_HOST|ACRYL_WEB_TRUSTED_HOSTS|ACRYL_INSTANCE|ACRYL_LOCAL_PRODUCT_NAME)\b(?!['"]?\]?\s*=(?!=))/u },
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
function sources(dir: string): string[] {
|
|
47
|
+
const out: string[] = []
|
|
48
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
49
|
+
if (['node_modules', 'lib', 'lib-publish', 'dist', 'tests', 'test', 'fixtures', 'example-plugins', '.turbo'].includes(entry.name)) continue
|
|
50
|
+
const path = join(dir, entry.name)
|
|
51
|
+
if (entry.isDirectory()) out.push(...sources(path))
|
|
52
|
+
else if (/\.(ts|tsx|mts|js|mjs)$/u.test(entry.name) && !/\.(test|spec)\./u.test(entry.name)) out.push(path)
|
|
53
|
+
}
|
|
54
|
+
return out
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Every home read outside ALLOWED under `root`'s ROOTS. The listed Blend apps (scripts/lib/blend-apps.mjs) are skipped: they run on the framework's own
|
|
59
|
+
* instance plugin outside ACRYL's runtime, like framework/, which is not scanned either (spec 051 T013, D5). Only that list exempts a folder.
|
|
60
|
+
*/
|
|
61
|
+
function offencesIn(root: string): string[] {
|
|
62
|
+
const offences: string[] = []
|
|
63
|
+
for (const top of ROOTS) {
|
|
64
|
+
let files: string[]
|
|
65
|
+
try {
|
|
66
|
+
files = sources(join(root, top))
|
|
67
|
+
} catch {
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
for (const file of files) {
|
|
71
|
+
const path = relative(root, file).split(sep).join('/')
|
|
72
|
+
if (path in ALLOWED || inBlendApp(path)) continue
|
|
73
|
+
const text = readFileSync(file, 'utf8').split('\n')
|
|
74
|
+
text.forEach((line, index) => {
|
|
75
|
+
if (/^\s*(\*|\/\/)/u.test(line)) return // comments may name the variables
|
|
76
|
+
for (const rule of AMBIENT) if (rule.pattern.test(line)) offences.push(`${path}:${String(index + 1)} ${rule.name}: ${line.trim().slice(0, 120)}`)
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return offences
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('bulkhead architecture', () => {
|
|
84
|
+
it('only the selector decides where an app lives', () => {
|
|
85
|
+
expect(offencesIn(repo)).toEqual([])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('a folder that grows a blend.yaml is still scanned; only the listed Blend apps are not', async () => {
|
|
89
|
+
const root = await mkdtemp(join(tmpdir(), 'bulkhead-'))
|
|
90
|
+
try {
|
|
91
|
+
for (const folder of ['plugins/x', 'apps/acryl-ade']) {
|
|
92
|
+
mkdirSync(join(root, folder, 'src'), { recursive: true })
|
|
93
|
+
writeFileSync(join(root, folder, 'blend.yaml'), 'id: x\n')
|
|
94
|
+
writeFileSync(join(root, folder, 'src', 'home.ts'), "import { homedir } from 'node:os'\nexport const home = homedir()\n")
|
|
95
|
+
}
|
|
96
|
+
expect(offencesIn(root)).toEqual(["plugins/x/src/home.ts:2 homedir(): export const home = homedir()"])
|
|
97
|
+
} finally {
|
|
98
|
+
await rm(root, { recursive: true, force: true })
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('the framework selector is allowed by file, so a home read in another library plugin is still caught', async () => {
|
|
103
|
+
const root = await mkdtemp(join(tmpdir(), 'bulkhead-'))
|
|
104
|
+
try {
|
|
105
|
+
for (const folder of ['plugins/instance', 'plugins/desktop-shell/src']) {
|
|
106
|
+
mkdirSync(join(root, folder), { recursive: true })
|
|
107
|
+
writeFileSync(join(root, folder, 'home.ts'), "import { homedir } from 'node:os'\nexport const home = homedir()\n")
|
|
108
|
+
}
|
|
109
|
+
// plugin.json is the library marker; the exemption is a file, not a marker, so the desktop copy stays caught.
|
|
110
|
+
writeFileSync(join(root, 'plugins', 'desktop-shell', 'plugin.json'), '{}')
|
|
111
|
+
expect(offencesIn(root)).toEqual(['plugins/desktop-shell/src/home.ts:2 homedir(): export const home = homedir()'])
|
|
112
|
+
} finally {
|
|
113
|
+
await rm(root, { recursive: true, force: true })
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('the allow-list only names files that exist', () => {
|
|
118
|
+
for (const path of Object.keys(ALLOWED)) expect(statSync(join(repo, path)).isFile(), path).toBe(true)
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const saved = { ...process.env }
|
|
123
|
+
const temporary: string[] = []
|
|
124
|
+
afterEach(async () => {
|
|
125
|
+
for (const key of Object.keys(process.env)) if (!(key in saved)) delete process.env[key]
|
|
126
|
+
Object.assign(process.env, saved)
|
|
127
|
+
await Promise.all(temporary.splice(0).map(path => rm(path, { force: true, recursive: true })))
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
async function bootApp(folder: string) {
|
|
131
|
+
// What `bin/acryl` hands an app: its folder as its home.
|
|
132
|
+
for (const key of ['DSH_HOME', 'ACRYL_WEB_PORT', 'ACRYL_WEB_HOST', 'ACRYL_WEB_TRUSTED_HOSTS', 'ACRYL_INSTANCE', 'ACRYL_LOCAL_PRODUCT_NAME', 'ACRYL_BLUEPRINT']) delete process.env[key]
|
|
133
|
+
process.env.ACRYL_HOME = folder
|
|
134
|
+
const host = await createAcrylEngineHost({
|
|
135
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
136
|
+
initialEngine: 'dsh',
|
|
137
|
+
prepare: ctx => { provideCmdline(ctx, { args: ['--no-open'], exit: () => {} }) },
|
|
138
|
+
})
|
|
139
|
+
const instance = host.ctx.get('appInstance' as never) as unknown as AppInstance
|
|
140
|
+
const port = (host.ctx.get('webServer' as never) as unknown as { port: number }).port
|
|
141
|
+
return { host, instance, port }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function filesUnder(dir: string): string[] {
|
|
145
|
+
const out: string[] = []
|
|
146
|
+
const walk = (current: string) => {
|
|
147
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
148
|
+
const path = join(current, entry.name)
|
|
149
|
+
if (entry.isDirectory() && entry.name !== 'node_modules') walk(path)
|
|
150
|
+
else if (entry.isFile()) out.push(path)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
walk(dir)
|
|
154
|
+
return out
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
describe('bulkhead behavior', () => {
|
|
158
|
+
it('two apps running at once share no home, profile, port, user data or project scope, and each writes only inside its own folder', async () => {
|
|
159
|
+
const root = realpathSync(await mkdtemp(join(tmpdir(), 'acryl-bulkhead-')))
|
|
160
|
+
temporary.push(root)
|
|
161
|
+
const app = (name: string, title: string): string => {
|
|
162
|
+
const dir = join(root, name); mkdirSync(join(dir, 'plugins'), { recursive: true })
|
|
163
|
+
writeFileSync(join(dir, 'blend.yaml'), `apiVersion: blends.acryl.dev/v1alpha1\nkind: Blend\nmetadata:\n id: app.${name}\n name: ${title}\n version: 0.1.0\nspec:\n runtime: cordis\n lineage:\n blueprint: acryl.blank\n blueprintVersion: 0.1.0\n rows:\n - id: brand\n name: '@acryldev/brand'\n config:\n name: ${title}\n`)
|
|
164
|
+
return dir
|
|
165
|
+
}
|
|
166
|
+
const music = await bootApp(app('music-editor', 'Music Editor'))
|
|
167
|
+
const social = await bootApp(app('social-machine', 'Social Machine'))
|
|
168
|
+
try {
|
|
169
|
+
for (const key of ['home', 'dshHome', 'userDataName', 'userDataDir', 'runLockFile', 'projectScope'] as const) {
|
|
170
|
+
expect(music.instance[key], key).not.toBe(social.instance[key])
|
|
171
|
+
}
|
|
172
|
+
expect(music.port).not.toBe(social.port)
|
|
173
|
+
for (const one of [music, social]) {
|
|
174
|
+
expect(one.instance.kind).toBe('app')
|
|
175
|
+
for (const file of filesUnder(root)) if (file.startsWith(one.instance.home)) expect(file.startsWith(one.instance.home)).toBe(true)
|
|
176
|
+
}
|
|
177
|
+
// Every file the two apps wrote is inside one of the two app folders: nothing outside, nothing crossing.
|
|
178
|
+
const written = filesUnder(root).map(file => relative(root, file).split(sep)[0])
|
|
179
|
+
expect(new Set(written)).toEqual(new Set(['music-editor', 'social-machine']))
|
|
180
|
+
const brand = (app: typeof music) => (app.host.ctx.get('acrylBrand' as never) as unknown as { identity: { name: string } }).identity.name
|
|
181
|
+
expect([brand(music), brand(social)]).toEqual(['Music Editor', 'Social Machine'])
|
|
182
|
+
} finally {
|
|
183
|
+
await music.host.dispose()
|
|
184
|
+
await social.host.dispose()
|
|
185
|
+
}
|
|
186
|
+
}, 180_000)
|
|
187
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { CODING_CAPABILITY_COMPOSITIONS } from '@acryldev/coding-capabilities'
|
|
3
|
+
import { ACRYL_CODING_CAPABILITIES } from '../src/coding-capabilities.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The two halves of a capability live apart on purpose (spec 051 T021): the runtime keeps the Blueprint vocabulary (which ids exist, and
|
|
7
|
+
* which need the framework router), the surface composition package keeps the rows and packages. They must name the same ids, both ways.
|
|
8
|
+
*/
|
|
9
|
+
describe('the Blueprint vocabulary and the surface composition', () => {
|
|
10
|
+
it('name exactly the same capability ids', () => {
|
|
11
|
+
expect(CODING_CAPABILITY_COMPOSITIONS.map(capability => capability.id).sort()).toEqual(
|
|
12
|
+
ACRYL_CODING_CAPABILITIES.map(capability => capability.id).sort(),
|
|
13
|
+
)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OPT-IN generator for `docs/system-prompt/current/{web,cli}.md`. Skipped unless `ACRYL_DUMP_SYSTEM_PROMPT` names an output directory
|
|
3
|
+
* (relative to the repository root). Desktop is generated by `apps/acryl-desktop` (`corepack pnpm --filter acryl-desktop run dump:system-prompt`).
|
|
4
|
+
*
|
|
5
|
+
* ACRYL_DUMP_SYSTEM_PROMPT=docs/system-prompt/current corepack pnpm --filter @acryldev/harness-runtime exec vitest run tests/dump-system-prompt.spec.ts
|
|
6
|
+
*/
|
|
7
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
8
|
+
import { tmpdir } from 'node:os'
|
|
9
|
+
import { join, resolve } from 'node:path'
|
|
10
|
+
import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
11
|
+
import { it } from 'vitest'
|
|
12
|
+
import { createDshEngineDefinition, createWebEngineDefinition } from '../src/engine-dsh.ts'
|
|
13
|
+
import { createAcrylEngineHost } from '../src/engine-host.ts'
|
|
14
|
+
import { measurePromptBudget, renderBudgetDoc, type PromptBudget } from '../src/prompt-budget.ts'
|
|
15
|
+
import { captureSystemPrompt, renderSystemPromptDoc } from '../src/system-prompt-capture.ts'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
|
|
18
|
+
const outDir = process.env.ACRYL_DUMP_SYSTEM_PROMPT
|
|
19
|
+
const repoRoot = resolve(fileURLToPath(new URL('../../..', import.meta.url)))
|
|
20
|
+
|
|
21
|
+
async function surface(kind: 'web' | 'cli'): Promise<{ doc: string; budget: PromptBudget }> {
|
|
22
|
+
const previous = { key: process.env.DEEPSEEK_API_KEY, home: process.env.DSH_HOME }
|
|
23
|
+
process.env.DEEPSEEK_API_KEY = 'dummy-key-for-prompt-capture'
|
|
24
|
+
const home = mkdtempSync(join(tmpdir(), 'acryl-prompt-'))
|
|
25
|
+
process.env.DSH_HOME = home
|
|
26
|
+
const host = await createAcrylEngineHost(kind === 'cli'
|
|
27
|
+
? { engines: [createDshEngineDefinition('acryl-prompt')], initialEngine: 'dsh' }
|
|
28
|
+
: {
|
|
29
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href)],
|
|
30
|
+
initialEngine: 'dsh',
|
|
31
|
+
prepare: ctx => { provideCmdline(ctx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
32
|
+
})
|
|
33
|
+
try {
|
|
34
|
+
const captured = await captureSystemPrompt(host.ctx, {
|
|
35
|
+
profile: kind === 'cli' ? 'acryl-prompt' : 'web',
|
|
36
|
+
selectStandardPreset: kind === 'web',
|
|
37
|
+
scrub: [[home, '<dsh-home>'], [repoRoot, '<acryl-repo>']],
|
|
38
|
+
})
|
|
39
|
+
return {
|
|
40
|
+
// The Web engine listens on a free port, different on every run; the copy names it <port> so it changes only when the prompt does.
|
|
41
|
+
doc: renderSystemPromptDoc(kind === 'web' ? 'web' : 'cli', kind === 'web' ? 'standard preset' : 'terminal engine', captured).replace(/(http:\/\/127\.0\.0\.1:)\d+/gu, '$1<port>'),
|
|
42
|
+
budget: measurePromptBudget(captured),
|
|
43
|
+
}
|
|
44
|
+
} finally {
|
|
45
|
+
await host.dispose()
|
|
46
|
+
rmSync(home, { recursive: true, force: true })
|
|
47
|
+
for (const [name, value] of [['DEEPSEEK_API_KEY', previous.key], ['DSH_HOME', previous.home]] as const) {
|
|
48
|
+
if (value === undefined) delete process.env[name]
|
|
49
|
+
else process.env[name] = value
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
it.skipIf(outDir === undefined)('dumps the current system prompt for web and cli', async () => {
|
|
55
|
+
const dir = resolve(repoRoot, outDir ?? '')
|
|
56
|
+
mkdirSync(dir, { recursive: true })
|
|
57
|
+
const budgets: Record<string, PromptBudget> = {}
|
|
58
|
+
for (const kind of ['web', 'cli'] as const) {
|
|
59
|
+
const { doc, budget } = await surface(kind)
|
|
60
|
+
writeFileSync(join(dir, `${kind}.md`), doc)
|
|
61
|
+
budgets[kind === 'web' ? 'web and desktop (standard preset)' : 'cli (terminal engine)'] = budget
|
|
62
|
+
}
|
|
63
|
+
// One table for every surface: per section and per tool, reproducible with this same command.
|
|
64
|
+
writeFileSync(join(dir, '..', 'budget.md'), renderBudgetDoc(budgets))
|
|
65
|
+
}, 240_000)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OPT-IN real-model end-to-end run of the self-extension loop (spec 037). Skipped unless
|
|
3
|
+
* `ACRYL_E2E_PROMPTS` is set: it spends real tokens.
|
|
4
|
+
*
|
|
5
|
+
* ACRYL_E2E_PROMPTS='build a kanban ...||change it ...||remove it' \
|
|
6
|
+
* ACRYL_E2E_LOG=/tmp/e2e.jsonl ACRYL_E2E_KEY_FILE=~/.secure-storage/llmproviders/deepseek/deepseek.json \
|
|
7
|
+
* corepack pnpm exec vitest run tests/e2e-real-model.spec.ts
|
|
8
|
+
*
|
|
9
|
+
* Boots the real web engine (or the CLI/terminal engine with ACRYL_E2E_ENGINE=tui) in a throwaway DSH_HOME. On web it opens
|
|
10
|
+
* one session on the `standard` preset (the composition the Web UI gives a session), sends each prompt in turn and appends every session event to the
|
|
11
|
+
* log file. The key is read from the file into the process environment and never logged.
|
|
12
|
+
*/
|
|
13
|
+
// keeps-temporary-directories: an opt-in real-model run; its homes, workspaces and logs are the evidence to read afterwards.
|
|
14
|
+
import { existsSync, mkdtempSync, readFileSync, readdirSync, appendFileSync } from 'node:fs'
|
|
15
|
+
import { homedir, tmpdir } from 'node:os'
|
|
16
|
+
import { join } from 'node:path'
|
|
17
|
+
import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
18
|
+
import { SessionId } from '@deepseek-ai/dsh-session'
|
|
19
|
+
import { it } from 'vitest'
|
|
20
|
+
import { createDshEngineDefinition, createWebEngineDefinition } from '../src/engine-dsh.ts'
|
|
21
|
+
import { createAcrylEngineHost } from '../src/engine-host.ts'
|
|
22
|
+
import { createAcrylSessionBridge } from '../src/session-bridge.ts'
|
|
23
|
+
|
|
24
|
+
const prompts = process.env.ACRYL_E2E_PROMPTS
|
|
25
|
+
|
|
26
|
+
it.skipIf(prompts === undefined)('the agent builds, changes, extends and removes extensions for real', async () => {
|
|
27
|
+
const keyFile = (process.env.ACRYL_E2E_KEY_FILE ?? '').replace(/^~/u, homedir())
|
|
28
|
+
process.env.DEEPSEEK_API_KEY = (JSON.parse(readFileSync(keyFile, 'utf8')) as { deepseek_api_key: string }).deepseek_api_key
|
|
29
|
+
process.env.DSH_HOME = mkdtempSync(join(tmpdir(), 'acryl-e2e-'))
|
|
30
|
+
const workspace = mkdtempSync(join(tmpdir(), 'acryl-e2e-ws-'))
|
|
31
|
+
const logFile = process.env.ACRYL_E2E_LOG ?? join(workspace, 'e2e.jsonl')
|
|
32
|
+
const log = (entry: unknown): void => appendFileSync(logFile, `${JSON.stringify(entry)}\n`)
|
|
33
|
+
log({ workspace })
|
|
34
|
+
|
|
35
|
+
const tui = process.env.ACRYL_E2E_ENGINE === 'tui'
|
|
36
|
+
const host = await createAcrylEngineHost(tui
|
|
37
|
+
? { engines: [createDshEngineDefinition('acryl-e2e')], initialEngine: 'dsh' }
|
|
38
|
+
: {
|
|
39
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href)],
|
|
40
|
+
initialEngine: 'dsh',
|
|
41
|
+
prepare: ctx => { provideCmdline(ctx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
42
|
+
})
|
|
43
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: tui ? 'acryl-e2e' : 'web', generationId: 'e2e', attachment: 'owner', cwd: workspace })
|
|
44
|
+
try {
|
|
45
|
+
const sessionId = await bridge.open()
|
|
46
|
+
await bridge.selectModel({ sessionId, provider: 'deepseek-official', model: 'deepseek-v4-flash' })
|
|
47
|
+
if (!tui) {
|
|
48
|
+
const presets = host.ctx.get('agentPresets' as never) as { select(agent: unknown, id: string): Promise<string> }
|
|
49
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
50
|
+
await presets.select(agent, 'standard')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let turnEnded: (() => void) | undefined
|
|
54
|
+
await bridge.subscribeEvents(sessionId, event => {
|
|
55
|
+
const { type, data } = event as { type: string; data?: unknown }
|
|
56
|
+
log({ ev: type, brief: JSON.stringify(data ?? {}).slice(0, 400) })
|
|
57
|
+
if (type === 'turn/end') turnEnded?.()
|
|
58
|
+
})
|
|
59
|
+
for (const prompt of (prompts ?? '').split('||')) {
|
|
60
|
+
log({ prompt })
|
|
61
|
+
const ended = new Promise<void>(resolve => { turnEnded = resolve })
|
|
62
|
+
await bridge.submitPrompt({ sessionId, text: prompt })
|
|
63
|
+
await Promise.race([ended, new Promise(resolve => setTimeout(resolve, 420_000))])
|
|
64
|
+
}
|
|
65
|
+
const extensions = join(workspace, '.acryl-plugins')
|
|
66
|
+
log({ done: true, extensions: existsSync(extensions) ? readdirSync(extensions) : [] })
|
|
67
|
+
} finally {
|
|
68
|
+
await bridge.dispose()
|
|
69
|
+
await host.dispose()
|
|
70
|
+
}
|
|
71
|
+
}, 1_800_000)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OPT-IN real-model end-to-end run of "the app survives a restart" (spec 001, T059). Skipped unless `ACRYL_E2E_RESTART_PROMPTS` is set: it spends real tokens.
|
|
3
|
+
*
|
|
4
|
+
* One pinned app home is booted once per prompt, with a full stop in between, and every turn must end `completed` (no error, no interrupted tool call). It
|
|
5
|
+
* exists because the first live restart of an app with an agent-authored extension found what every single-boot test had missed: an extension that listed
|
|
6
|
+
* the framework under `dependencies` brought a second copy into the profile, and every tool call failed after the restart.
|
|
7
|
+
*
|
|
8
|
+
* ACRYL_HOME=/some/throwaway/app-folder ACRYL_REQUIRE_ISOLATED_HOME=1 HOME=/some/throwaway/home \
|
|
9
|
+
* ACRYL_E2E_KEY_FILE=~/.secure-storage/llmproviders/deepseek/deepseek.json \
|
|
10
|
+
* ACRYL_E2E_RESTART_PROMPTS='build a tool plugin ... in the extensions folder, install it||call hello_acryl and report what it returned' \
|
|
11
|
+
* ACRYL_E2E_RESTART_EXPECT='hello after restart' ACRYL_E2E_LOG=/tmp/restart.jsonl corepack pnpm exec vitest run tests/e2e-restart-real-model.spec.ts
|
|
12
|
+
*
|
|
13
|
+
* `ACRYL_E2E_RESTART_EXPECT` is text the LAST turn's tool results must contain: a model that completes without doing the work cannot pass.
|
|
14
|
+
* Each session runs on the `standard` preset, the composition the Web UI gives a session (file and shell tools included).
|
|
15
|
+
*
|
|
16
|
+
* The caller pins the home (`scripts/live-run.mjs` shows the isolated environment to use); the key is read from the file into the process environment and
|
|
17
|
+
* never logged.
|
|
18
|
+
*/
|
|
19
|
+
// keeps-temporary-directories: an opt-in real-model run; its homes, workspaces and logs are the evidence to read afterwards.
|
|
20
|
+
import { appendFileSync, mkdtempSync, readFileSync } from 'node:fs'
|
|
21
|
+
import { homedir, tmpdir } from 'node:os'
|
|
22
|
+
import { join } from 'node:path'
|
|
23
|
+
import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
24
|
+
import { SessionId } from '@deepseek-ai/dsh-session'
|
|
25
|
+
import { expect, it } from 'vitest'
|
|
26
|
+
import { createWebEngineDefinition } from '../src/engine-dsh.ts'
|
|
27
|
+
import { createAcrylEngineHost } from '../src/engine-host.ts'
|
|
28
|
+
import { createAcrylSessionBridge } from '../src/session-bridge.ts'
|
|
29
|
+
|
|
30
|
+
const prompts = process.env.ACRYL_E2E_RESTART_PROMPTS
|
|
31
|
+
|
|
32
|
+
it.skipIf(prompts === undefined)('every turn completes across restarts of one app home', async () => {
|
|
33
|
+
expect(process.env.ACRYL_HOME, 'pin ACRYL_HOME to a throwaway app folder').toBeTruthy()
|
|
34
|
+
const keyFile = (process.env.ACRYL_E2E_KEY_FILE ?? '').replace(/^~/u, homedir())
|
|
35
|
+
process.env.DEEPSEEK_API_KEY = (JSON.parse(readFileSync(keyFile, 'utf8')) as { deepseek_api_key: string }).deepseek_api_key
|
|
36
|
+
const logFile = process.env.ACRYL_E2E_LOG ?? join(mkdtempSync(join(tmpdir(), 'acryl-e2e-restart-')), 'restart.jsonl')
|
|
37
|
+
const log = (entry: unknown): void => appendFileSync(logFile, `${JSON.stringify(entry)}\n`)
|
|
38
|
+
const endings: Array<{ prompt: string, reason: unknown }> = []
|
|
39
|
+
let lastResults = ''
|
|
40
|
+
|
|
41
|
+
for (const prompt of (prompts ?? '').split('||')) {
|
|
42
|
+
const workspace = mkdtempSync(join(tmpdir(), 'acryl-e2e-restart-ws-'))
|
|
43
|
+
const host = await createAcrylEngineHost({
|
|
44
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href)],
|
|
45
|
+
initialEngine: 'dsh',
|
|
46
|
+
prepare: ctx => { provideCmdline(ctx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
47
|
+
})
|
|
48
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'e2e-restart', attachment: 'owner', cwd: workspace })
|
|
49
|
+
try {
|
|
50
|
+
const sessionId = await bridge.open()
|
|
51
|
+
await bridge.selectModel({ sessionId, provider: 'deepseek-official', model: 'deepseek-v4-flash' })
|
|
52
|
+
const presets = host.ctx.get('agentPresets' as never) as { select(agent: unknown, id: string): Promise<string> }
|
|
53
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
54
|
+
await presets.select(agent, 'standard')
|
|
55
|
+
lastResults = ''
|
|
56
|
+
let ended: (() => void) | undefined
|
|
57
|
+
let reason: unknown
|
|
58
|
+
await bridge.subscribeEvents(sessionId, event => {
|
|
59
|
+
const { type, data } = event as { type: string, data?: { reason?: unknown } }
|
|
60
|
+
log({ ev: type, brief: JSON.stringify(data ?? {}).slice(0, 400) })
|
|
61
|
+
if (type === 'tool/result') lastResults += JSON.stringify(data)
|
|
62
|
+
if (type === 'turn/end') { reason = data?.reason; ended?.() }
|
|
63
|
+
})
|
|
64
|
+
log({ prompt })
|
|
65
|
+
const done = new Promise<void>(resolve => { ended = resolve })
|
|
66
|
+
await bridge.submitPrompt({ sessionId, text: prompt })
|
|
67
|
+
await Promise.race([done, new Promise(resolve => setTimeout(resolve, 420_000))])
|
|
68
|
+
endings.push({ prompt, reason })
|
|
69
|
+
} finally {
|
|
70
|
+
await bridge.dispose()
|
|
71
|
+
await host.dispose()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
expect(endings.map(ending => ending.reason)).toEqual(endings.map(() => ({ kind: 'completed' })))
|
|
75
|
+
const expected = process.env.ACRYL_E2E_RESTART_EXPECT
|
|
76
|
+
if (expected !== undefined) expect(lastResults).toContain(expected)
|
|
77
|
+
}, 1_800_000)
|