@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,83 @@
1
+ /**
2
+ * Spec 044 S12, opt-in and live (network, third-party code): ACRYL runs released community DSH plugins. Each plugin is pulled from its GitHub
3
+ * release through the plugin hub (sha512 checked), installed with DSH's own installer into a throwaway Web profile (install scripts stay
4
+ * blocked), and the engine is booted again, as an app restart does; then each plugin's Loader rows are read. The result is written to
5
+ * ACRYL_LIVE_COMMUNITY_REPORT (JSON) for the spec's record. Run:
6
+ *
7
+ * ACRYL_LIVE_COMMUNITY=1 ACRYL_LIVE_COMMUNITY_REPORT=/tmp/s12.json corepack pnpm --filter @acryldev/harness-runtime exec vitest run tests/live/community-plugins.spec.ts
8
+ */
9
+ import { writeFileSync } from 'node:fs'
10
+ import { mkdtemp, rm } from 'node:fs/promises'
11
+ import { tmpdir } from 'node:os'
12
+ import { join } from 'node:path'
13
+ import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
14
+ import { createPluginHub, githubReleasesOverHttps, PluginStore, type InstallerPort } from '@acryldev/plugin-hub-core'
15
+ import { afterEach, describe, expect, it } from 'vitest'
16
+ import { createWebEngineDefinition } from '../../src/engine-dsh.ts'
17
+ import { createAcrylEngineHost } from '../../src/engine-host.ts'
18
+
19
+ const PLUGINS = [
20
+ 'SpookySandwich/dsh-plugin-message-edit',
21
+ 'SpookySandwich/dsh-plugin-smooth-stream',
22
+ 'yusufameri/dsh-t3-model-picker',
23
+ 'Charaaah/dsh-web-api-balance',
24
+ 'MoYu-CN/dsh-knowledge',
25
+ 'MoYu-CN/dsh-agent-profiles',
26
+ 'lgquan/dsh-workspace-memory',
27
+ 'wobenshiwomu/dsh-bite',
28
+ ]
29
+
30
+ const live = process.env['ACRYL_LIVE_COMMUNITY'] === '1'
31
+ const homes: string[] = []
32
+ const initialDshHome = process.env['DSH_HOME']
33
+ afterEach(async () => {
34
+ if (initialDshHome === undefined) delete process.env['DSH_HOME']
35
+ else process.env['DSH_HOME'] = initialDshHome
36
+ await Promise.all(homes.splice(0).map(home => rm(home, { recursive: true, force: true })))
37
+ })
38
+
39
+ const boot = () => createAcrylEngineHost({
40
+ engines: [createWebEngineDefinition(new URL('../../package.json', import.meta.url).href)],
41
+ initialEngine: 'dsh',
42
+ prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
43
+ })
44
+
45
+ interface ManagerRows { listPlugins(): Promise<{ entryId: string; moduleName: string; enabled: boolean; fiberPhase?: string }[]> }
46
+
47
+ describe.skipIf(!live)('S12: ACRYL runs released community DSH plugins', () => {
48
+ it('pulls, installs and restarts with each plugin, and records what each one does', async () => {
49
+ const home = await mkdtemp(join(tmpdir(), 'acryl-s12-'))
50
+ homes.push(home)
51
+ process.env['DSH_HOME'] = home
52
+ const report: Record<string, unknown>[] = []
53
+ const first = await boot()
54
+ try {
55
+ const installer = first.ctx.get('pluginManager' as never) as unknown as InstallerPort
56
+ const hub = createPluginHub({ store: new PluginStore(join(home, 'plugin-store')), releases: githubReleasesOverHttps(), has: name => first.ctx.get(name as never) !== undefined, installer: () => installer })
57
+ for (const repo of PLUGINS) {
58
+ try {
59
+ const pulled = await hub.pull(`github:${repo}`)
60
+ report.push({ repo, name: pulled.name, version: pulled.version, pull: pulled.status, contractChecked: pulled.contractChecked, ...(pulled.outcome?.error === undefined ? {} : { installError: pulled.outcome.error, output: pulled.outcome.packageResult?.output.split('\n').slice(-6).join('\n') }) })
61
+ } catch (cause) {
62
+ report.push({ repo, pull: 'error', error: cause instanceof Error ? cause.message : String(cause) })
63
+ }
64
+ }
65
+ } finally {
66
+ await first.dispose()
67
+ }
68
+ const again = await boot()
69
+ try {
70
+ const rows = await (again.ctx.get('pluginManager' as never) as unknown as ManagerRows).listPlugins()
71
+ for (const entry of report) {
72
+ const name = entry['name']
73
+ if (typeof name !== 'string') continue
74
+ entry['rows'] = rows.filter(row => row.moduleName === name || row.moduleName.startsWith(`${name}/`)).map(row => ({ entryId: row.entryId, enabled: row.enabled, phase: row.fiberPhase ?? 'unknown' }))
75
+ }
76
+ } finally {
77
+ await again.dispose()
78
+ }
79
+ const out = process.env['ACRYL_LIVE_COMMUNITY_REPORT']
80
+ if (out !== undefined) writeFileSync(out, `${JSON.stringify(report, null, 2)}\n`)
81
+ expect(report).toHaveLength(PLUGINS.length)
82
+ }, 900_000)
83
+ })
@@ -0,0 +1,35 @@
1
+ import Module from 'node:module'
2
+ import { afterEach, describe, expect, it } from 'vitest'
3
+ import { installProfilePackageResolver } from '../src/module-resolution.ts'
4
+ import { ModuleHooksUnavailableError, registerModuleHooks } from '../src/module-hooks.ts'
5
+ import { installRuntimeInterception } from '../src/profile-resolution/resolver.ts'
6
+
7
+ const nodeModule = Module as { registerHooks?: unknown }
8
+ const original = nodeModule.registerHooks
9
+
10
+ describe('a runtime without module.registerHooks', () => {
11
+ afterEach(() => {
12
+ nodeModule.registerHooks = original
13
+ })
14
+
15
+ it('registers hooks through the public API when it exists', () => {
16
+ const hooks = registerModuleHooks({ resolve: (specifier, context, next) => next(specifier, context) })
17
+ hooks.deregister()
18
+ })
19
+
20
+ it('fails profile package routing with a message that names the runtime', () => {
21
+ delete nodeModule.registerHooks
22
+ const message = /^DSH provider unavailable on Node \d+\.\d+\.\d+: profile packages load through module\.registerHooks/
23
+ expect(() => registerModuleHooks({})).toThrow(ModuleHooksUnavailableError)
24
+ expect(() => installRuntimeInterception({ entries: [], profileDir: '/profile' } as never)).toThrow(message)
25
+ const resolveFilename = (Module as unknown as { _resolveFilename: unknown })._resolveFilename
26
+ expect(() => installProfilePackageResolver('file:///profile/package.json', {
27
+ installEntryUrl: 'file:///install/main.js',
28
+ installPackageUrl: 'file:///install/package.json',
29
+ loaderEntryUrl: 'file:///install/node_modules/loader/index.js',
30
+ binName: 'acryl',
31
+ })).toThrow(message)
32
+ // Nothing was patched on the way to the failure.
33
+ expect((Module as unknown as { _resolveFilename: unknown })._resolveFilename).toBe(resolveFilename)
34
+ })
35
+ })
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Real behavior coverage for the Cordis Loader package-overlay resolution
3
+ * hook, ported verbatim (mocks and all) from acryl-desktop's own original
4
+ * module-resolution.spec.ts - the actual hook logic moved here when
5
+ * acryl-desktop's module-resolution.ts became a thin wrapper supplying its
6
+ * own anchors to this package's shared installProfilePackageResolver().
7
+ * Desktop's own test now only checks that its wrapper passes the right
8
+ * anchors through; this suite is the real, deep coverage of the hook itself.
9
+ */
10
+ import { resolve } from 'node:path'
11
+ import { pathToFileURL } from 'node:url'
12
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
13
+
14
+ const harness = vi.hoisted(() => {
15
+ const cjsOriginal = vi.fn((
16
+ request: string,
17
+ _parent?: { filename?: string } | null,
18
+ _isMain?: boolean,
19
+ _options?: unknown,
20
+ ) => `ordinary:${request}`)
21
+ return {
22
+ resolve: undefined as undefined | ((
23
+ specifier: string,
24
+ context: { parentURL?: string },
25
+ nextResolve: (specifier: string, context: { parentURL?: string }) => unknown,
26
+ ) => unknown),
27
+ deregister: vi.fn(),
28
+ sources: new Map<string, 'install' | 'profile'>(),
29
+ overlay: vi.fn((packageName: string) => {
30
+ const source = harness.sources.get(packageName) ?? 'profile'
31
+ return {
32
+ packageName,
33
+ selected: {
34
+ source,
35
+ manifestPath: `/${source}/${packageName}/package.json`,
36
+ },
37
+ }
38
+ }),
39
+ cjsOriginal,
40
+ cjsModule: { _resolveFilename: cjsOriginal },
41
+ }
42
+ })
43
+
44
+ vi.mock('node:module', () => {
45
+ const registerHooks = vi.fn((definition: { resolve: typeof harness.resolve }) => {
46
+ harness.resolve = definition.resolve
47
+ return { deregister: harness.deregister }
48
+ })
49
+ // The runtime reads registerHooks from the default export (src/module-hooks.ts).
50
+ Object.assign(harness.cjsModule, { registerHooks })
51
+ // Node's builtins never reach the overlay; the two the tests ask for are enough.
52
+ const isBuiltin = (specifier: string) => ['fs', 'path'].includes(specifier.replace(/^node:/u, ''))
53
+ return { default: harness.cjsModule, registerHooks, isBuiltin }
54
+ })
55
+
56
+ vi.mock('../src/package-overlay.ts', () => ({
57
+ findOverlayPackage: harness.overlay,
58
+ packageNameFromSpecifier(specifier: string): string | undefined {
59
+ if (specifier.length === 0 || specifier.startsWith('.') || specifier.startsWith('/')
60
+ || specifier.startsWith('#') || URL.canParse(specifier)) return undefined
61
+ const parts = specifier.split('/')
62
+ return specifier.startsWith('@') ? `${parts[0]}/${parts[1]}` : parts[0]
63
+ },
64
+ resolveOverlayPackage: harness.overlay,
65
+ }))
66
+
67
+ const { installProfilePackageResolver } = await import('../src/module-resolution.ts')
68
+
69
+ const loaderEntryUrl = import.meta.resolve('@deepseek-ai/cordis-plugin-loader')
70
+ // Built for the host, like the Profile paths below: a file URL without a drive letter is not a path on Windows.
71
+ const installManifest = resolve('/Applications/DSH.app/Contents/Resources/app.asar/package.json')
72
+ const installPackageUrl = pathToFileURL(installManifest).href
73
+ const installEntryUrl = pathToFileURL(resolve(installManifest, '..', 'lib', 'index.js')).href
74
+
75
+ function anchors(): Parameters<typeof installProfilePackageResolver>[1] {
76
+ return { binName: 'test-app', installPackageUrl, installEntryUrl, loaderEntryUrl }
77
+ }
78
+
79
+ function missing(specifier: string, parentURL?: string): Error {
80
+ return Object.assign(
81
+ new Error(`Cannot find package '${specifier}' imported from ${parentURL ?? 'unknown'}`),
82
+ { code: 'ERR_MODULE_NOT_FOUND' },
83
+ )
84
+ }
85
+
86
+ describe('installProfilePackageResolver', () => {
87
+ beforeEach(() => {
88
+ harness.resolve = undefined
89
+ harness.deregister.mockClear()
90
+ harness.overlay.mockClear()
91
+ harness.sources.clear()
92
+ harness.cjsOriginal.mockClear()
93
+ harness.cjsModule._resolveFilename = harness.cjsOriginal
94
+ })
95
+
96
+ it('uses the overlay-selected side for every Loader package and subpath', () => {
97
+ const profileBaseUrl = 'file:///C:/Users/test/profile/package.json'
98
+ harness.sources.set('@deepseek-ai/dsh-web-app', 'install')
99
+ harness.sources.set('test-app', 'profile')
100
+ installProfilePackageResolver(profileBaseUrl, anchors())
101
+ const nextResolve = vi.fn((specifier: string, context: { parentURL?: string }) => ({ specifier, context }))
102
+
103
+ const installed = harness.resolve?.(
104
+ '@deepseek-ai/dsh-web-app',
105
+ { parentURL: loaderEntryUrl },
106
+ nextResolve,
107
+ ) as { context: { parentURL?: string } }
108
+ expect(installed.context.parentURL).not.toBe(profileBaseUrl)
109
+ expect(installed.context.parentURL).toBe(installEntryUrl)
110
+
111
+ expect(harness.resolve?.(
112
+ 'test-app/profile',
113
+ { parentURL: loaderEntryUrl },
114
+ nextResolve,
115
+ )).toEqual({
116
+ specifier: 'test-app/profile',
117
+ context: { parentURL: profileBaseUrl },
118
+ })
119
+ expect(harness.overlay).toHaveBeenCalledWith('@deepseek-ai/dsh-web-app', expect.any(Object))
120
+ expect(harness.overlay).toHaveBeenCalledWith('test-app', expect.any(Object))
121
+ })
122
+
123
+ it('keeps non-package Loader specifiers on ordinary Node resolution', () => {
124
+ installProfilePackageResolver('file:///C:/Users/test/profile/package.json', anchors())
125
+ const nextResolve = vi.fn((specifier: string, context: { parentURL?: string }) => ({ specifier, context }))
126
+
127
+ expect(harness.resolve?.('./relative.js', { parentURL: loaderEntryUrl }, nextResolve)).toEqual({
128
+ specifier: './relative.js',
129
+ context: { parentURL: loaderEntryUrl },
130
+ })
131
+ expect(harness.resolve?.('cordis:include', { parentURL: loaderEntryUrl }, nextResolve)).toEqual({
132
+ specifier: 'cordis:include',
133
+ context: { parentURL: loaderEntryUrl },
134
+ })
135
+ expect(harness.overlay).not.toHaveBeenCalled()
136
+ })
137
+
138
+ it('keeps package-local dependencies and Profile fallback across linked relative modules', () => {
139
+ const profileBaseUrl = 'file:///C:/Users/test/profile/package.json'
140
+ const linkedPluginUrl = 'file:///D:/workspace/plugins/dsh-linked/lib/index.js'
141
+ const linkedFeatureUrl = 'file:///D:/workspace/plugins/dsh-linked/lib/feature.js'
142
+ const localDependencyUrl = 'file:///D:/workspace/plugins/dsh-linked/node_modules/local-dependency/index.js'
143
+ const profilePeerUrl = 'file:///C:/Users/test/profile/node_modules/profile-peer/index.js'
144
+ installProfilePackageResolver(profileBaseUrl, anchors())
145
+ const nextResolve = vi.fn((specifier: string, context: { parentURL?: string }) => {
146
+ if (specifier === 'dsh-linked' && context.parentURL === profileBaseUrl) return { url: linkedPluginUrl }
147
+ if (specifier === './feature.js' && context.parentURL === linkedPluginUrl) return { url: linkedFeatureUrl }
148
+ if (specifier === 'local-dependency' && context.parentURL === linkedFeatureUrl) return { url: localDependencyUrl }
149
+ if (specifier === 'profile-peer' && context.parentURL === profileBaseUrl) return { url: profilePeerUrl }
150
+ throw missing(specifier, context.parentURL)
151
+ })
152
+
153
+ expect(harness.resolve?.('dsh-linked', { parentURL: loaderEntryUrl }, nextResolve)).toEqual({ url: linkedPluginUrl })
154
+ expect(harness.resolve?.('./feature.js', { parentURL: linkedPluginUrl }, nextResolve)).toEqual({ url: linkedFeatureUrl })
155
+ expect(harness.resolve?.('local-dependency', { parentURL: linkedFeatureUrl }, nextResolve)).toEqual({ url: localDependencyUrl })
156
+ expect(harness.resolve?.('profile-peer', { parentURL: localDependencyUrl }, nextResolve)).toEqual({ url: profilePeerUrl })
157
+ })
158
+
159
+ it('allows an installation-selected package to use a missing dependency from the Profile overlay', () => {
160
+ const profileBaseUrl = 'file:///C:/Users/test/profile/package.json'
161
+ const installedPluginUrl = installEntryUrl
162
+ const profilePeerUrl = 'file:///C:/Users/test/profile/node_modules/profile-peer/index.js'
163
+ harness.sources.set('plugin', 'install')
164
+ installProfilePackageResolver(profileBaseUrl, anchors())
165
+ const nextResolve = vi.fn((specifier: string, context: { parentURL?: string }) => {
166
+ if (specifier === 'plugin' && context.parentURL === installEntryUrl) return { url: installedPluginUrl }
167
+ if (specifier === 'profile-peer' && context.parentURL === installedPluginUrl) return { url: profilePeerUrl }
168
+ throw missing(specifier, context.parentURL)
169
+ })
170
+
171
+ expect(harness.resolve?.('plugin', { parentURL: loaderEntryUrl }, nextResolve)).toEqual({ url: installedPluginUrl })
172
+ expect(harness.resolve?.('profile-peer', { parentURL: installedPluginUrl }, nextResolve)).toEqual({ url: profilePeerUrl })
173
+ })
174
+
175
+ it('does not expose Profile dependencies to unrelated modules', () => {
176
+ const profileBaseUrl = 'file:///C:/Users/test/profile/package.json'
177
+ installProfilePackageResolver(profileBaseUrl, anchors())
178
+ const nextResolve = vi.fn((specifier: string, context: { parentURL?: string }) => {
179
+ if (context.parentURL === profileBaseUrl) return { url: 'file:///C:/Users/test/profile/node_modules/zod/index.js' }
180
+ throw missing(specifier, context.parentURL)
181
+ })
182
+
183
+ expect(() => harness.resolve?.(
184
+ 'zod',
185
+ { parentURL: 'file:///unrelated/module.js' },
186
+ nextResolve,
187
+ )).toThrow('Cannot find package')
188
+ expect(nextResolve).toHaveBeenCalledTimes(1)
189
+ })
190
+
191
+ it('uses the same overlay for CommonJS package manifests resolved from the Profile anchor', () => {
192
+ // A file URL needs a drive letter on Windows, so the profile manifest path is built for the host.
193
+ const profileManifest = resolve('/tmp/dsh-profile/package.json')
194
+ const profileBaseUrl = pathToFileURL(profileManifest).href
195
+ harness.sources.set('@deepseek-ai/dsh-client-modules', 'install')
196
+ const dispose = installProfilePackageResolver(profileBaseUrl, anchors())
197
+ const resolveFilename = harness.cjsModule._resolveFilename
198
+
199
+ expect(resolveFilename(
200
+ '@deepseek-ai/dsh-client-modules/package.json',
201
+ { filename: profileManifest },
202
+ false,
203
+ )).toBe('/install/@deepseek-ai/dsh-client-modules/package.json')
204
+ expect(resolveFilename(
205
+ '@deepseek-ai/dsh-client-modules/package.json',
206
+ { filename: resolve('/tmp/another-profile/package.json') },
207
+ false,
208
+ )).toBe('ordinary:@deepseek-ai/dsh-client-modules/package.json')
209
+ expect(resolveFilename(
210
+ '@deepseek-ai/dsh-client-modules/client.js',
211
+ { filename: profileManifest },
212
+ false,
213
+ )).toBe('ordinary:@deepseek-ai/dsh-client-modules/client.js')
214
+
215
+ dispose()
216
+ expect(harness.cjsModule._resolveFilename).toBe(harness.cjsOriginal)
217
+ })
218
+
219
+ it('resolves a bare plugin import from the Profile anchor on the overlay-selected side', () => {
220
+ // dsh-app-boot's root Include resolves every Loader row with the Profile manifest as the CommonJS parent; a fresh Profile
221
+ // holds no node_modules, so an installation-selected package must be looked up from the installation's own manifest.
222
+ const profileManifest = resolve('/tmp/dsh-profile/package.json')
223
+ harness.sources.set('@deepseek-ai/cordis-plugin-timer', 'install')
224
+ harness.sources.set('profile-plugin', 'profile')
225
+ const dispose = installProfilePackageResolver(pathToFileURL(profileManifest).href, anchors())
226
+ const resolveFilename = harness.cjsModule._resolveFilename
227
+ const options = { conditions: new Set(['node', 'import']) }
228
+
229
+ resolveFilename('@deepseek-ai/cordis-plugin-timer', { filename: profileManifest }, false, options)
230
+ const installCall = harness.cjsOriginal.mock.calls.at(-1)!
231
+ expect(installCall[1]).toMatchObject({ filename: expect.stringContaining('app.asar') })
232
+ expect((installCall[1] as { paths: string[] }).paths[0]).toBe(resolve(installManifest, '..', 'node_modules'))
233
+ expect(installCall[3]).toBe(options)
234
+
235
+ resolveFilename('profile-plugin/lib/index.js', { filename: profileManifest }, false, options)
236
+ expect(harness.cjsOriginal.mock.calls.at(-1)![1]).toEqual({ filename: profileManifest })
237
+
238
+ // The file the Loader imports next keeps the Profile fallback for a dependency it cannot find beside itself.
239
+ const pluginFile = resolve('/install/node_modules/third-party/index.js')
240
+ harness.cjsOriginal.mockImplementationOnce(() => pluginFile)
241
+ harness.sources.set('third-party', 'install')
242
+ expect(resolveFilename('third-party', { filename: profileManifest }, false, options)).toBe(pluginFile)
243
+ const nextResolve = vi.fn((specifier: string, context: { parentURL?: string }) => {
244
+ if (context.parentURL !== pathToFileURL(profileManifest).href) throw missing(specifier, context.parentURL)
245
+ return { url: `file:///profile/node_modules/${specifier}/index.js` }
246
+ })
247
+ expect(harness.resolve?.('third-party-dependency', { parentURL: pathToFileURL(pluginFile).href }, nextResolve))
248
+ .toEqual({ url: 'file:///profile/node_modules/third-party-dependency/index.js' })
249
+
250
+ // Node builtins, relative requests and parents outside the Profile never consult the overlay.
251
+ harness.overlay.mockClear()
252
+ resolveFilename('fs', { filename: profileManifest }, false)
253
+ resolveFilename('./local.js', { filename: profileManifest }, false)
254
+ resolveFilename('@deepseek-ai/cordis-plugin-timer', { filename: resolve('/elsewhere/index.js') }, false)
255
+ expect(harness.overlay).not.toHaveBeenCalled()
256
+ dispose()
257
+ })
258
+
259
+ it('deregisters hooks only once even if the disposer is reused', () => {
260
+ const dispose = installProfilePackageResolver('file:///C:/Users/test/profile/package.json', anchors())
261
+ dispose()
262
+ dispose()
263
+ expect(harness.deregister).toHaveBeenCalledTimes(1)
264
+ })
265
+ })
@@ -0,0 +1,61 @@
1
+ /** An import of a framework package from before it moved to acrylblends (spec 049 slice 17) fails with what replaces it, while the profile resolution is mounted. */
2
+
3
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
4
+ import { tmpdir } from 'node:os'
5
+ import { join } from 'node:path'
6
+ import { pathToFileURL } from 'node:url'
7
+ import { Context } from '@deepseek-ai/cordis'
8
+ import type { RuntimeResolution } from '@deepseek-ai/dsh-app-boot'
9
+ import { afterEach, describe, expect, it } from 'vitest'
10
+ import { MOVED_FRAMEWORK_IMPORTS } from '../src/profile-resolution/moved-framework.ts'
11
+ import { ProfilePluginPackages } from '../src/profile-resolution/service.ts'
12
+
13
+ const roots: string[] = []
14
+ afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }) })
15
+
16
+ /** An app plugin with no framework package of its own beside it, and a profile resolution that knows none. */
17
+ function setup(): { plugin: string, resolution: RuntimeResolution } {
18
+ const root = mkdtempSync(join(tmpdir(), 'acryl-moved-framework-'))
19
+ roots.push(root)
20
+ const profileDir = join(root, 'profiles', 'web')
21
+ mkdirSync(profileDir, { recursive: true })
22
+ const plugin = join(root, 'plugins', 'todo', 'index.js')
23
+ mkdirSync(join(root, 'plugins', 'todo'), { recursive: true })
24
+ writeFileSync(plugin, '')
25
+ return { plugin, resolution: { profilesDir: join(root, 'profiles'), profileDir, localPackageNames: [], linkedRoots: [], entries: [] } }
26
+ }
27
+
28
+ function failure(load: () => unknown): string {
29
+ try {
30
+ load()
31
+ } catch (error) {
32
+ return error instanceof Error ? error.message : String(error)
33
+ }
34
+ throw new Error('expected the import to fail')
35
+ }
36
+
37
+ describe('an import of a moved framework package', () => {
38
+ it('fails naming its acrylblends replacement while the resolution is mounted, and plainly once it is gone', async () => {
39
+ const { plugin, resolution } = setup()
40
+ // ESM resolution, as a plugin's import runs; unlike require it ignores NODE_PATH, which pnpm's script shims point at the workspace.
41
+ const resolve = (specifier: string): string => import.meta.resolve(specifier, pathToFileURL(plugin).href)
42
+ const ctx = new Context()
43
+ await ctx.plugin(ProfilePluginPackages, { resolution })
44
+
45
+ const router = failure(() => resolve('@acryldev/router'))
46
+ expect(router).toContain("'@acryldev/router' is part of acrylblends")
47
+ expect(router).toContain("'@acryldev/blends/cordis/router'")
48
+ expect(failure(() => resolve('@acryldev/router/middleware'))).toContain("'@acryldev/blends/body-limit'")
49
+ // Any other missing package fails as before.
50
+ expect(failure(() => resolve('not-a-framework-package'))).not.toContain('acrylblends')
51
+
52
+ await ctx.fiber.dispose()
53
+ expect(failure(() => resolve('@acryldev/router'))).not.toContain('acrylblends')
54
+ })
55
+
56
+ it('names a replacement for every package that moved', () => {
57
+ for (const old of ['@acryldev/router', '@acryldev/router-http', '@acryldev/state', '@acryldev/inspect', '@acryldev/node-server', '@acryldev/door', '@acryldev/db', '@acryldev/db-sqlite', '@acryldev/kv', '@acryldev/kv-json', '@acryldev/kv-db']) {
58
+ expect(MOVED_FRAMEWORK_IMPORTS[old], old).toMatch(/'@acryldev\/blends(\/[a-z/-]+)?'/u)
59
+ }
60
+ })
61
+ })
@@ -0,0 +1,132 @@
1
+ /** `acryl new` and the app manifest (spec 036): one file format for the Blends tooling and the runtime, and one app shape for every app. */
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+ import { parse } from 'yaml'
6
+ import { afterEach, describe, expect, it } from 'vitest'
7
+ import {
8
+ BLANK_BLUEPRINT,
9
+ IDE_BLUEPRINT,
10
+ InvalidBlueprintError,
11
+ NewAppError,
12
+ appManifest,
13
+ blueprintFromEnvironment,
14
+ blueprintFromManifest,
15
+ brandIdentity,
16
+ composeBlueprintRows,
17
+ planNewApp,
18
+ writeNewApp,
19
+ } from '../src/index.ts'
20
+ import { RENAMED_MODULES } from '../src/blueprint/index.ts'
21
+
22
+ const dirs: string[] = []
23
+ afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { force: true, recursive: true }) })
24
+ const temp = (): string => { const dir = mkdtempSync(join(tmpdir(), 'acryl-new-')); dirs.push(dir); return dir }
25
+ const launcher = '/framework/scripts/blank.mjs'
26
+
27
+ describe('acryl new', () => {
28
+ it('plans the conventional app shape', () => {
29
+ const app = planNewApp('/apps/stage-sound', { title: 'Stage Sound', brand: { accent: '#e8590c' }, launcher })
30
+ expect(Object.keys(app.files).sort()).toEqual(['.github/workflows/app.yml', '.gitignore', 'AGENTS.md', 'README.md', 'bin/acryl', 'blend.yaml', 'plugins/README.md'])
31
+ expect(app.files['.github/workflows/app.yml']).toMatch(/blends-validate blend\.yaml[\s\S]*acryl-secret-check \./u)
32
+ const manifest = parse(app.files['blend.yaml']!) as Record<string, any>
33
+ expect(manifest).toMatchObject({ apiVersion: 'blends.acryl.dev/v1alpha1', kind: 'Blend', metadata: { id: 'app.stage-sound', name: 'Stage Sound' }, spec: { lineage: { blueprint: 'acryl.blank' } } })
34
+ expect(manifest.spec.rows[0]).toMatchObject({ id: 'brand', name: '@acryldev/brand', config: { name: 'Stage Sound', accent: '#e8590c' } })
35
+ expect(app.files['bin/acryl']).toContain(JSON.stringify(launcher))
36
+ expect(app.files['AGENTS.md']).toContain('plugins/<name>/')
37
+ // Runtime data is never committed with the app: the engine home, the run lock, and the plugin store (spec 044).
38
+ expect(app.files['.gitignore']!.split('\n')).toEqual(expect.arrayContaining(['.dsh/', 'instance.json', 'plugins/.store/']))
39
+ })
40
+
41
+ it('the manifest it writes boots back into the same Blueprint with the brand', () => {
42
+ const app = planNewApp('/apps/ledger', { title: 'Ledger', launcher })
43
+ const blueprint = blueprintFromManifest(parse(app.files['blend.yaml']!))
44
+ expect(blueprint.id).toBe('app.ledger')
45
+ expect(blueprint.rows).toEqual(BLANK_BLUEPRINT.rows)
46
+ expect(blueprint.capabilities).toEqual(BLANK_BLUEPRINT.capabilities)
47
+ expect(blueprint.brand).toEqual({ kind: 'custom', identity: expect.objectContaining({ name: 'Ledger' }) })
48
+ })
49
+
50
+ it('refuses a folder name that cannot be an app, an unknown blueprint, and a non-empty folder', () => {
51
+ expect(() => planNewApp('/apps/My App', { launcher })).toThrow(NewAppError)
52
+ expect(() => planNewApp('/apps/ok', { blueprint: 'acryl.nope', launcher })).toThrow(/unknown blueprint/)
53
+ const dir = join(temp(), 'busy'); mkdirSync(dir); writeFileSync(join(dir, 'mine.txt'), 'x')
54
+ expect(() => writeNewApp(planNewApp(dir, { launcher }))).toThrow(/not empty/)
55
+ expect(readFileSync(join(dir, 'mine.txt'), 'utf8')).toBe('x')
56
+ })
57
+
58
+ it('the app is the user\'s product: its own git repository, no ACRYL name in what its users see, license left to them', () => {
59
+ const dir = join(temp(), 'ledger-pro')
60
+ const { git } = writeNewApp(planNewApp(dir, { title: 'Ledger Pro', launcher }))
61
+ expect(git).toBe('initialized')
62
+ expect(existsSync(join(dir, '.git'))).toBe(true)
63
+ expect(readFileSync(join(dir, '.gitignore'), 'utf8')).toContain('.dsh/')
64
+ expect(existsSync(join(dir, 'LICENSE'))).toBe(false) // the user chooses
65
+ const blueprint = blueprintFromEnvironment({ ACRYL_BLUEPRINT: join(dir, 'blend.yaml') })
66
+ expect(blueprint.brand.kind === 'custom' && blueprint.brand.identity.name).toBe('Ledger Pro')
67
+ expect(readFileSync(join(dir, 'blend.yaml'), 'utf8')).not.toMatch(/name: ACRYL|ACRYL Blends app/)
68
+ expect(readFileSync(join(dir, 'README.md'), 'utf8')).toMatch(/license it however you want, including closed source/)
69
+ })
70
+
71
+ it('writes a runnable app whose definition the runtime selects from the environment', () => {
72
+ const dir = join(temp(), 'video-cut')
73
+ expect(writeNewApp(planNewApp(dir, { title: 'Video Cut', launcher }), { git: false }).git).toBe('skipped')
74
+ // The launcher is a POSIX shell script; Windows has no executable bit to check.
75
+ if (process.platform !== 'win32') expect(statSync(join(dir, 'bin', 'acryl')).mode & 0o100).toBeTruthy()
76
+ expect(existsSync(join(dir, 'plugins'))).toBe(true)
77
+ const blueprint = blueprintFromEnvironment({ ACRYL_BLUEPRINT: join(dir, 'blend.yaml') })
78
+ expect(blueprint.id).toBe('app.video-cut')
79
+ 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'])
80
+ })
81
+ })
82
+
83
+ describe('acryl new --from', () => {
84
+ it('a derived app takes its own identity, and the source\'s name does not stay in the manifest header', () => {
85
+ const source = planNewApp('/apps/app-a', { title: 'Round Trip A', launcher })
86
+ const derived = planNewApp('/apps/app-b', { title: 'Round Trip B', from: { manifestText: source.files['blend.yaml']! }, launcher })
87
+ expect(derived.files['blend.yaml']!.split('\n', 1)[0]).toMatch(/^# Round Trip B: what this app is/u)
88
+ expect(derived.files['blend.yaml']).not.toContain('Round Trip A')
89
+ expect(parse(derived.files['blend.yaml']!)).toMatchObject({ metadata: { id: 'app.app-b', name: 'Round Trip B' } })
90
+ })
91
+ })
92
+
93
+ describe('reading a Blends manifest', () => {
94
+ const blend = (rows: unknown[]) => ({ apiVersion: 'blends.acryl.dev/v1alpha1', kind: 'Blend', metadata: { id: 'app.x', name: 'X', version: '0.1.0' }, spec: { runtime: 'cordis', lineage: { blueprint: 'acryl.blank', blueprintVersion: '0.1.0' }, rows } })
95
+
96
+ it('an ACRYL row turns a capability on, a disabled one turns it off, and any other row is an app plugin left to plugins/', () => {
97
+ const blueprint = blueprintFromManifest(blend([
98
+ { id: 'community-market', name: '@acryldev/cordis-plugin-market' },
99
+ { id: '@acryl/ui', name: '@acryldev/ui', disabled: true },
100
+ { id: 'organizer', name: 'acryl-organizer' },
101
+ ]))
102
+ expect(blueprint.rows).toContain('community-market')
103
+ expect(blueprint.rows).not.toContain('ui-library')
104
+ expect(blueprint.rows).not.toContain('organizer' as never)
105
+ })
106
+
107
+ it('an app written before the context plugin was renamed still names it (spec 044 step 1b)', () => {
108
+ expect(blueprintFromManifest(blend([{ id: 'extension-context', name: 'acryl-extension-context', disabled: true }])).rows).not.toContain('plugin-context')
109
+ expect(blueprintFromManifest(blend([{ id: 'extension-context', name: 'acryl-extension-context' }])).rows).toContain('plugin-context')
110
+ })
111
+
112
+ it('an app written before the framework moved to acrylblends still names its packages, read as the acrylblends modules (spec 049 slice 17)', () => {
113
+ expect(blueprintFromManifest(blend([{ id: 'acryl-inspect', name: '@acryldev/inspect', disabled: true }])).rows).not.toContain('framework-kit')
114
+ expect(blueprintFromManifest(blend([{ id: 'acryl-inspect', name: '@acryldev/inspect' }])).rows).toContain('framework-kit')
115
+ // Written today: each row under its module, never an old name. A row written before the module moved (spec 051 T038) is not read as today's
116
+ // module: day 0 reinstalls old apps instead of aliasing their names.
117
+ const written = appManifest({ id: 'app.y', name: 'Y', blueprint: BLANK_BLUEPRINT, brand: brandIdentity({ name: 'Y' }) }) as { spec: { rows: { id: string, name: string }[] } }
118
+ expect(written.spec.rows).toContainEqual({ id: 'acrylblends/cordis/inspect', name: '@acryldev/blends/cordis/inspect' })
119
+ expect(written.spec.rows.map(row => row.name).filter(name => Object.hasOwn(RENAMED_MODULES, name))).toEqual([])
120
+ })
121
+
122
+ it('a Blueprint manifest names a known Blueprint; the IDE can be selected that way', () => {
123
+ expect(blueprintFromManifest({ apiVersion: 'blends.acryl.dev/v1alpha1', kind: 'Blueprint', metadata: { id: 'acryl.ide', name: 'ACRYL', version: '0.1.0' }, spec: { runtime: 'cordis' } }).rows).toEqual(IDE_BLUEPRINT.rows)
124
+ })
125
+
126
+ it('rejects what it cannot boot', () => {
127
+ expect(() => blueprintFromManifest({ ...blend([]), kind: 'Thing' })).toThrow(/kind/)
128
+ expect(() => blueprintFromManifest({ ...blend([]), metadata: { id: 'noDots' } })).toThrow(/metadata.id/)
129
+ expect(() => blueprintFromManifest({ ...blend([]), spec: { runtime: 'cordis', lineage: { blueprint: 'acryl.nope' } } })).toThrow(InvalidBlueprintError)
130
+ expect(() => blueprintFromManifest({ ...blend([{ id: 'x' }]) })).toThrow(/spec\.rows\[0\]\.name/)
131
+ })
132
+ })