@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,316 @@
1
+ import { mkdtemp, rm, writeFile } from 'node:fs/promises'
2
+ import { tmpdir } from 'node:os'
3
+ import { join } from 'node:path'
4
+ import { afterEach, describe, expect, it } from 'vitest'
5
+ import { DEFAULT_PROFILE_BUNDLES, initProfile, resolveProfileDir } from '@deepseek-ai/dsh-app-boot'
6
+ import { createAssistantMessage, createToolResultMessage } from '@deepseek-ai/dsh-llm'
7
+ import { SessionId } from '@deepseek-ai/dsh-session'
8
+ import { bootAcrylHarnessProfile } from '../src/index.ts'
9
+ import { createAcrylSessionBridge } from '../src/session-bridge.ts'
10
+
11
+ const temporaryHomes: string[] = []
12
+ const initialDshHome = process.env.DSH_HOME
13
+
14
+ async function bootRuntime(profile: string) {
15
+ process.env.DSH_HOME = await mkdtemp(join(tmpdir(), 'acryl-session-bridge-'))
16
+ temporaryHomes.push(process.env.DSH_HOME)
17
+ const profileDirectory = resolveProfileDir(profile)
18
+ initProfile(profileDirectory, DEFAULT_PROFILE_BUNDLES)
19
+ await writeFile(join(profileDirectory, 'cordis.patch.yml'), '- id: hmr\n disabled: true\n')
20
+ return bootAcrylHarnessProfile({ profile })
21
+ }
22
+
23
+ afterEach(async () => {
24
+ // Assigning undefined would store the string "undefined" and the next boot would create a ./undefined profile directory.
25
+ if (initialDshHome === undefined) delete process.env.DSH_HOME
26
+ else process.env.DSH_HOME = initialDshHome
27
+ await Promise.all(temporaryHomes.splice(0).map(home => rm(home, { force: true, recursive: true })))
28
+ })
29
+
30
+ // Every test here boots a real runtime (one boots two); under load the 5 s default is a coin flip, as the other real-engine specs already know.
31
+ describe('createAcrylSessionBridge', { timeout: 60_000 }, () => {
32
+ it('creates one native durable session and projects its initial state', async () => {
33
+ const runtime = await bootRuntime('acryl-test')
34
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
35
+ profile: 'acryl-test',
36
+ generationId: 'generation-test',
37
+ attachment: 'owner',
38
+ cwd: process.cwd(),
39
+ })
40
+
41
+ const sessionId = await bridge.open()
42
+ const snapshot = await bridge.snapshot(sessionId)
43
+
44
+ expect(snapshot).toMatchObject({
45
+ profile: 'acryl-test',
46
+ generationId: 'generation-test',
47
+ attachment: 'owner',
48
+ sessionId,
49
+ agentStatus: 'idle',
50
+ transcript: [],
51
+ tools: [],
52
+ })
53
+
54
+ await bridge.dispose()
55
+ await runtime.dispose()
56
+ })
57
+
58
+ it('forwards cancellation into the native active turn', async () => {
59
+ const runtime = await bootRuntime('acryl-test')
60
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
61
+ profile: 'acryl-test',
62
+ generationId: 'generation-test',
63
+ attachment: 'owner',
64
+ cwd: process.cwd(),
65
+ })
66
+ try {
67
+ const sessionId = await bridge.open()
68
+ const stop = runtime.ctx.on('session/event', (session, event) => {
69
+ if (session.id === sessionId && event.type === 'user/message') bridge.cancel(sessionId)
70
+ })
71
+ await bridge.submitPrompt({ sessionId, text: 'Cancel this turn' })
72
+ stop()
73
+
74
+ expect(runtime.ctx.agents.get(SessionId(sessionId))?.session.snapshotEvents()).toContainEqual(expect.objectContaining({
75
+ type: 'turn/end',
76
+ data: expect.objectContaining({ reason: expect.objectContaining({ kind: 'aborted' }) }),
77
+ }))
78
+ } finally {
79
+ await bridge.dispose()
80
+ await runtime.dispose()
81
+ }
82
+ })
83
+
84
+ it('notifies a subscription when the agent goes idle after a turn, which logs no event of its own', async () => {
85
+ const runtime = await bootRuntime('acryl-test')
86
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
87
+ profile: 'acryl-test',
88
+ generationId: 'generation-test',
89
+ attachment: 'owner',
90
+ cwd: process.cwd(),
91
+ })
92
+ try {
93
+ const sessionId = await bridge.open()
94
+ const statuses: string[] = []
95
+ await bridge.subscribe(sessionId, (snapshot) => { statuses.push(snapshot.agentStatus) })
96
+ // The test profile has no model to finish a turn, so the turn is cancelled: it still ends, and the agent still goes idle.
97
+ const stop = runtime.ctx.on('session/event', (session, event) => {
98
+ if (session.id === sessionId && event.type === 'user/message') bridge.cancel(sessionId)
99
+ })
100
+ await bridge.submitPrompt({ sessionId, text: 'A turn' })
101
+ stop()
102
+ const agent = runtime.ctx.agents.get(SessionId(sessionId))
103
+ if (agent === undefined) throw new Error('test agent was not registered')
104
+ await agent.whenIdle()
105
+ await new Promise(resolve => setTimeout(resolve, 0))
106
+ expect(statuses).toContain('running')
107
+ expect(statuses.at(-1)).toBe('idle')
108
+ } finally {
109
+ await bridge.dispose()
110
+ await runtime.dispose()
111
+ }
112
+ })
113
+
114
+ it('notifies a subscription then stops after disposal', async () => {
115
+ const runtime = await bootRuntime('acryl-test')
116
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
117
+ profile: 'acryl-test',
118
+ generationId: 'generation-test',
119
+ attachment: 'owner',
120
+ cwd: process.cwd(),
121
+ })
122
+ try {
123
+ const sessionId = await bridge.open()
124
+ const updates: string[][] = []
125
+ const subscription = await bridge.subscribe(sessionId, snapshot => {
126
+ updates.push(snapshot.transcript.map(item => item.text))
127
+ })
128
+ await bridge.submitPrompt({ sessionId, text: 'Observed prompt' })
129
+ expect(updates.at(-1)).toEqual(['Observed prompt'])
130
+
131
+ await subscription.dispose()
132
+ const session = runtime.ctx.agents.get(SessionId(sessionId))?.session
133
+ if (session === undefined) throw new Error('test agent was not registered')
134
+ session.append('todo/write', { todos: [] })
135
+ await new Promise(resolve => setTimeout(resolve, 0))
136
+ expect(updates.at(-1)).toEqual(['Observed prompt'])
137
+ } finally {
138
+ await bridge.dispose()
139
+ await runtime.dispose()
140
+ }
141
+ })
142
+
143
+ it('resumes a persisted session and replays its durable transcript', async () => {
144
+ const runtime = await bootRuntime('acryl-test')
145
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
146
+ profile: 'acryl-test',
147
+ generationId: 'generation-one',
148
+ attachment: 'owner',
149
+ cwd: process.cwd(),
150
+ })
151
+ const sessionId = await bridge.open()
152
+ await bridge.submitPrompt({ sessionId, text: 'Keep this prompt' })
153
+ await bridge.dispose()
154
+ await runtime.dispose()
155
+
156
+ const resumedRuntime = await bootAcrylHarnessProfile({ profile: 'acryl-test' })
157
+ const resumedBridge = createAcrylSessionBridge(resumedRuntime.ctx, {
158
+ profile: 'acryl-test',
159
+ generationId: 'generation-two',
160
+ attachment: 'owner',
161
+ cwd: process.cwd(),
162
+ })
163
+ try {
164
+ await resumedBridge.open(sessionId)
165
+ await expect(resumedBridge.snapshot(sessionId)).resolves.toMatchObject({
166
+ transcript: [{ author: 'user', text: 'Keep this prompt' }],
167
+ })
168
+ } finally {
169
+ await resumedBridge.dispose()
170
+ await resumedRuntime.dispose()
171
+ }
172
+ })
173
+
174
+ it('replays durable assistant and tool records into the projection', async () => {
175
+ const runtime = await bootRuntime('acryl-test')
176
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
177
+ profile: 'acryl-test',
178
+ generationId: 'generation-test',
179
+ attachment: 'owner',
180
+ cwd: process.cwd(),
181
+ })
182
+ try {
183
+ const sessionId = await bridge.open()
184
+ const session = runtime.ctx.agents.get(SessionId(sessionId))?.session
185
+ if (session === undefined) throw new Error('test agent was not registered')
186
+ session.append('turn/start', { turn: 1 })
187
+ session.append('step/start', { turn: 1, step: 1 })
188
+ session.append('assistant/message', {
189
+ turn: 1,
190
+ step: 1,
191
+ // Session format v2: a durable Assistant settlement carries its compact stream.
192
+ stream: [
193
+ { type: 'chunk', time: 1, chunk: { type: 'usage', usage: { inputTokens: 1, outputTokens: 1 } } },
194
+ { type: 'chunk', time: 2, chunk: { type: 'finish', reason: { kind: 'stop' } } },
195
+ ],
196
+ message: createAssistantMessage({
197
+ content: [{ type: 'text', text: 'Native response' }],
198
+ source: { provider: 'test', model: 'test' },
199
+ }),
200
+ } as never, { surfaceOp: 'append' })
201
+ session.append('tool/call', { turn: 1, step: 1, callId: 'call-1', name: 'inspect', arguments: '{}' })
202
+ session.append('tool/result', {
203
+ turn: 1,
204
+ step: 1,
205
+ message: createToolResultMessage({
206
+ callId: 'call-1',
207
+ content: [{ type: 'text', text: 'done' }],
208
+ isError: false,
209
+ }),
210
+ }, { surfaceOp: 'append' })
211
+ session.append('step/end', { turn: 1, step: 1 })
212
+ session.append('turn/end', { turn: 1, reason: { kind: 'stop' } })
213
+
214
+ await expect(bridge.snapshot(sessionId)).resolves.toMatchObject({
215
+ transcript: [{ author: 'assistant', text: 'Native response' }],
216
+ tools: [{ callId: 'call-1', name: 'inspect', status: 'succeeded' }],
217
+ })
218
+ } finally {
219
+ await bridge.dispose()
220
+ await runtime.dispose()
221
+ }
222
+ })
223
+
224
+ it('streams incremental durable events to an event subscription', async () => {
225
+ const runtime = await bootRuntime('acryl-test')
226
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
227
+ profile: 'acryl-test',
228
+ generationId: 'generation-test',
229
+ attachment: 'owner',
230
+ cwd: process.cwd(),
231
+ })
232
+ try {
233
+ const sessionId = await bridge.open()
234
+ const seen: string[] = []
235
+ const subscription = await bridge.subscribeEvents(sessionId, event => {
236
+ seen.push(event.type)
237
+ })
238
+
239
+ const session = runtime.ctx.agents.get(SessionId(sessionId))?.session
240
+ if (session === undefined) throw new Error('test agent was not registered')
241
+ session.append('assistant/chunk', { turn: 1, step: 1, chunk: { type: 'text', text: 'hello' } })
242
+ await new Promise(resolve => setTimeout(resolve, 0))
243
+
244
+ expect(seen).toContain('assistant/chunk')
245
+
246
+ await subscription.dispose()
247
+ session.append('tool/call', { turn: 1, step: 1, callId: 'call-1', name: 'inspect', arguments: '{}' })
248
+ await new Promise(resolve => setTimeout(resolve, 0))
249
+ expect(seen).not.toContain('tool/call')
250
+ } finally {
251
+ await bridge.dispose()
252
+ await runtime.dispose()
253
+ }
254
+ })
255
+
256
+ it('exposes the full durable event log for store seeding and replay', async () => {
257
+ const runtime = await bootRuntime('acryl-test')
258
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
259
+ profile: 'acryl-test',
260
+ generationId: 'generation-test',
261
+ attachment: 'owner',
262
+ cwd: process.cwd(),
263
+ })
264
+ try {
265
+ const sessionId = await bridge.open()
266
+ await bridge.submitPrompt({ sessionId, text: 'seed me' })
267
+
268
+ const events = bridge.events(sessionId)
269
+ expect(events.some(event => event.type === 'user/message')).toBe(true)
270
+ expect(events).toEqual(runtime.ctx.agents.get(SessionId(sessionId))?.session.snapshotEvents())
271
+ } finally {
272
+ await bridge.dispose()
273
+ await runtime.dispose()
274
+ }
275
+ })
276
+
277
+ it('does not accumulate native agents for repeated opens', async () => {
278
+ const runtime = await bootRuntime('acryl-test')
279
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
280
+ profile: 'acryl-test',
281
+ generationId: 'generation-test',
282
+ attachment: 'owner',
283
+ cwd: process.cwd(),
284
+ })
285
+ try {
286
+ await bridge.open()
287
+ await expect(bridge.open()).rejects.toThrow('already has an active session')
288
+ } finally {
289
+ await bridge.dispose()
290
+ await runtime.dispose()
291
+ }
292
+ })
293
+
294
+ it('persists a submitted prompt in the native durable session', async () => {
295
+ const runtime = await bootRuntime('acryl-test')
296
+ const bridge = createAcrylSessionBridge(runtime.ctx, {
297
+ profile: 'acryl-test',
298
+ generationId: 'generation-test',
299
+ attachment: 'owner',
300
+ cwd: process.cwd(),
301
+ })
302
+ try {
303
+ const sessionId = await bridge.open()
304
+
305
+ await bridge.submitPrompt({ sessionId, text: 'Persist this prompt' })
306
+ await new Promise(resolve => setTimeout(resolve, 25))
307
+
308
+ await expect(bridge.snapshot(sessionId)).resolves.toMatchObject({
309
+ transcript: [{ author: 'user', text: 'Persist this prompt' }],
310
+ })
311
+ } finally {
312
+ await bridge.dispose()
313
+ await runtime.dispose()
314
+ }
315
+ })
316
+ })
@@ -0,0 +1,65 @@
1
+ /** Where a new app starts from (spec 036): a folder, a git repository (via a real local git server), or a starter id in a registry. */
2
+ import { spawnSync } from 'node:child_process'
3
+ import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
4
+ import { tmpdir } from 'node:os'
5
+ import { join, resolve } from 'node:path'
6
+ import { afterEach, describe, expect, it } from 'vitest'
7
+ import { buildRegistryIndex } from '@acryldev/blends-core'
8
+ import { StartSourceError, classifyStartSource, resolveStartSource } from '../src/app/start-source.ts'
9
+
10
+ const dirs: string[] = []
11
+ afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { force: true, recursive: true }) })
12
+ const temp = (): string => { const dir = realpathSync(mkdtempSync(join(tmpdir(), 'acryl-start-'))); dirs.push(dir); return dir }
13
+ const git = (cwd: string, ...args: string[]) => { const r = spawnSync('git', args, { cwd, encoding: 'utf8' }); if (r.status !== 0) throw new Error(r.stderr) }
14
+
15
+ const starter = (id: string) => `apiVersion: blends.acryl.dev/v1alpha1\nkind: Blend\nmetadata:\n id: ${id}\n name: Accounting\n version: 0.1.0\n license: MIT\n visibility: public\nspec:\n runtime: cordis\n lineage:\n blueprint: acryl.blank\n blueprintVersion: 0.1.0\n`
16
+
17
+ /** A git repository on disk, reached by a file:// URL: the same transport as a remote one, without a network. */
18
+ function repository(root: string, files: Record<string, string>): string {
19
+ const dir = join(root, 'origin'); mkdirSync(dir, { recursive: true })
20
+ for (const [path, text] of Object.entries(files)) { mkdirSync(join(dir, path, '..'), { recursive: true }); writeFileSync(join(dir, path), text) }
21
+ git(dir, 'init', '--quiet'); git(dir, 'add', '.'); git(dir, '-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '--quiet', '-m', 'x')
22
+ return `file://${dir}`
23
+ }
24
+
25
+ describe('classifyStartSource', () => {
26
+ it('tells folders, git URLs and starter ids apart', () => {
27
+ expect(classifyStartSource('/x', path => path === '/x' || path === resolve('/x'))).toEqual({ kind: 'folder', path: resolve('/x') })
28
+ expect(classifyStartSource('git@github.com:agency/accounting.git', () => false)).toEqual({ kind: 'git', url: 'git@github.com:agency/accounting.git' })
29
+ expect(classifyStartSource('https://github.com/acrylblends/acrylblends.github.io.git#registry/blends/x', () => false)).toMatchObject({ kind: 'git', subdir: 'registry/blends/x' })
30
+ expect(classifyStartSource('acme.accounting', () => false)).toEqual({ kind: 'registry', id: 'acme.accounting' })
31
+ expect(() => classifyStartSource('just words', () => false)).toThrow(StartSourceError)
32
+ expect(() => classifyStartSource('https://h/r.git#../etc', () => false)).toThrow(/not a folder inside/)
33
+ })
34
+ })
35
+
36
+ describe('resolveStartSource', () => {
37
+ it('clones a git repository (private ones use the user\'s own git login) and cleans up after', () => {
38
+ const url = repository(temp(), { 'blend.yaml': starter('agency.accounting'), 'plugins/ledger/package.json': '{}' })
39
+ const resolved = resolveStartSource(url)
40
+ expect(existsSync(join(resolved.folder, 'plugins', 'ledger', 'package.json'))).toBe(true)
41
+ resolved.dispose()
42
+ expect(existsSync(resolved.folder)).toBe(false)
43
+ })
44
+
45
+ it('finds a starter by id in a registry, from a git repository or a folder', () => {
46
+ const root = temp()
47
+ const { index } = buildRegistryIndex([{ path: 'blends/acme.accounting', manifestText: starter('acme.accounting') }])
48
+ const url = repository(root, { 'registry/index.json': JSON.stringify(index), 'registry/blends/acme.accounting/blend.yaml': starter('acme.accounting') })
49
+ const fromGit = resolveStartSource('acme.accounting', { registry: `${url}#registry` })
50
+ expect(fromGit.folder.endsWith(join('registry', 'blends', 'acme.accounting'))).toBe(true)
51
+ expect(fromGit.origin).toContain('acme.accounting')
52
+ fromGit.dispose()
53
+ const fromFolder = resolveStartSource('acme.accounting', { registry: `${join(root, 'origin')}#registry` })
54
+ expect(existsSync(join(fromFolder.folder, 'blend.yaml'))).toBe(true)
55
+ expect(() => resolveStartSource('acme.missing', { registry: `${join(root, 'origin')}#registry` })).toThrow(/no starter "acme.missing"/)
56
+ })
57
+
58
+ it('says what is wrong: not a repository, no credentials, not an app', () => {
59
+ const root = temp()
60
+ expect(() => resolveStartSource('file:///nowhere/at/all.git')).toThrow(/could not clone.*own git login/su)
61
+ mkdirSync(join(root, 'empty'))
62
+ expect(() => resolveStartSource(join(root, 'empty'))).toThrow(/has no blend.yaml/)
63
+ expect(() => resolveStartSource('acme.x', { registry: join(root, 'empty') })).toThrow(/not a registry/)
64
+ })
65
+ })
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The `@acryldev/system-prompt` plugin on the real engines: the model receives the ACRYL identity first, every other section tagged pi.dev-style
3
+ * with the extension router present exactly once, and upstream's contribution matches the committed drift baseline. A harness update that changes
4
+ * the harness's prompt sections fails the baseline check and shows which sections changed; refresh it deliberately with
5
+ * `ACRYL_UPDATE_DRIFT=1 corepack pnpm --filter @acryldev/harness-runtime exec vitest run tests/system-prompt-shape.spec.ts`.
6
+ */
7
+ import { existsSync, readFileSync, writeFileSync } 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 { afterEach, describe, expect, it } from 'vitest'
13
+ import { createDshEngineDefinition, createWebEngineDefinition } from '../src/engine-dsh.ts'
14
+ import { createAcrylEngineHost } from '../src/engine-host.ts'
15
+ import { ceilingsFor, measurePromptBudget, overBudget, type BudgetCeilings } from '../src/prompt-budget.ts'
16
+ import { captureSystemPrompt } from '../src/system-prompt-capture.ts'
17
+ import { fileURLToPath } from 'node:url'
18
+ import { codingCapabilities } from '@acryldev/coding-capabilities'
19
+
20
+ const driftDir = fileURLToPath(new URL('../../../plugins/system-prompt/drift/', import.meta.url))
21
+ // Windows has its own shell tool (`pwsh`, not `bash`), so what the harness contributes differs there by design; its baselines are recorded separately (`*.win32.json`).
22
+ const platformSuffix = process.platform === 'win32' ? '.win32' : ''
23
+ const temporaryHomes: string[] = []
24
+ const initialDshHome = process.env.DSH_HOME
25
+ afterEach(async () => {
26
+ // Assigning undefined would store the string "undefined" and the next boot would create a ./undefined profile directory.
27
+ if (initialDshHome === undefined) delete process.env.DSH_HOME
28
+ else process.env.DSH_HOME = initialDshHome
29
+ await Promise.all(temporaryHomes.splice(0).map(home => rm(home, { force: true, recursive: true })))
30
+ })
31
+
32
+ async function capture(kind: 'web' | 'cli') {
33
+ process.env.DEEPSEEK_API_KEY = 'dummy-key-for-prompt-capture'
34
+ const home = await mkdtemp(join(tmpdir(), 'acryl-shape-'))
35
+ temporaryHomes.push(home)
36
+ process.env.DSH_HOME = home
37
+ const host = await createAcrylEngineHost(kind === 'cli'
38
+ ? { engines: [createDshEngineDefinition('acryl-shape', codingCapabilities)], initialEngine: 'dsh' }
39
+ : {
40
+ engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
41
+ initialEngine: 'dsh',
42
+ prepare: ctx => { provideCmdline(ctx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
43
+ })
44
+ try {
45
+ const captured = await captureSystemPrompt(host.ctx, { profile: kind === 'cli' ? 'acryl-shape' : 'web', selectStandardPreset: kind === 'web' })
46
+ const service = host.ctx.get('acrylSystemPrompt' as never) as unknown as { lastUpstream(): Array<{ name: string; hash: string }> }
47
+ return { captured, upstream: service.lastUpstream() }
48
+ } finally { await host.dispose() }
49
+ }
50
+
51
+ describe.each(['web', 'cli'] as const)('@acryldev/system-prompt on the %s engine', kind => {
52
+ it('puts the ACRYL identity first, tags sections pi.dev-style, and keeps the router once', async () => {
53
+ const { captured, upstream } = await capture(kind)
54
+ expect(captured.system.startsWith('You are an expert coding assistant operating inside ACRYL')).toBe(true)
55
+ expect(captured.system).not.toContain('powered by DeepSeek Harness')
56
+ expect(captured.system).toContain('<tool_read>')
57
+ expect(captured.system).toContain('</tool_read>')
58
+ expect(captured.system.match(/<acryl_plugin_docs>/gu)).toHaveLength(1)
59
+ expect(captured.system).not.toMatch(/<plan_policy>\s*<\/plan_policy>/u)
60
+ expect(upstream.length).toBeGreaterThan(5)
61
+ }, 90_000)
62
+
63
+ it('matches the committed baseline of what upstream contributes', async () => {
64
+ const { upstream } = await capture(kind)
65
+ const baselinePath = join(driftDir, `${kind}${platformSuffix}.json`)
66
+ if (process.env.ACRYL_UPDATE_DRIFT === '1' || !existsSync(baselinePath)) {
67
+ writeFileSync(baselinePath, `${JSON.stringify(upstream, null, 2)}\n`)
68
+ return
69
+ }
70
+ const baseline = JSON.parse(readFileSync(baselinePath, 'utf8')) as Array<{ name: string; hash: string }>
71
+ // `harness:source` states where this machine's harness checkout lives on disk, so its hash differs per
72
+ // checkout location and says nothing about what the harness contributes; it is not part of the shape.
73
+ const MACHINE_SPECIFIC = new Set(['harness:source'])
74
+ const byName = (list: Array<{ name: string; hash: string }>) => new Map(list.filter(section => !MACHINE_SPECIFIC.has(section.name)).map(section => [section.name, section.hash]))
75
+ const before = byName(baseline)
76
+ const now = byName(upstream)
77
+ const added = [...now.keys()].filter(name => !before.has(name))
78
+ const removed = [...before.keys()].filter(name => !now.has(name))
79
+ const changed = [...now.keys()].filter(name => before.has(name) && before.get(name) !== now.get(name))
80
+ expect({ added, removed, changed }, 'the harness changed its prompt sections; review, then refresh with ACRYL_UPDATE_DRIFT=1').toEqual({ added: [], removed: [], changed: [] })
81
+ }, 90_000)
82
+
83
+ it('stays within the committed size ceilings for the system prompt and the tool definitions', async () => {
84
+ const { captured } = await capture(kind)
85
+ const budget = measurePromptBudget(captured)
86
+ const path = join(driftDir, `budget${platformSuffix}.json`)
87
+ const all = existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) as Record<string, BudgetCeilings> : {}
88
+ if (process.env.ACRYL_UPDATE_DRIFT === '1' || all[kind] === undefined) {
89
+ writeFileSync(path, `${JSON.stringify({ ...all, [kind]: ceilingsFor(budget) }, null, 2)}\n`)
90
+ return
91
+ }
92
+ // Growth is a decision: raise the ceiling on purpose (ACRYL_UPDATE_DRIFT=1) after reviewing docs/system-prompt/budget.md.
93
+ expect(overBudget(budget, all[kind])).toEqual([])
94
+ }, 90_000)
95
+ })
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The three levels of the framework (spec 036): the blank canvas (built-in Blueprint), a starter kit (a Blueprint that extends another), and a project
3
+ * (a Blend grown from either). A starter boots as it is; a project grown from a starter keeps it in blueprints/, so it boots anywhere.
4
+ */
5
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
6
+ import { tmpdir } from 'node:os'
7
+ import { join } from 'node:path'
8
+ import { afterEach, describe, expect, it } from 'vitest'
9
+ import { BLANK_BLUEPRINT, InvalidBlueprintError, catalogWithStarters, planNewApp, readBlueprintFile, writeNewApp, blueprintFromManifest } from '../src/index.ts'
10
+ import { parse } from 'yaml'
11
+
12
+ const dirs: string[] = []
13
+ afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { force: true, recursive: true }) })
14
+ const temp = (): string => { const dir = realpathSync(mkdtempSync(join(tmpdir(), 'acryl-levels-'))); dirs.push(dir); return dir }
15
+
16
+ const starter = `# The sound-stage starter kit.
17
+ apiVersion: blends.acryl.dev/v1alpha1
18
+ kind: Blueprint
19
+ metadata:
20
+ id: acme.sound-stage
21
+ name: Sound Stage
22
+ version: 1.2.0
23
+ license: MIT
24
+ visibility: public
25
+ spec:
26
+ runtime: cordis
27
+ extends: acryl.blank
28
+ rows:
29
+ - id: brand
30
+ name: '@acryldev/brand'
31
+ config:
32
+ name: Sound Stage
33
+ accent: "#e8590c"
34
+ - id: community-market
35
+ name: '@acryldev/cordis-plugin-market'
36
+ `
37
+
38
+ describe('three levels', () => {
39
+ it('a starter kit boots as it is: the blank canvas plus what it adds', () => {
40
+ const dir = temp(); writeFileSync(join(dir, 'blend.yaml'), starter)
41
+ const blueprint = readBlueprintFile(join(dir, 'blend.yaml'))
42
+ expect(blueprint.id).toBe('acme.sound-stage')
43
+ expect(blueprint.capabilities).toEqual(BLANK_BLUEPRINT.capabilities)
44
+ expect(blueprint.rows).toEqual([...BLANK_BLUEPRINT.rows, 'community-market'])
45
+ expect(blueprint.brand).toEqual({ kind: 'custom', identity: expect.objectContaining({ name: 'Sound Stage', accent: '#e8590c' }) })
46
+ })
47
+
48
+ it('a project from a starter is the user\'s own: private, Proprietary, the starter kept in blueprints/ and its license in THIRD-PARTY.md', () => {
49
+ const root = temp()
50
+ const project = join(root, 'my-gigs')
51
+ writeNewApp(planNewApp(project, { title: 'My Gigs', launcher: '/fw/scripts/blank.mjs', from: { manifestText: starter } }), { git: false })
52
+ const manifest = parse(readFileSync(join(project, 'blend.yaml'), 'utf8')) as Record<string, any>
53
+ expect(manifest.kind).toBe('Blend')
54
+ expect(manifest.spec.extends).toBeUndefined()
55
+ expect(manifest.spec.lineage).toEqual({ blueprint: 'acme.sound-stage', blueprintVersion: '1.2.0' })
56
+ expect(manifest.metadata).toMatchObject({ id: 'app.my-gigs', name: 'My Gigs', license: 'Proprietary', visibility: 'private' })
57
+ expect(readFileSync(join(project, 'blueprints', 'acme.sound-stage.yaml'), 'utf8')).toBe(starter)
58
+ expect(readFileSync(join(project, 'THIRD-PARTY.md'), 'utf8')).toMatch(/acme\.sound-stage \(Sound Stage\), licensed MIT/u)
59
+ const blueprint = readBlueprintFile(join(project, 'blend.yaml'))
60
+ expect(blueprint.id).toBe('app.my-gigs')
61
+ expect(blueprint.rows).toContain('community-market') // inherited through the starter
62
+ expect(blueprint.brand).toEqual({ kind: 'custom', identity: expect.objectContaining({ name: 'My Gigs', accent: '#e8590c' }) })
63
+ })
64
+
65
+ it('a project from a project brings the chain of starters with it', () => {
66
+ const root = temp()
67
+ const first = join(root, 'my-gigs')
68
+ writeNewApp(planNewApp(first, { title: 'My Gigs', launcher: '/fw', from: { manifestText: starter } }), { git: false })
69
+ const second = join(root, 'my-gigs-eu')
70
+ writeNewApp(planNewApp(second, { title: 'My Gigs EU', launcher: '/fw', from: { manifestText: readFileSync(join(first, 'blend.yaml'), 'utf8') } }), { git: false, blueprintsFrom: join(first, 'blueprints') })
71
+ expect(existsSync(join(second, 'blueprints', 'acme.sound-stage.yaml'))).toBe(true)
72
+ expect(readBlueprintFile(join(second, 'blend.yaml')).rows).toContain('community-market')
73
+ })
74
+
75
+ it('an unknown parent and a cycle between starters are refused with a message', () => {
76
+ const orphan = temp(); writeFileSync(join(orphan, 'blend.yaml'), starter.replace('extends: acryl.blank', 'extends: acme.missing'))
77
+ expect(() => readBlueprintFile(join(orphan, 'blend.yaml'))).toThrow(/acme\.missing/)
78
+ const a = { id: 'acme.a', document: parse(starter.replace('acme.sound-stage', 'acme.a').replace('extends: acryl.blank', 'extends: acme.b')) }
79
+ const b = { id: 'acme.b', document: parse(starter.replace('acme.sound-stage', 'acme.b').replace('extends: acryl.blank', 'extends: acme.a')) }
80
+ expect(() => catalogWithStarters([a, b]).get('acme.a')).toThrow(InvalidBlueprintError)
81
+ expect(() => blueprintFromManifest(parse(starter.replace('extends: acryl.blank', 'extends: acme.a')), catalogWithStarters([a, b]))).toThrow(/cycle/)
82
+ void mkdirSync
83
+ })
84
+ })