@acryldev/harness-runtime 0.0.0-stage → 0.2.11

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 (167) hide show
  1. package/LICENSE +49 -0
  2. package/lib/index.mjs +5693 -0
  3. package/lib/index.mjs.map +1 -0
  4. package/lib/types/acryl-home.d.ts +81 -0
  5. package/lib/types/app/new-app.d.ts +65 -0
  6. package/lib/types/app/start-source.d.ts +47 -0
  7. package/lib/types/blueprint/blueprint.d.ts +74 -0
  8. package/lib/types/blueprint/brand-identity.d.ts +26 -0
  9. package/lib/types/blueprint/compose.d.ts +53 -0
  10. package/lib/types/blueprint/definition.d.ts +22 -0
  11. package/lib/types/blueprint/index.d.ts +7 -0
  12. package/lib/types/blueprint/manifest.d.ts +35 -0
  13. package/lib/types/blueprint/selection.d.ts +19 -0
  14. package/lib/types/cli-market-install.d.ts +97 -0
  15. package/lib/types/cli-market-plugins.d.ts +81 -0
  16. package/lib/types/coding-capabilities.d.ts +29 -0
  17. package/lib/types/durable-message.d.ts +18 -0
  18. package/lib/types/engine-dsh.d.ts +181 -0
  19. package/lib/types/engine-files.d.ts +8 -0
  20. package/lib/types/engine-host.d.ts +32 -0
  21. package/lib/types/engine-tools.d.ts +11 -0
  22. package/lib/types/index.d.ts +67 -0
  23. package/lib/types/instance/announce-self.d.ts +38 -0
  24. package/lib/types/instance/app-instance.d.ts +125 -0
  25. package/lib/types/instance/index.d.ts +6 -0
  26. package/lib/types/instance/offline-lock.d.ts +29 -0
  27. package/lib/types/instance/online-secret.d.ts +29 -0
  28. package/lib/types/instance/registry.d.ts +26 -0
  29. package/lib/types/instance/select.d.ts +43 -0
  30. package/lib/types/module-hooks.d.ts +19 -0
  31. package/lib/types/module-resolution.d.ts +31 -0
  32. package/lib/types/package-overlay.d.ts +41 -0
  33. package/lib/types/pinned-pnpm.d.ts +15 -0
  34. package/lib/types/plugin-acryl-workspace-status.d.ts +24 -0
  35. package/lib/types/plugin-doctor.d.ts +49 -0
  36. package/lib/types/plugin-lifecycle-state.d.ts +92 -0
  37. package/lib/types/plugin-lifecycle.d.ts +87 -0
  38. package/lib/types/profile-layout.d.ts +17 -0
  39. package/lib/types/profile-owner.d.ts +25 -0
  40. package/lib/types/profile-repair/backup.d.ts +37 -0
  41. package/lib/types/profile-repair/findings.d.ts +29 -0
  42. package/lib/types/profile-repair/index.d.ts +9 -0
  43. package/lib/types/profile-repair/inspector.d.ts +11 -0
  44. package/lib/types/profile-repair/repair.d.ts +38 -0
  45. package/lib/types/profile-resolution/moved-framework.d.ts +21 -0
  46. package/lib/types/profile-resolution/resolver.d.ts +41 -0
  47. package/lib/types/profile-resolution/service.d.ts +22 -0
  48. package/lib/types/prompt-budget.d.ts +44 -0
  49. package/lib/types/session-bridge.d.ts +57 -0
  50. package/lib/types/session-log-exporter.d.ts +31 -0
  51. package/lib/types/system-prompt-capture.d.ts +29 -0
  52. package/lib/types/web-favicon-data.d.ts +5 -0
  53. package/lib/types/web-favicon.d.ts +23 -0
  54. package/lib/types/web-market-install.d.ts +114 -0
  55. package/lib/types/web-market-plugins.d.ts +106 -0
  56. package/lib/types/web-port.d.ts +15 -0
  57. package/package.json +211 -3
  58. package/src/acryl-home.ts +103 -0
  59. package/src/app/new-app.ts +239 -0
  60. package/src/app/start-source.ts +110 -0
  61. package/src/blueprint/blueprint.ts +141 -0
  62. package/src/blueprint/brand-identity.ts +75 -0
  63. package/src/blueprint/compose.ts +222 -0
  64. package/src/blueprint/definition.ts +92 -0
  65. package/src/blueprint/index.ts +20 -0
  66. package/src/blueprint/manifest.ts +145 -0
  67. package/src/blueprint/selection.ts +74 -0
  68. package/src/cli-market-install.ts +181 -0
  69. package/src/cli-market-plugins.ts +176 -0
  70. package/src/coding-capabilities.ts +61 -0
  71. package/src/durable-message.ts +23 -0
  72. package/src/engine-dsh.ts +856 -0
  73. package/src/engine-files.ts +9 -0
  74. package/src/engine-host.ts +128 -0
  75. package/src/engine-tools.ts +26 -0
  76. package/src/index.ts +436 -0
  77. package/src/instance/announce-self.ts +88 -0
  78. package/src/instance/app-instance.ts +240 -0
  79. package/src/instance/index.ts +45 -0
  80. package/src/instance/offline-lock.ts +71 -0
  81. package/src/instance/online-secret.ts +55 -0
  82. package/src/instance/registry.ts +53 -0
  83. package/src/instance/select.ts +134 -0
  84. package/src/module-hooks.ts +41 -0
  85. package/src/module-resolution.ts +187 -0
  86. package/src/package-overlay.ts +160 -0
  87. package/src/pinned-pnpm.ts +67 -0
  88. package/src/plugin-acryl-workspace-status.ts +99 -0
  89. package/src/plugin-doctor.ts +141 -0
  90. package/src/plugin-lifecycle-state.ts +347 -0
  91. package/src/plugin-lifecycle.ts +223 -0
  92. package/src/profile-layout.ts +97 -0
  93. package/src/profile-owner.ts +52 -0
  94. package/src/profile-repair/backup.ts +119 -0
  95. package/src/profile-repair/findings.ts +43 -0
  96. package/src/profile-repair/index.ts +10 -0
  97. package/src/profile-repair/inspector.ts +156 -0
  98. package/src/profile-repair/repair.ts +137 -0
  99. package/src/profile-resolution/moved-framework.ts +64 -0
  100. package/src/profile-resolution/resolver.ts +876 -0
  101. package/src/profile-resolution/service.ts +99 -0
  102. package/src/prompt-budget.ts +118 -0
  103. package/src/session-bridge.ts +350 -0
  104. package/src/session-log-exporter.ts +68 -0
  105. package/src/system-prompt-capture.ts +99 -0
  106. package/src/web-favicon-data.ts +6 -0
  107. package/src/web-favicon.ts +43 -0
  108. package/src/web-market-install.ts +206 -0
  109. package/src/web-market-plugins.ts +215 -0
  110. package/src/web-port.ts +39 -0
  111. package/tests/account-callback.spec.ts +173 -0
  112. package/tests/acryl-home.spec.ts +39 -0
  113. package/tests/agent-self-hosting.spec.ts +101 -0
  114. package/tests/announce-self.spec.ts +84 -0
  115. package/tests/app-lifecycle.spec.ts +99 -0
  116. package/tests/blank-blueprint.spec.ts +110 -0
  117. package/tests/blueprint-definition.spec.ts +128 -0
  118. package/tests/blueprint.spec.ts +138 -0
  119. package/tests/bulkhead.spec.ts +187 -0
  120. package/tests/coding-vocabulary.spec.ts +15 -0
  121. package/tests/dump-system-prompt.spec.ts +65 -0
  122. package/tests/e2e-real-model.spec.ts +71 -0
  123. package/tests/e2e-restart-real-model.spec.ts +77 -0
  124. package/tests/engine-dsh.spec.ts +340 -0
  125. package/tests/engine-host-mount-root-include.spec.ts +118 -0
  126. package/tests/engine-host.spec.ts +176 -0
  127. package/tests/engine-optional.spec.ts +81 -0
  128. package/tests/extension-examples.spec.ts +261 -0
  129. package/tests/hooks-thread-stack.ts +27 -0
  130. package/tests/instance-patches.spec.ts +25 -0
  131. package/tests/instance.spec.ts +235 -0
  132. package/tests/live/community-plugins.spec.ts +83 -0
  133. package/tests/module-hooks.spec.ts +35 -0
  134. package/tests/module-resolution.spec.ts +265 -0
  135. package/tests/moved-framework.spec.ts +61 -0
  136. package/tests/new-app.spec.ts +132 -0
  137. package/tests/organizer-growth.spec.ts +117 -0
  138. package/tests/pinned-pnpm.spec.ts +34 -0
  139. package/tests/plugin-acryl-workspace-status.spec.ts +63 -0
  140. package/tests/plugin-context.spec.ts +640 -0
  141. package/tests/plugin-doctor.spec.ts +183 -0
  142. package/tests/plugin-enablement-one-store.spec.ts +130 -0
  143. package/tests/plugin-lifecycle-state.spec.ts +169 -0
  144. package/tests/profile-layout.spec.ts +58 -0
  145. package/tests/profile-owner.spec.ts +38 -0
  146. package/tests/profile-repair/profile-repair.spec.ts +231 -0
  147. package/tests/profile-resolution-port.spec.ts +30 -0
  148. package/tests/profile-resolution-service.spec.ts +273 -0
  149. package/tests/profile-resolution-swap.spec.ts +69 -0
  150. package/tests/profile-resolution.spec.ts +2535 -0
  151. package/tests/profile.spec.ts +70 -0
  152. package/tests/project-registry.spec.ts +81 -0
  153. package/tests/prompt-budget.spec.ts +58 -0
  154. package/tests/real-home-guard.spec.ts +178 -0
  155. package/tests/session-bridge.spec.ts +316 -0
  156. package/tests/start-source.spec.ts +65 -0
  157. package/tests/system-prompt-shape.spec.ts +95 -0
  158. package/tests/three-levels.spec.ts +84 -0
  159. package/tests/tool-gateway.spec.ts +116 -0
  160. package/tests/tool-schemas.spec.ts +41 -0
  161. package/tests/web-favicon.spec.ts +42 -0
  162. package/tests/web-port.spec.ts +38 -0
  163. package/tests/web-startup-hold.spec.ts +79 -0
  164. package/tsconfig.json +24 -0
  165. package/tsdown.config.ts +2 -0
  166. package/vitest.config.ts +18 -0
  167. package/README.md +0 -3
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The app lifecycle on real engines (spec 036): an app IS its Blend. Create an app with a plugin in its plugins/, start it (the plugin installs itself),
3
+ * record it with /blend snapshot (into the app folder), create a second app from it (like a fresh clone of the app's git repository), and start that one:
4
+ * its plugins install themselves too, from the app's own files, with the lock verified.
5
+ */
6
+ import { spawnSync } from 'node:child_process'
7
+ import { cpSync, existsSync, readFileSync, realpathSync } from 'node:fs'
8
+ import { mkdtemp, rm } from 'node:fs/promises'
9
+ import { tmpdir } from 'node:os'
10
+ import { join } from 'node:path'
11
+ import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
12
+ import { SessionId } from '@deepseek-ai/dsh-session'
13
+ import { afterEach, describe, expect, it } from 'vitest'
14
+ import { planNewApp, writeNewApp } from '../src/app/new-app.ts'
15
+ import { createWebEngineDefinition } from '../src/engine-dsh.ts'
16
+ import { createAcrylEngineHost } from '../src/engine-host.ts'
17
+ import { createAcrylSessionBridge } from '../src/session-bridge.ts'
18
+ import { fileURLToPath } from 'node:url'
19
+ import { codingCapabilities } from '@acryldev/coding-capabilities'
20
+
21
+ const organizer = fileURLToPath(new URL('../../../examples/acryl-organizer/', import.meta.url))
22
+ const saved = { ...process.env }
23
+ const temporary: string[] = []
24
+ afterEach(async () => {
25
+ for (const key of Object.keys(process.env)) if (!(key in saved)) delete process.env[key]
26
+ Object.assign(process.env, saved)
27
+ await Promise.all(temporary.splice(0).map(path => rm(path, { force: true, recursive: true })))
28
+ })
29
+
30
+ async function start(app: string) {
31
+ 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]
32
+ process.env.ACRYL_HOME = app
33
+ const host = await createAcrylEngineHost({
34
+ engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
35
+ initialEngine: 'dsh',
36
+ prepare: ctx => { provideCmdline(ctx, { args: ['--no-open'], exit: () => {} }) },
37
+ })
38
+ const tools = async () => (await host.ctx.get('systemPrompt')!.assemble()).tools.map(tool => tool.name)
39
+ // The startup pass runs one tick after boot and installs the app's own plugins: wait for its signal, the one Desktop waits on, and keep what
40
+ // it reports, so a missing plugin fails with the reason (a failed install) instead of a tool list.
41
+ const pluginContext = host.ctx.get('pluginContext' as never) as unknown as { startupSettled: Promise<{ status: string, lines: string[] }> }
42
+ const startup = await pluginContext.startupSettled
43
+ const report = `startup pass ${startup.status}: ${startup.lines.join('; ') || '(nothing reported)'}`
44
+ const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: `app-${String(Date.now())}`, attachment: 'owner', cwd: app })
45
+ const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(await bridge.open()))
46
+ const commands = host.ctx.get('commands' as never) as unknown as {
47
+ execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { kind: string, text?: string } } | undefined>
48
+ }
49
+ return {
50
+ tools,
51
+ report,
52
+ run: async (line: string) => (await commands.execute(agent, line, [], new AbortController().signal))?.result,
53
+ async stop() { await bridge.dispose(); await host.dispose() },
54
+ }
55
+ }
56
+
57
+ describe('an app is its Blend', () => {
58
+ it('installs its own plugins at start, records into its own folder, and a second app created from it starts with the same plugins', async () => {
59
+ const root = realpathSync(await mkdtemp(join(tmpdir(), 'acryl-app-lifecycle-')))
60
+ temporary.push(root)
61
+ const launcher = '/framework/scripts/blank.mjs'
62
+
63
+ // App A: created by `acryl new`, with a plugin committed in its plugins/ (what the builder inside would have written).
64
+ const a = join(root, 'planner')
65
+ writeNewApp(planNewApp(a, { title: 'Planner', launcher }), { git: false })
66
+ cpSync(organizer, join(a, 'plugins', 'acryl-organizer'), { recursive: true, filter: source => !source.includes('/tests') })
67
+ let app = await start(a)
68
+ try {
69
+ expect(app.report).toBe("startup pass done: installed the app's plugins acryl-organizer")
70
+ expect(await app.tools(), app.report).toContain('todo_add') // installed by the startup pass, nobody typed /reload
71
+ const snapshot = await app.run('/blend snapshot')
72
+ expect(snapshot?.kind, String(snapshot?.text)).toBe('success')
73
+ expect(snapshot?.text).toContain(`Recorded the app in ${a}`)
74
+ expect(readFileSync(join(a, 'blend.yaml'), 'utf8')).toMatch(/name: acryl-organizer/u)
75
+ expect(readFileSync(join(a, 'blend.yaml'), 'utf8')).toMatch(/^# Planner: what this app is/u) // the user's definition is kept
76
+ expect(JSON.parse(readFileSync(join(a, 'blend.lock.json'), 'utf8')).modules).toEqual([expect.objectContaining({ name: 'acryl-organizer', origin: 'local', source: 'plugins/acryl-organizer' })])
77
+ expect((await app.run('/blend verify'))?.text).toContain('matches its lock')
78
+ expect(existsSync(join(a, '.acryl'))).toBe(false) // nothing written into a hidden side folder: the app folder is the Blend
79
+ // Saved from its own chat into its own repository: the app's files, never its runtime data.
80
+ Object.assign(process.env, { GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@t' })
81
+ const saved = await app.run('/app save the planner with its organizer')
82
+ expect(saved?.kind, String(saved?.text)).toBe('success')
83
+ expect(saved?.text).toMatch(/Saved [0-9a-f]{8}\. It has no remote yet/u)
84
+ const tracked = spawnSync('git', ['ls-files'], { cwd: a, encoding: 'utf8' }).stdout.split('\n')
85
+ expect(tracked).toContain('blend.lock.json')
86
+ expect(tracked.some(file => file.startsWith('.dsh/'))).toBe(false)
87
+ } finally { await app.stop() }
88
+
89
+ // App B: created from A (what a fresh clone of A's repository amounts to: definition, lock and plugins, nothing installed).
90
+ const b = join(root, 'planner-eu')
91
+ const source = { manifestText: readFileSync(join(a, 'blend.yaml'), 'utf8'), lockText: readFileSync(join(a, 'blend.lock.json'), 'utf8') }
92
+ writeNewApp(planNewApp(b, { title: 'Planner EU', launcher, from: source }), { git: false, pluginsFrom: join(a, 'plugins') })
93
+ app = await start(b)
94
+ try {
95
+ expect(await app.tools(), app.report).toContain('meeting_book')
96
+ expect((await app.run('/blend verify'))?.text).toContain('matches its lock')
97
+ } finally { await app.stop() }
98
+ }, 300_000)
99
+ })
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Real-engine proof of the Blank Blueprint (spec 036): a Web app and a CLI app booted with ACRYL_BLUEPRINT=acryl.blank carry
3
+ * the stem-cell rows and none of the full product's, wear the configured brand, and can still grow themselves.
4
+ */
5
+ import { mkdtemp, rm } from 'node:fs/promises'
6
+ import { tmpdir } from 'node:os'
7
+ import { join } from 'node:path'
8
+ import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
9
+ import { afterEach, describe, expect, it } from 'vitest'
10
+ import { createDshEngineDefinition, createWebEngineDefinition } from '../src/engine-dsh.ts'
11
+ import { createAcrylEngineHost } from '../src/engine-host.ts'
12
+ import { codingCapabilities } from '@acryldev/coding-capabilities'
13
+
14
+ const STATES = ['PENDING', 'LOADING', 'ACTIVE', 'FAILED', 'UNLOADING', 'DISPOSED']
15
+ const homes: string[] = []
16
+ const saved = { home: process.env.DSH_HOME, blueprint: process.env.ACRYL_BLUEPRINT, name: process.env.ACRYL_BRAND_NAME, accent: process.env.ACRYL_BRAND_ACCENT }
17
+
18
+ function restore(key: keyof typeof saved, variable: string): void {
19
+ if (saved[key] === undefined) delete process.env[variable]
20
+ else process.env[variable] = saved[key]
21
+ }
22
+
23
+ afterEach(async () => {
24
+ restore('home', 'DSH_HOME'); restore('blueprint', 'ACRYL_BLUEPRINT'); restore('name', 'ACRYL_BRAND_NAME'); restore('accent', 'ACRYL_BRAND_ACCENT')
25
+ await Promise.all(homes.splice(0).map(home => rm(home, { force: true, recursive: true })))
26
+ })
27
+
28
+ async function freshHome(label: string): Promise<void> {
29
+ const home = await mkdtemp(join(tmpdir(), `acryl-blank-${label}-`))
30
+ homes.push(home)
31
+ process.env.DSH_HOME = home
32
+ }
33
+
34
+ function rowIds(host: { ctx: { loader: { entries(): Iterable<{ options: { id?: string } }> } } }): string[] {
35
+ return [...host.ctx.loader.entries()].map(entry => entry.options.id ?? '')
36
+ }
37
+
38
+ describe('blank blueprint on the Web engine', () => {
39
+ it('composes the stem cell, wears the brand, and keeps the growth path open', async () => {
40
+ await freshHome('web')
41
+ process.env.ACRYL_BLUEPRINT = 'acryl.blank'
42
+ process.env.ACRYL_BRAND_NAME = 'Orbit'
43
+ process.env.ACRYL_BRAND_ACCENT = '#e8590c'
44
+ const host = await createAcrylEngineHost({
45
+ engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
46
+ initialEngine: 'dsh',
47
+ prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
48
+ })
49
+ try {
50
+ const ids = rowIds(host)
51
+ // The stem cell.
52
+ expect(ids).toEqual(expect.arrayContaining(['brand', 'acryl-plugin-context', 'acryl-system-prompt', '@acryl/ui', 'authorization']))
53
+ // Nothing of the full product.
54
+ for (const absent of ['acryl-workspace', 'acryl-plugin-admin', 'community-market', 'acryl-shortcuts', 'acryl-mount-anchors', 'ui-acryl']) {
55
+ expect(ids, absent).not.toContain(absent)
56
+ }
57
+ // The stock brand is swapped out, not deleted (reversible): the row still exists and is disabled.
58
+ const official = [...host.ctx.loader.entries()].find(entry => entry.options.id === 'ui-brand-official')
59
+ expect(official?.options.disabled).toBe(true)
60
+
61
+ const brand = host.ctx.get('acrylBrand' as never) as { identity: { name: string, accent: string } } | undefined
62
+ expect(brand?.identity).toMatchObject({ name: 'Orbit', accent: '#e8590c' })
63
+
64
+ const assembly = await host.ctx.get('systemPrompt')!.assemble()
65
+ expect(JSON.stringify(assembly.sections)).toContain('inside Orbit')
66
+ expect(assembly.tools.map(tool => tool.name)).toContain('acryl_install_plugin')
67
+
68
+ // The failed-row check: every row the blueprint composed reached ACTIVE.
69
+ const failed = [...host.ctx.loader.entries()].filter(entry => entry.fiber && STATES[entry.fiber.state as number] === 'FAILED').map(entry => entry.options.id)
70
+ expect(failed).toEqual([])
71
+ } finally {
72
+ await host.dispose()
73
+ }
74
+ }, 90_000)
75
+
76
+ it('a profile without a selected blueprint still composes the full product', async () => {
77
+ await freshHome('web-full')
78
+ delete process.env.ACRYL_BLUEPRINT
79
+ delete process.env.ACRYL_BRAND_NAME
80
+ delete process.env.ACRYL_BRAND_ACCENT
81
+ const host = await createAcrylEngineHost({
82
+ engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
83
+ initialEngine: 'dsh',
84
+ prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
85
+ })
86
+ try {
87
+ expect(rowIds(host)).toEqual(expect.arrayContaining(['ui-acryl', 'community-market', 'acryl-workspace', 'acryl-plugin-admin', 'acryl-shortcuts', 'acryl-mount-anchors']))
88
+ } finally {
89
+ await host.dispose()
90
+ }
91
+ }, 90_000)
92
+ })
93
+
94
+ describe('blank blueprint on the CLI engine', () => {
95
+ it('keeps the agent and the extension pack and nothing else of ACRYL\'s own rows', async () => {
96
+ await freshHome('tui')
97
+ process.env.ACRYL_BLUEPRINT = 'acryl.blank'
98
+ const host = await createAcrylEngineHost({ engines: [createDshEngineDefinition('acryl-blank-test', codingCapabilities)], initialEngine: 'dsh' })
99
+ try {
100
+ const ids = rowIds(host)
101
+ expect(ids).toEqual(expect.arrayContaining(['acryl-plugin-context', 'acryl-system-prompt', 'authorization', 'agent-preset-registry']))
102
+ expect(ids).not.toContain('brand')
103
+ const assembly = await host.ctx.get('systemPrompt')!.assemble()
104
+ expect(JSON.stringify(assembly.sections)).toContain('inside Blank')
105
+ expect(assembly.tools.map(tool => tool.name)).toContain('acryl_install_plugin')
106
+ } finally {
107
+ await host.dispose()
108
+ }
109
+ }, 90_000)
110
+ })
@@ -0,0 +1,128 @@
1
+ /** Blueprints defined by a file (spec 036): a team's own starter and brand, no code. Pure parsing plus the one file boundary. */
2
+ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+ import { afterEach, describe, expect, it } from 'vitest'
6
+ import {
7
+ BLANK_BLUEPRINT,
8
+ BLUEPRINT_ROW_IDS,
9
+ InvalidBlueprintError,
10
+ blueprintFromEnvironment,
11
+ builtInCatalog,
12
+ composeBlueprintRows,
13
+ parseBlueprint,
14
+ } from '../src/index.ts'
15
+ import { fileURLToPath } from 'node:url'
16
+ import { blueprintRowForModule } from '../src/blueprint/index.ts'
17
+ import { ACRYL_CODING_CAPABILITIES } from '../src/coding-capabilities.ts'
18
+ import { ADVANCED_SHELL_PATCHES } from '@acryldev/coding-capabilities'
19
+
20
+ const dirs: string[] = []
21
+ afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { force: true, recursive: true }) })
22
+
23
+ function file(name: string, body: string): string {
24
+ const dir = mkdtempSync(join(tmpdir(), 'acryl-blueprint-'))
25
+ dirs.push(dir)
26
+ const path = join(dir, name)
27
+ writeFileSync(path, body)
28
+ return path
29
+ }
30
+
31
+ describe('parseBlueprint', () => {
32
+ it('reads dshChat, inherits it from the parent, and refuses a non-boolean', () => {
33
+ expect(parseBlueprint({ id: 'acme.own-agents', extends: 'acryl.ide', dshChat: false }).dshChat).toBe(false)
34
+ expect(parseBlueprint({ id: 'acme.child', extends: 'acryl.agents' }).dshChat).toBe(false)
35
+ expect(parseBlueprint({ id: 'acme.plain' }).dshChat).toBe(true)
36
+ expect(() => parseBlueprint({ id: 'acme.bad', dshChat: 'no' })).toThrow(InvalidBlueprintError)
37
+ })
38
+
39
+ it('extends a known blueprint, overriding only what it names', () => {
40
+ const blueprint = parseBlueprint({ id: 'acme.notes', name: 'Acme Notes', extends: 'acryl.blank', brand: { name: 'Acme Notes', accent: '#0a7d4b' }, rows: ['extension-context', 'system-prompt', 'ui-library', 'community-market'] })
41
+ expect(blueprint.id).toBe('acme.notes')
42
+ expect(blueprint.capabilities).toEqual(BLANK_BLUEPRINT.capabilities)
43
+ expect(blueprint.rows).toContain('community-market')
44
+ // Written before spec 044 step 1b renamed the row: read as its current name.
45
+ expect(blueprint.rows).toContain('plugin-context')
46
+ expect(blueprint.rows).not.toContain('extension-context' as never)
47
+ expect(blueprint.brand).toEqual({ kind: 'custom', identity: expect.objectContaining({ name: 'Acme Notes', accent: '#0a7d4b' }) })
48
+ })
49
+
50
+ it('stands alone with safe defaults when it extends nothing', () => {
51
+ const blueprint = parseBlueprint({ id: 'tiny' })
52
+ expect(blueprint.capabilities).toEqual(['authorization', 'acryl-settings'])
53
+ expect(blueprint.shell).toBe('compatibility')
54
+ })
55
+
56
+ it('rejects what it cannot honor: typos, unknown rows and capabilities, a bad id, a missing parent', () => {
57
+ expect(() => parseBlueprint({ id: 'x', rowz: [] })).toThrow(/unknown key "rowz"/)
58
+ expect(() => parseBlueprint({ id: 'x', rows: ['market'] })).toThrow(/"market"/)
59
+ expect(() => parseBlueprint({ id: 'x', capabilities: ['teleport'] })).toThrow(InvalidBlueprintError)
60
+ expect(() => parseBlueprint({ id: 'Bad Id' })).toThrow(/"id" is required/)
61
+ expect(() => parseBlueprint({ id: 'x', extends: 'nope' })).toThrow(/not a known blueprint/)
62
+ expect(() => parseBlueprint({ id: 'x', shell: 'wide' })).toThrow(/"shell"/)
63
+ expect(() => parseBlueprint([])).toThrow(/expected an object/)
64
+ })
65
+
66
+ it('refuses a capability that needs the router without the framework kit that serves its routes, and every built-in with one has the kit', () => {
67
+ expect(() => parseBlueprint({ id: 'acme.ide', extends: 'acryl.ide', rows: ['plugin-context', 'system-prompt'] })).toThrow(/"framework-kit"/)
68
+ expect(() => parseBlueprint({ id: 'acme.ws', capabilities: ['workspace'] })).toThrow(/"workspace" capability needs the "framework-kit"/)
69
+ expect(() => parseBlueprint({ id: 'acme.door', capabilities: ['agent-control-ui'] })).toThrow(/"agent-control-ui" capability needs the "framework-kit"/)
70
+ expect(() => parseBlueprint({ id: 'acme.login', capabilities: ['sign-in'] })).toThrow(/"sign-in" capability needs the "framework-kit"/)
71
+ expect(parseBlueprint({ id: 'acme.ws', capabilities: ['workspace'], rows: ['framework-kit'] }).rows).toEqual(['framework-kit'])
72
+ expect(parseBlueprint({ id: 'acme.door', capabilities: ['agent-control-ui'], rows: ['framework-kit'] }).capabilities).toEqual(['agent-control-ui'])
73
+ const routed = ACRYL_CODING_CAPABILITIES.filter(capability => capability.needsRouter === true).map(capability => capability.id)
74
+ expect(routed).toEqual(['workspace', 'plugin-admin', 'sign-in', 'launcher-screen', 'support', 'agent-control-ui'])
75
+ for (const blueprint of builtInCatalog().list()) {
76
+ if (blueprint.capabilities.some(id => routed.includes(id))) expect(blueprint.rows).toContain('framework-kit')
77
+ }
78
+ })
79
+
80
+ it('every row id a file may name composes on at least one surface (the id list cannot drift from the row table)', () => {
81
+ for (const id of BLUEPRINT_ROW_IDS) {
82
+ const probe = parseBlueprint({ id: 'probe', rows: [id], capabilities: ['authorization'] })
83
+ const composed = (['tui', 'web', 'desktop'] as const).some(surface => composeBlueprintRows(probe, surface).packages.some(name => name !== '@acryldev/brand-client' && name !== '@acryldev/brand'))
84
+ expect(composed, id).toBe(true)
85
+ }
86
+ })
87
+
88
+ it('a Blend with the app-shell row owns its frame on Web and Desktop: the frame package and row, the stock layout off, sidebar and conversation on', () => {
89
+ const blueprint = parseBlueprint({ id: 'acme.music', extends: 'acryl.blank', rows: [...BLANK_BLUEPRINT.rows, 'app-shell'] })
90
+ for (const surface of ['web', 'desktop'] as const) {
91
+ const { packages, patches } = composeBlueprintRows(blueprint, surface, new Set(), ADVANCED_SHELL_PATCHES)
92
+ expect(packages).toContain('@acryldev/app-shell')
93
+ expect(patches.flatMap(patch => patch.insert ?? []).map(row => row.id)).toContain('acryl-app-shell')
94
+ expect(patches).toEqual(expect.arrayContaining([{ id: 'ui-layout', disabled: true }, { id: 'ui-sidebar', disabled: false }, { id: 'ui-conversation', disabled: false }]))
95
+ }
96
+ const tui = composeBlueprintRows(blueprint, 'tui')
97
+ expect(tui.packages).not.toContain('acryl-app-shell')
98
+ expect(tui.patches).not.toContainEqual({ id: 'ui-layout', disabled: true })
99
+ expect(blueprintRowForModule('@acryldev/app-shell')).toBe('app-shell')
100
+ })
101
+
102
+ it('a Blend without it keeps the stock frame', () => {
103
+ expect(composeBlueprintRows(BLANK_BLUEPRINT, 'web').patches).not.toContainEqual({ id: 'ui-layout', disabled: true })
104
+ })
105
+ })
106
+
107
+ describe('a blueprint file selected from the environment', () => {
108
+ it('the documented private-brand sample is valid', () => {
109
+ const sample = fileURLToPath(new URL('../../../specs/036-cordis-ecosystem-and-acryl-blends/samples/private-brand.blueprint.yaml', import.meta.url))
110
+ const blueprint = blueprintFromEnvironment({ ACRYL_BLUEPRINT: sample })
111
+ expect(blueprint.id).toBe('acme.notes')
112
+ expect(blueprint.rows).not.toContain('acryl-workspace' as never)
113
+ expect(composeBlueprintRows(blueprint, 'web').patches.flatMap(patch => patch.insert ?? []).map(row => row.id)).toEqual(['brand', 'acrylblends/cordis/router', 'acrylblends/cordis/router-http', 'acrylblends/cordis/state', 'acrylblends/cordis/inspect', 'acryl-plugin-context', 'acryl-system-prompt', '@acryl/ui', 'acryl-app-save', 'acryl-plugin-hub', 'acryl-command-reply', 'acryl-plugin-hub/manager'])
114
+ })
115
+
116
+ it('is read, validated and rebranded like a built-in', () => {
117
+ const path = file('acme.yaml', 'id: acme.notes\nextends: acryl.blank\nbrand:\n name: Acme Notes\n accent: "#0a7d4b"\n')
118
+ const blueprint = blueprintFromEnvironment({ ACRYL_BLUEPRINT: path, ACRYL_BRAND_TAGLINE: 'Notes that write themselves' })
119
+ expect(blueprint.id).toBe('acme.notes')
120
+ expect(blueprint.brand).toEqual({ kind: 'custom', identity: expect.objectContaining({ name: 'Acme Notes', tagline: 'Notes that write themselves' }) })
121
+ })
122
+
123
+ it('fails loudly on a missing file, bad YAML and an invalid definition instead of booting the wrong product', () => {
124
+ expect(() => blueprintFromEnvironment({ ACRYL_BLUEPRINT: join(tmpdir(), 'does-not-exist.yaml') })).toThrow(/cannot read/)
125
+ expect(() => blueprintFromEnvironment({ ACRYL_BLUEPRINT: file('bad.yaml', 'id: [unclosed') })).toThrow(/not valid YAML/)
126
+ expect(() => blueprintFromEnvironment({ ACRYL_BLUEPRINT: file('invalid.yml', 'id: x\nrows: [nope]\n') })).toThrow(/"nope"/)
127
+ })
128
+ })
@@ -0,0 +1,138 @@
1
+ /**
2
+ * The blueprint context (spec 036): pure domain rules, no engine. What a Blueprint composes per surface is the contract,
3
+ * so it is asserted as exact row ids, in mount order.
4
+ */
5
+ import { describe, expect, it } from 'vitest'
6
+ import {
7
+ ACRYL_CODING_CAPABILITIES,
8
+ AGENTS_BLUEPRINT,
9
+ BLANK_BLUEPRINT,
10
+ DSH_CHAT_ROW_IDS,
11
+ DSH_PLUGIN_MANAGER_ROW_ID,
12
+ IDE_BLUEPRINT,
13
+ PLUGIN_MANAGER_ROW_ID,
14
+ InvalidBrandIdentityError,
15
+ UnknownBlueprintError,
16
+ blueprintFromEnvironment,
17
+ brandIdentity,
18
+ composeBlueprintRows,
19
+ identityLine,
20
+ selectBlueprint,
21
+ } from '../src/index.ts'
22
+ import { createAcrylCodingCapabilityPatches, createAcrylShellCapabilityPatches } from '@acryldev/coding-capabilities'
23
+
24
+ function insertedIds(patches: readonly unknown[]): string[] {
25
+ return patches.flatMap(patch => ((patch as { insert?: { id?: string }[] }).insert ?? []).map(row => row.id ?? ''))
26
+ }
27
+
28
+ describe('brand identity', () => {
29
+ it('needs a name and rejects malformed colors, oversized text and non-objects', () => {
30
+ expect(brandIdentity({ name: ' Orbit ' }).name).toBe('Orbit')
31
+ expect(() => brandIdentity({})).toThrow(InvalidBrandIdentityError)
32
+ expect(() => brandIdentity({ name: 'X', accent: 'blue' })).toThrow(/#rrggbb/)
33
+ expect(() => brandIdentity({ name: 'x'.repeat(41) })).toThrow(/at most 40/)
34
+ expect(() => brandIdentity('Orbit')).toThrow(/expected an object/)
35
+ })
36
+
37
+ it('names the brand in the agent identity line', () => {
38
+ expect(identityLine(brandIdentity({ name: 'Orbit' }))).toContain('inside Orbit')
39
+ })
40
+ })
41
+
42
+ describe('blueprint selection', () => {
43
+ it('defaults to the full ACRYL, resolves built-ins, and fails loud on an unknown id', () => {
44
+ expect(selectBlueprint(undefined)).toBe(IDE_BLUEPRINT)
45
+ expect(selectBlueprint(' ')).toBe(IDE_BLUEPRINT)
46
+ expect(selectBlueprint('acryl.blank')).toBe(BLANK_BLUEPRINT)
47
+ expect(() => selectBlueprint('acryl.nope')).toThrow(UnknownBlueprintError)
48
+ })
49
+
50
+ it('reads the blueprint and rebrands it from the environment without mutating the built-in', () => {
51
+ const rebranded = blueprintFromEnvironment({ ACRYL_BLUEPRINT: 'acryl.blank', ACRYL_BRAND_NAME: 'Orbit', ACRYL_BRAND_ACCENT: '#e8590c' })
52
+ expect(rebranded.brand).toEqual({ kind: 'custom', identity: expect.objectContaining({ name: 'Orbit', accent: '#e8590c' }) })
53
+ expect(BLANK_BLUEPRINT.brand.kind === 'custom' && BLANK_BLUEPRINT.brand.identity.name).toBe('Blank')
54
+ expect(() => blueprintFromEnvironment({ ACRYL_BRAND_NAME: 'X', ACRYL_BRAND_ACCENT: 'red' })).toThrow(InvalidBrandIdentityError)
55
+ })
56
+ })
57
+
58
+ describe('what each Blueprint composes', () => {
59
+ it('the IDE is a Blend grown from blank: it keeps every capability and row of the blank canvas and says so', () => {
60
+ expect(IDE_BLUEPRINT.grewFrom).toBe(BLANK_BLUEPRINT.id)
61
+ for (const capability of BLANK_BLUEPRINT.capabilities) expect(IDE_BLUEPRINT.capabilities).toContain(capability)
62
+ for (const row of BLANK_BLUEPRINT.rows) expect(IDE_BLUEPRINT.rows).toContain(row)
63
+ })
64
+
65
+ it('full ACRYL composes every declared capability, including ones added later', () => {
66
+ expect([...IDE_BLUEPRINT.capabilities].sort()).toEqual(ACRYL_CODING_CAPABILITIES.map(capability => capability.id).sort())
67
+ })
68
+
69
+ it('full ACRYL keeps today\'s web rows in mount order', () => {
70
+ const { patches, packages } = composeBlueprintRows(IDE_BLUEPRINT, 'web')
71
+ expect(insertedIds(patches)).toEqual(['ui-acryl', 'acrylblends/cordis/router', 'acrylblends/cordis/router-http', 'community-market', 'acrylblends/cordis/state', 'acrylblends/cordis/inspect', 'acryl-plugin-context', 'acryl-system-prompt', '@acryl/ui', 'acryl-app-save', 'acryl-plugin-hub', 'acryl-shortcuts', 'acryl-mount-anchors', 'acryl-command-reply', 'acryl-plugin-hub/manager'])
72
+ expect(packages).toContain('@acryldev/brand-client')
73
+ // The Market injects `router` and `routerHttp`, so their rows come with it, once and just before it (spec 046).
74
+ expect(packages).toEqual(expect.arrayContaining(['@acryldev/blends', '@acryldev/cordis-plugin-market']))
75
+ })
76
+
77
+ it('does not mount the router rows twice when the profile already has them', () => {
78
+ const { patches } = composeBlueprintRows(IDE_BLUEPRINT, 'web', new Set(['acrylblends/cordis/router', 'acrylblends/cordis/router-http']))
79
+ expect(insertedIds(patches)).not.toContain('acrylblends/cordis/router')
80
+ expect(insertedIds(patches)).toContain('community-market')
81
+ expect(insertedIds(patches)).not.toContain('acrylblends/cordis/router-http')
82
+ })
83
+
84
+ it('blank web: brand, extension pack, prompt shaping, UI library and the start-page command reply only', () => {
85
+ const { patches } = composeBlueprintRows(BLANK_BLUEPRINT, 'web')
86
+ expect(insertedIds(patches)).toEqual(['brand', 'acrylblends/cordis/router', 'acrylblends/cordis/router-http', 'acrylblends/cordis/state', 'acrylblends/cordis/inspect', 'acryl-plugin-context', 'acryl-system-prompt', '@acryl/ui', 'acryl-app-save', 'acryl-plugin-hub', 'acryl-command-reply', 'acryl-plugin-hub/manager'])
87
+ const capabilities = new Set(BLANK_BLUEPRINT.capabilities)
88
+ const capabilityIds = insertedIds(createAcrylCodingCapabilityPatches(new Set(['web']), new Set(), capabilities))
89
+ expect(capabilityIds).toEqual(['authorization', 'acryl-settings'])
90
+ expect(createAcrylShellCapabilityPatches(new Set(['web']), 'advanced', new Set(), capabilities)).toEqual([])
91
+ })
92
+
93
+ it('blank keeps the agent essentials on the terminal and adds no browser rows', () => {
94
+ const { patches, packages } = composeBlueprintRows(BLANK_BLUEPRINT, 'tui')
95
+ expect(insertedIds(patches)).toEqual(['acryl-plugin-context', 'acryl-system-prompt', 'acryl-app-save', 'acryl-plugin-hub', 'acryl-plugin-hub/manager'])
96
+ expect(packages).toContain('@acryldev/ui-tui')
97
+ const tui = insertedIds(createAcrylCodingCapabilityPatches(new Set(['tui']), new Set(), new Set(BLANK_BLUEPRINT.capabilities)))
98
+ expect(tui).toEqual(['agent-preset-registry', 'session-stats', 'authorization', 'acryl-settings'])
99
+ })
100
+
101
+ it('a custom brand carries into the system prompt identity, and a row the profile already has is not composed twice', () => {
102
+ const { patches } = composeBlueprintRows(BLANK_BLUEPRINT, 'web', new Set(['acryl-plugin-context']))
103
+ expect(insertedIds(patches)).not.toContain('acryl-plugin-context')
104
+ const prompt = patches.flatMap(patch => patch.insert ?? []).find(row => row.id === 'acryl-system-prompt')
105
+ expect(String((prompt?.config as { identity?: string }).identity)).toContain('inside Blank')
106
+ })
107
+
108
+ it('returns fresh objects every call so one root cannot mutate another', () => {
109
+ const first = composeBlueprintRows(BLANK_BLUEPRINT, 'web').patches
110
+ const second = composeBlueprintRows(BLANK_BLUEPRINT, 'web').patches
111
+ expect(first).not.toBe(second)
112
+ expect(first).toEqual(second)
113
+ })
114
+
115
+ it('acryl.agents is the IDE with the DSH chat off: same rows, the chat rows disabled on web and desktop, untouched on the terminal', () => {
116
+ expect(AGENTS_BLUEPRINT.rows).toEqual(IDE_BLUEPRINT.rows)
117
+ expect(AGENTS_BLUEPRINT.grewFrom).toBe(IDE_BLUEPRINT.id)
118
+ expect(IDE_BLUEPRINT.dshChat).toBe(true)
119
+ for (const surface of ['web', 'desktop'] as const) {
120
+ const disabled = composeBlueprintRows(AGENTS_BLUEPRINT, surface).patches.filter(patch => patch.disabled === true).map(patch => patch.id)
121
+ expect(disabled).toEqual(expect.arrayContaining([...DSH_CHAT_ROW_IDS]))
122
+ expect(composeBlueprintRows(IDE_BLUEPRINT, surface).patches.filter(patch => patch.disabled === true).map(patch => patch.id)).not.toContain('agent')
123
+ }
124
+ // The terminal client is the DSH chat itself: switching it off there would leave nothing to run.
125
+ expect(composeBlueprintRows(AGENTS_BLUEPRINT, 'tui').patches.filter(patch => patch.disabled === true && DSH_CHAT_ROW_IDS.includes(patch.id ?? ''))).toEqual([])
126
+ })
127
+
128
+ it('with the plugin hub, DSH\'s plugin manager row is swapped for the hub\'s on every surface, never doubled', () => {
129
+ for (const surface of ['tui', 'web', 'desktop'] as const) {
130
+ const { patches } = composeBlueprintRows(BLANK_BLUEPRINT, surface)
131
+ expect(patches.filter(patch => patch.disabled === true).map(patch => patch.id)).toContain(DSH_PLUGIN_MANAGER_ROW_ID)
132
+ expect(insertedIds(patches).filter(id => id === PLUGIN_MANAGER_ROW_ID)).toHaveLength(1)
133
+ // A profile whose own bundle already composes the hub's manager keeps DSH's row alone: no second swap.
134
+ expect(insertedIds(composeBlueprintRows(BLANK_BLUEPRINT, surface, new Set([PLUGIN_MANAGER_ROW_ID])).patches)).not.toContain(PLUGIN_MANAGER_ROW_ID)
135
+ }
136
+ expect(insertedIds(composeBlueprintRows({ ...BLANK_BLUEPRINT, rows: BLANK_BLUEPRINT.rows.filter(row => row !== 'plugin-hub') }, 'web').patches)).not.toContain(PLUGIN_MANAGER_ROW_ID)
137
+ })
138
+ })