@ekanos/cli 0.16.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -4
- package/dist/commands/add.d.ts +2 -0
- package/dist/commands/add.js +118 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/audiences.d.ts +31 -0
- package/dist/commands/audiences.js +239 -0
- package/dist/commands/audiences.js.map +1 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +41 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +43 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/codegen.d.ts +2 -0
- package/dist/commands/codegen.js +49 -0
- package/dist/commands/codegen.js.map +1 -0
- package/dist/commands/contract.d.ts +52 -0
- package/dist/commands/contract.js +300 -0
- package/dist/commands/contract.js.map +1 -0
- package/dist/commands/dev.d.ts +7 -0
- package/dist/commands/dev.js +186 -12
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/index-experience.d.ts +31 -0
- package/dist/commands/index-experience.js +21 -0
- package/dist/commands/index-experience.js.map +1 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +12 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/new.d.ts +2 -0
- package/dist/commands/new.js +39 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/publish.d.ts +59 -0
- package/dist/commands/publish.js +118 -65
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/scope-notice.d.ts +6 -0
- package/dist/commands/scope-notice.js +15 -0
- package/dist/commands/scope-notice.js.map +1 -1
- package/dist/commands/sources.js +2 -0
- package/dist/commands/sources.js.map +1 -1
- package/dist/commands/sync.d.ts +2 -0
- package/dist/commands/sync.js +150 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/commands/teams-audience.d.ts +12 -0
- package/dist/commands/teams-audience.js +144 -0
- package/dist/commands/teams-audience.js.map +1 -0
- package/dist/commands/teams-scope.js +4 -0
- package/dist/commands/teams-scope.js.map +1 -1
- package/dist/commands/teams.d.ts +1 -1
- package/dist/commands/teams.js +6 -1
- package/dist/commands/teams.js.map +1 -1
- package/dist/compatibility.d.ts +10 -1
- package/dist/compatibility.js +10 -1
- package/dist/compatibility.js.map +1 -1
- package/dist/dev-experience.d.ts +125 -0
- package/dist/dev-experience.js +128 -0
- package/dist/dev-experience.js.map +1 -0
- package/dist/experience/boundary.d.ts +12 -0
- package/dist/experience/boundary.js +260 -0
- package/dist/experience/boundary.js.map +1 -0
- package/dist/experience/build.d.ts +16 -0
- package/dist/experience/build.js +90 -0
- package/dist/experience/build.js.map +1 -0
- package/dist/experience/checks.d.ts +29 -0
- package/dist/experience/checks.js +133 -0
- package/dist/experience/checks.js.map +1 -0
- package/dist/experience/contract-sources.d.ts +36 -0
- package/dist/experience/contract-sources.js +111 -0
- package/dist/experience/contract-sources.js.map +1 -0
- package/dist/experience/definition-checks.d.ts +26 -0
- package/dist/experience/definition-checks.js +201 -0
- package/dist/experience/definition-checks.js.map +1 -0
- package/dist/experience/definition-shape.d.ts +60 -0
- package/dist/experience/definition-shape.js +2 -0
- package/dist/experience/definition-shape.js.map +1 -0
- package/dist/experience/init.d.ts +10 -0
- package/dist/experience/init.js +64 -0
- package/dist/experience/init.js.map +1 -0
- package/dist/experience/integrations-codegen.d.ts +17 -0
- package/dist/experience/integrations-codegen.js +51 -0
- package/dist/experience/integrations-codegen.js.map +1 -0
- package/dist/experience/json-schema-to-ts.d.ts +1 -0
- package/dist/experience/json-schema-to-ts.js +90 -0
- package/dist/experience/json-schema-to-ts.js.map +1 -0
- package/dist/experience/load-experience.d.ts +23 -0
- package/dist/experience/load-experience.js +115 -0
- package/dist/experience/load-experience.js.map +1 -0
- package/dist/experience/overrides.d.ts +8 -0
- package/dist/experience/overrides.js +21 -0
- package/dist/experience/overrides.js.map +1 -0
- package/dist/experience/pin-integration.d.ts +8 -0
- package/dist/experience/pin-integration.js +17 -0
- package/dist/experience/pin-integration.js.map +1 -0
- package/dist/experience/pin-ops.d.ts +12 -0
- package/dist/experience/pin-ops.js +36 -0
- package/dist/experience/pin-ops.js.map +1 -0
- package/dist/experience/pins.d.ts +35 -0
- package/dist/experience/pins.js +91 -0
- package/dist/experience/pins.js.map +1 -0
- package/dist/experience/project.d.ts +52 -0
- package/dist/experience/project.js +149 -0
- package/dist/experience/project.js.map +1 -0
- package/dist/experience/publish.d.ts +51 -0
- package/dist/experience/publish.js +144 -0
- package/dist/experience/publish.js.map +1 -0
- package/dist/experience/regenerate.d.ts +10 -0
- package/dist/experience/regenerate.js +33 -0
- package/dist/experience/regenerate.js.map +1 -0
- package/dist/experience/report.d.ts +9 -0
- package/dist/experience/report.js +23 -0
- package/dist/experience/report.js.map +1 -0
- package/dist/harness-scaffold.d.ts +52 -18
- package/dist/harness-scaffold.js +189 -9
- package/dist/harness-scaffold.js.map +1 -1
- package/dist/index.js +139 -7
- package/dist/index.js.map +1 -1
- package/dist/pack.js +5 -0
- package/dist/pack.js.map +1 -1
- package/dist/project-checks.d.ts +19 -0
- package/dist/project-checks.js +93 -0
- package/dist/project-checks.js.map +1 -1
- package/dist/project.d.ts +14 -0
- package/dist/project.js +10 -0
- package/dist/project.js.map +1 -1
- package/dist/repo/publish.d.ts +42 -0
- package/dist/repo/publish.js +225 -0
- package/dist/repo/publish.js.map +1 -0
- package/dist/repo/scaffold.d.ts +30 -0
- package/dist/repo/scaffold.js +165 -0
- package/dist/repo/scaffold.js.map +1 -0
- package/dist/teams-api.d.ts +37 -1
- package/dist/teams-api.js +62 -1
- package/dist/teams-api.js.map +1 -1
- package/dist/validate-findings.js +3 -1
- package/dist/validate-findings.js.map +1 -1
- package/package.json +2 -2
- package/templates/ekanos.json.tmpl +1 -0
- package/templates/experience/AGENTS.md.tmpl +22 -0
- package/templates/experience/ekanos.json.tmpl +7 -0
- package/templates/experience/ekanos.lock.json.tmpl +4 -0
- package/templates/experience/eslint.config.mjs.tmpl +25 -0
- package/templates/experience/gitignore.tmpl +17 -0
- package/templates/experience/package.json.tmpl +41 -0
- package/templates/experience/src/.ekanos/integrations.d.ts.tmpl +3 -0
- package/templates/experience/src/experience.ts.tmpl +30 -0
- package/templates/experience/src/widgets/hello-widget.tsx.tmpl +40 -0
- package/templates/experience/tsconfig.json.tmpl +20 -0
- package/templates/harness/app/%5F%5Fekanos/api/[...path]/route.ts.tmpl +9 -0
- package/templates/harness/app/[slug]/activation/page.tsx.tmpl +1 -1
- package/templates/harness/app/[slug]/page.tsx.tmpl +1 -1
- package/templates/harness/app/[slug]/tile/page.tsx.tmpl +1 -1
- package/templates/harness/app/[slug]/triggers/page.tsx.tmpl +1 -1
- package/templates/harness/app/[slug]/widgets/[widgetId]/page.tsx.tmpl +1 -1
- package/templates/harness/app/[slug]/widgets/page.tsx.tmpl +1 -1
- package/templates/harness/app/experience/layout.tsx.tmpl +17 -0
- package/templates/harness/app/experience/page.tsx.tmpl +1 -0
- package/templates/harness/app/experience/pages/[id]/page.tsx.tmpl +1 -0
- package/templates/harness/app/experience/review-queue/page.tsx.tmpl +1 -0
- package/templates/harness/app/experience/runs/page.tsx.tmpl +1 -0
- package/templates/harness/app/experience/widgets/[id]/page.tsx.tmpl +1 -0
- package/templates/harness/app/experience/widgets/page.tsx.tmpl +1 -0
- package/templates/harness/app/experience/workflows/[id]/page.tsx.tmpl +1 -0
- package/templates/harness/app/experience/workflows/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/connect/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/events/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/health/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/operations/[kind]/[name]/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/operations/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/preview/activation/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/preview/layout.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/preview/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/preview/tile/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/preview/triggers/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/preview/widgets/[widgetId]/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/preview/widgets/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/[slug]/runs/page.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/layout.tsx.tmpl +1 -0
- package/templates/harness/app/integrations/page.tsx.tmpl +1 -0
- package/templates/harness/app/page.experience.tsx.tmpl +5 -0
- package/templates/harness/repo/app/%5F%5Fekanos/api/[...path]/route.ts.tmpl +11 -0
- package/templates/harness/repo/app/(repo)/connections/page.tsx.tmpl +1 -0
- package/templates/harness/repo/app/(repo)/layout.tsx.tmpl +1 -0
- package/templates/harness/repo/app/(repo)/page.tsx.tmpl +1 -0
- package/templates/harness/repo/app/experiences/[name]/connect/page.tsx.tmpl +1 -0
- package/templates/harness/repo/app/experiences/[name]/layout.tsx.tmpl +9 -0
- package/templates/harness/repo/app/experiences/page.tsx.tmpl +5 -0
- package/templates/harness/repo/app/harness-shell.tsx.tmpl +9 -0
- package/templates/harness/repo/app/integrations/[slug]/layout.tsx.tmpl +1 -0
- package/templates/harness/repo/app/integrations/page.tsx.tmpl +5 -0
- package/templates/harness/repo/app/repo-experiences.ts.tmpl +5 -0
- package/templates/harness/styles/globals.css.tmpl +15 -1
- package/templates/package.json.tmpl +5 -4
|
@@ -15,25 +15,30 @@ export declare const BUILD_CACHE_DIR = ".next";
|
|
|
15
15
|
export declare const VERSION_MARKER = ".ekanos-version";
|
|
16
16
|
/** The partner-owned registry, at the PROJECT ROOT. Never regenerated. */
|
|
17
17
|
export declare const HARNESS_CONFIG_FILENAME = "harness.config.ts";
|
|
18
|
+
/** An experience's generated, empty registry, inside the shell. */
|
|
19
|
+
export declare const SHELL_REGISTRY_FILENAME = "harness.config.ts";
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* export map alone — which is the test of whether the package boundary is in
|
|
22
|
-
* the right place. If a shell file ever needs a judgment call, the boundary
|
|
23
|
-
* has moved, not the template.
|
|
24
|
-
*
|
|
25
|
-
* `app/api/integrations/[slug]/[...path]/route.ts` is the shell's one SERVER
|
|
26
|
-
* route: it injects the registry into `@ekanos/harness/api`, which serves the
|
|
27
|
-
* live-mode OAuth loop, storage bridge and trigger route over a server-held
|
|
28
|
-
* context. It is the third registry injection point, beside the two pages.
|
|
29
|
-
*
|
|
30
|
-
* `app/harness-shell.tsx` exists because a `HarnessIntegration` holds React
|
|
31
|
-
* component references and MCP `run` functions. Next cannot serialize those
|
|
32
|
-
* across a server→client boundary, so the `'use client'` mark has to sit ABOVE
|
|
33
|
-
* the point where the registry is injected — hence a client shell of its own
|
|
34
|
-
* rather than a client `RootLayout` called from a server layout. Keeping
|
|
35
|
-
* `app/page.tsx` a server component is what lets `/` prerender static.
|
|
21
|
+
* The Integration console (`/integrations/**`). Generated for every project:
|
|
22
|
+
* an integration repo's home, and half of an experience repo's.
|
|
36
23
|
*/
|
|
24
|
+
export declare const CONSOLE_SHELL_FILES: readonly {
|
|
25
|
+
template: string;
|
|
26
|
+
dest: string;
|
|
27
|
+
}[];
|
|
28
|
+
/**
|
|
29
|
+
* The Experience view (`/experience/**`), generated only for `kind:
|
|
30
|
+
* "experience"`. Its layout imports the experience entry (the widgets and
|
|
31
|
+
* pages are React components that only the project's own module holds), and
|
|
32
|
+
* the home page redirects here.
|
|
33
|
+
*/
|
|
34
|
+
export declare const EXPERIENCE_SHELL_FILES: readonly {
|
|
35
|
+
template: string;
|
|
36
|
+
dest: string;
|
|
37
|
+
}[];
|
|
38
|
+
export declare const REPO_SHELL_ONLY_FILES: readonly {
|
|
39
|
+
template: string;
|
|
40
|
+
dest: string;
|
|
41
|
+
}[];
|
|
37
42
|
export declare const SHELL_FILES: readonly {
|
|
38
43
|
template: string;
|
|
39
44
|
dest: string;
|
|
@@ -140,6 +145,25 @@ export interface ScaffoldShellArgs {
|
|
|
140
145
|
force: boolean;
|
|
141
146
|
/** Extra Tailwind @source globs from ekanos.json, already validated. */
|
|
142
147
|
sourceGlobs?: readonly string[];
|
|
148
|
+
/**
|
|
149
|
+
* Set for a `kind: "experience"` project: its entry (project-relative). The
|
|
150
|
+
* Experience view is generated, and mounts the entry's widgets and pages.
|
|
151
|
+
*/
|
|
152
|
+
experienceEntry?: string;
|
|
153
|
+
/** Set when `projectDir` is a repo root: the packages the shell serves. */
|
|
154
|
+
repo?: RepoShellPackages;
|
|
155
|
+
}
|
|
156
|
+
/** Package directories and entries are relative to the repo root. */
|
|
157
|
+
export interface RepoShellPackages {
|
|
158
|
+
integrations: readonly {
|
|
159
|
+
name: string;
|
|
160
|
+
dir: string;
|
|
161
|
+
}[];
|
|
162
|
+
experiences: readonly {
|
|
163
|
+
name: string;
|
|
164
|
+
dir: string;
|
|
165
|
+
entry: string;
|
|
166
|
+
}[];
|
|
143
167
|
}
|
|
144
168
|
export interface ScaffoldShellResult extends WrittenFiles {
|
|
145
169
|
harnessDir: string;
|
|
@@ -164,6 +188,16 @@ export interface ScaffoldShellResult extends WrittenFiles {
|
|
|
164
188
|
* source, and nothing else.
|
|
165
189
|
*/
|
|
166
190
|
export declare function scaffoldShell(args: ScaffoldShellArgs): ScaffoldShellResult;
|
|
191
|
+
/** The shell file set: the legacy shell + console, plus the Experience view for an experience. */
|
|
192
|
+
export declare function shellFilesFor(experience: boolean): readonly {
|
|
193
|
+
template: string;
|
|
194
|
+
dest: string;
|
|
195
|
+
}[];
|
|
196
|
+
/** The repo shell file set. */
|
|
197
|
+
export declare function repoShellFiles(): readonly {
|
|
198
|
+
template: string;
|
|
199
|
+
dest: string;
|
|
200
|
+
}[];
|
|
167
201
|
/**
|
|
168
202
|
* Establish that `.ekanos/harness` is a tree WE generated before writing a
|
|
169
203
|
* single byte into it, and return the version marker it carried.
|
|
@@ -201,7 +235,7 @@ export declare function entryImportSpecifier(entry: string): string;
|
|
|
201
235
|
* unsandboxed anyway — but "the templates cannot be injected into" is a claim
|
|
202
236
|
* we make, and it should be true.
|
|
203
237
|
*/
|
|
204
|
-
export declare function entryImportLiteral(entry: string): string;
|
|
238
|
+
export declare function entryImportLiteral(entry: string, prefix?: string): string;
|
|
205
239
|
export interface BootstrapConfigResult {
|
|
206
240
|
/** True only when this run created the file. */
|
|
207
241
|
bootstrapped: boolean;
|
package/dist/harness-scaffold.js
CHANGED
|
@@ -21,6 +21,16 @@ export const BUILD_CACHE_DIR = '.next';
|
|
|
21
21
|
export const VERSION_MARKER = '.ekanos-version';
|
|
22
22
|
/** The partner-owned registry, at the PROJECT ROOT. Never regenerated. */
|
|
23
23
|
export const HARNESS_CONFIG_FILENAME = 'harness.config.ts';
|
|
24
|
+
/** An experience's generated, empty registry, inside the shell. */
|
|
25
|
+
export const SHELL_REGISTRY_FILENAME = 'harness.config.ts';
|
|
26
|
+
/**
|
|
27
|
+
* Re-point a shell file's import of the project-root registry at the shell's
|
|
28
|
+
* own: the shell sits two directories below the root, so the specifier loses
|
|
29
|
+
* exactly two `../`.
|
|
30
|
+
*/
|
|
31
|
+
function pointAtShellRegistry(source) {
|
|
32
|
+
return source.replace(/((?:\.\.\/){3,})harness\.config(['"])/g, (_match, ups, quote) => `${ups.slice(6)}harness.config${quote}`);
|
|
33
|
+
}
|
|
24
34
|
/**
|
|
25
35
|
* Every file in the generated shell: bundled template → path inside
|
|
26
36
|
* `.ekanos/harness/`. The ten route files are mechanically derivable from the
|
|
@@ -40,6 +50,89 @@ export const HARNESS_CONFIG_FILENAME = 'harness.config.ts';
|
|
|
40
50
|
* rather than a client `RootLayout` called from a server layout. Keeping
|
|
41
51
|
* `app/page.tsx` a server component is what lets `/` prerender static.
|
|
42
52
|
*/
|
|
53
|
+
const consolePage = (dest) => ({
|
|
54
|
+
template: `harness/app/${dest}.tmpl`,
|
|
55
|
+
dest: `app/${dest}`,
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* The Integration console (`/integrations/**`). Generated for every project:
|
|
59
|
+
* an integration repo's home, and half of an experience repo's.
|
|
60
|
+
*/
|
|
61
|
+
export const CONSOLE_SHELL_FILES = [
|
|
62
|
+
'integrations/layout.tsx',
|
|
63
|
+
'integrations/page.tsx',
|
|
64
|
+
'integrations/[slug]/page.tsx',
|
|
65
|
+
'integrations/[slug]/connect/page.tsx',
|
|
66
|
+
'integrations/[slug]/operations/page.tsx',
|
|
67
|
+
'integrations/[slug]/operations/[kind]/[name]/page.tsx',
|
|
68
|
+
'integrations/[slug]/events/page.tsx',
|
|
69
|
+
'integrations/[slug]/health/page.tsx',
|
|
70
|
+
'integrations/[slug]/runs/page.tsx',
|
|
71
|
+
'integrations/[slug]/preview/layout.tsx',
|
|
72
|
+
'integrations/[slug]/preview/page.tsx',
|
|
73
|
+
'integrations/[slug]/preview/widgets/page.tsx',
|
|
74
|
+
'integrations/[slug]/preview/widgets/[widgetId]/page.tsx',
|
|
75
|
+
'integrations/[slug]/preview/tile/page.tsx',
|
|
76
|
+
'integrations/[slug]/preview/activation/page.tsx',
|
|
77
|
+
'integrations/[slug]/preview/triggers/page.tsx',
|
|
78
|
+
].map(consolePage);
|
|
79
|
+
/**
|
|
80
|
+
* The Experience view (`/experience/**`), generated only for `kind:
|
|
81
|
+
* "experience"`. Its layout imports the experience entry (the widgets and
|
|
82
|
+
* pages are React components that only the project's own module holds), and
|
|
83
|
+
* the home page redirects here.
|
|
84
|
+
*/
|
|
85
|
+
export const EXPERIENCE_SHELL_FILES = [
|
|
86
|
+
...[
|
|
87
|
+
'experience/layout.tsx',
|
|
88
|
+
'experience/page.tsx',
|
|
89
|
+
'experience/widgets/page.tsx',
|
|
90
|
+
'experience/widgets/[id]/page.tsx',
|
|
91
|
+
'experience/pages/[id]/page.tsx',
|
|
92
|
+
'experience/workflows/page.tsx',
|
|
93
|
+
'experience/workflows/[id]/page.tsx',
|
|
94
|
+
'experience/review-queue/page.tsx',
|
|
95
|
+
'experience/runs/page.tsx',
|
|
96
|
+
].map(consolePage),
|
|
97
|
+
{ template: 'harness/app/page.experience.tsx.tmpl', dest: 'app/page.tsx' },
|
|
98
|
+
];
|
|
99
|
+
/**
|
|
100
|
+
* The repo shell (`ekanos dev` at a repo root). It is the ordinary shell with
|
|
101
|
+
* the single-project home, console layout and API route swapped for the repo's:
|
|
102
|
+
* the repo home and Connections under a `(repo)` route group, each integration
|
|
103
|
+
* package's console under `/integrations/<name>`, each experience package's
|
|
104
|
+
* view under `/experiences/<name>`, and one API route that answers the repo
|
|
105
|
+
* overview and forwards to a package's own harness API.
|
|
106
|
+
*/
|
|
107
|
+
const REPO_REPLACED_DESTS = new Set([
|
|
108
|
+
'app/page.tsx',
|
|
109
|
+
'app/harness-shell.tsx',
|
|
110
|
+
'app/integrations/layout.tsx',
|
|
111
|
+
'app/integrations/page.tsx',
|
|
112
|
+
'app/%5F%5Fekanos/api/[...path]/route.ts',
|
|
113
|
+
]);
|
|
114
|
+
const repoTemplate = (dest) => ({
|
|
115
|
+
template: `harness/repo/app/${dest}.tmpl`,
|
|
116
|
+
dest: `app/${dest}`,
|
|
117
|
+
});
|
|
118
|
+
export const REPO_SHELL_ONLY_FILES = [
|
|
119
|
+
'harness-shell.tsx',
|
|
120
|
+
'(repo)/layout.tsx',
|
|
121
|
+
'(repo)/page.tsx',
|
|
122
|
+
'(repo)/connections/page.tsx',
|
|
123
|
+
'integrations/page.tsx',
|
|
124
|
+
'integrations/[slug]/layout.tsx',
|
|
125
|
+
'experiences/page.tsx',
|
|
126
|
+
'experiences/[name]/layout.tsx',
|
|
127
|
+
'experiences/[name]/connect/page.tsx',
|
|
128
|
+
'%5F%5Fekanos/api/[...path]/route.ts',
|
|
129
|
+
].map(repoTemplate);
|
|
130
|
+
/** The Experience view's pages, re-homed under `/experiences/[name]`. */
|
|
131
|
+
const REPO_EXPERIENCE_PAGES = EXPERIENCE_SHELL_FILES.filter((file) => file.dest.startsWith('app/experience/') &&
|
|
132
|
+
file.dest !== 'app/experience/layout.tsx').map((file) => ({
|
|
133
|
+
template: file.template,
|
|
134
|
+
dest: file.dest.replace('app/experience/', 'app/experiences/[name]/'),
|
|
135
|
+
}));
|
|
43
136
|
export const SHELL_FILES = [
|
|
44
137
|
{ template: 'harness/app/layout.tsx.tmpl', dest: 'app/layout.tsx' },
|
|
45
138
|
{
|
|
@@ -79,6 +172,11 @@ export const SHELL_FILES = [
|
|
|
79
172
|
template: 'harness/app/api/integrations/[slug]/[...path]/route.ts.tmpl',
|
|
80
173
|
dest: 'app/api/integrations/[slug]/[...path]/route.ts',
|
|
81
174
|
},
|
|
175
|
+
{
|
|
176
|
+
template: 'harness/app/%5F%5Fekanos/api/[...path]/route.ts.tmpl',
|
|
177
|
+
dest: 'app/%5F%5Fekanos/api/[...path]/route.ts',
|
|
178
|
+
},
|
|
179
|
+
...CONSOLE_SHELL_FILES,
|
|
82
180
|
{ template: 'harness/next.config.mjs.tmpl', dest: 'next.config.mjs' },
|
|
83
181
|
{ template: 'harness/postcss.config.mjs.tmpl', dest: 'postcss.config.mjs' },
|
|
84
182
|
{ template: 'harness/tsconfig.json.tmpl', dest: 'tsconfig.json' },
|
|
@@ -228,10 +326,13 @@ export function scaffoldShell(args) {
|
|
|
228
326
|
const markerState = readShellMarkerState(harnessDir);
|
|
229
327
|
const previousMarker = markerState.kind === 'ok' ? markerState.marker : null;
|
|
230
328
|
const previousVersion = (_a = previousMarker === null || previousMarker === void 0 ? void 0 : previousMarker.harness) !== null && _a !== void 0 ? _a : null;
|
|
329
|
+
const shellFiles = args.repo
|
|
330
|
+
? repoShellFiles()
|
|
331
|
+
: shellFilesFor(args.experienceEntry !== undefined);
|
|
231
332
|
const marker = {
|
|
232
333
|
harness: args.harnessVersion,
|
|
233
334
|
cli: cliVersion(),
|
|
234
|
-
templates: templatesFingerprint(
|
|
335
|
+
templates: templatesFingerprint(shellFiles.map((f) => f.template)),
|
|
235
336
|
};
|
|
236
337
|
// A shell is current only if EVERYTHING that produced it is unchanged.
|
|
237
338
|
// Checking the harness version alone certified shells generated by an older
|
|
@@ -264,12 +365,19 @@ export function scaffoldShell(args) {
|
|
|
264
365
|
fs.rmSync(buildCacheDir, { recursive: true, force: true });
|
|
265
366
|
}
|
|
266
367
|
const files = { created: [], updated: [], unchanged: [] };
|
|
267
|
-
const vars = {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
for (const { template, dest } of
|
|
272
|
-
|
|
368
|
+
const vars = Object.assign({ SLUG: args.slug, SOURCE_GLOBS: renderSourceGlobs((_c = args.sourceGlobs) !== null && _c !== void 0 ? _c : []), EXPERIENCE_ENTRY: args.experienceEntry === undefined
|
|
369
|
+
? '""'
|
|
370
|
+
: entryImportLiteral(args.experienceEntry, SHELL_APP_TO_PROJECT) }, (args.repo ? renderRepoExperiences(args.repo) : {}));
|
|
371
|
+
const experience = args.experienceEntry !== undefined || args.repo !== undefined;
|
|
372
|
+
for (const { template, dest } of shellFiles) {
|
|
373
|
+
const rendered = readTemplate(template, vars);
|
|
374
|
+
writeIfChanged(args.projectDir, path.join(harnessDir, dest), experience ? pointAtShellRegistry(rendered) : rendered, files, dest, args.force);
|
|
375
|
+
}
|
|
376
|
+
// An experience registers no integration, so it has no project-root
|
|
377
|
+
// `harness.config.ts` to own: the shell carries its own (generated, empty)
|
|
378
|
+
// registry and the files above import that instead.
|
|
379
|
+
if (experience) {
|
|
380
|
+
writeIfChanged(args.projectDir, path.join(harnessDir, SHELL_REGISTRY_FILENAME), args.repo ? renderRepoRegistry(args.repo) : renderHarnessConfig([]), files, SHELL_REGISTRY_FILENAME, args.force);
|
|
273
381
|
}
|
|
274
382
|
writeIfChanged(args.projectDir, path.join(harnessDir, VERSION_MARKER), serializeMarker(marker), files, VERSION_MARKER, args.force);
|
|
275
383
|
return Object.assign(Object.assign({}, files), { harnessDir,
|
|
@@ -279,6 +387,49 @@ export function scaffoldShell(args) {
|
|
|
279
387
|
staleReasons,
|
|
280
388
|
buildCacheCleared });
|
|
281
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* `app/repo-experiences.ts`: the experience entries, imported statically (they
|
|
392
|
+
* hold React components, which cannot cross the server/client boundary).
|
|
393
|
+
*/
|
|
394
|
+
function renderRepoExperiences(repo) {
|
|
395
|
+
const imports = [];
|
|
396
|
+
const entries = [];
|
|
397
|
+
repo.experiences.forEach((experience, index) => {
|
|
398
|
+
const ident = `experience${index}`;
|
|
399
|
+
imports.push(`import ${ident} from ${entryImportLiteral(`${experience.dir}/${experience.entry}`,
|
|
400
|
+
// app/repo-experiences.ts sits one level above app/experience/.
|
|
401
|
+
'../../../')};`);
|
|
402
|
+
entries.push(` ${JSON.stringify(experience.name)}: { widgets: ${ident}.widgets ?? [], pages: ${ident}.pages ?? [] },\n`);
|
|
403
|
+
});
|
|
404
|
+
return {
|
|
405
|
+
EXPERIENCE_IMPORTS: imports.join('\n'),
|
|
406
|
+
EXPERIENCE_ENTRIES: entries.join(''),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* The shell's registry at a repo root: every integration package's own
|
|
411
|
+
* `harness.config.ts`, concatenated, so each integration's widgets, tile and
|
|
412
|
+
* activation surfaces and its OAuth routes keep working.
|
|
413
|
+
*/
|
|
414
|
+
function renderRepoRegistry(repo) {
|
|
415
|
+
const imports = repo.integrations.map((integration, index) => {
|
|
416
|
+
const specifier = JSON.stringify(`${SHELL_TO_PROJECT_REGISTRY}${integration.dir}/${path.basename(HARNESS_CONFIG_FILENAME, '.ts')}`);
|
|
417
|
+
return `import { harnessIntegrations as integration${index} } from ${specifier};`;
|
|
418
|
+
});
|
|
419
|
+
const spread = repo.integrations
|
|
420
|
+
.map((_, index) => `...integration${index}`)
|
|
421
|
+
.join(', ');
|
|
422
|
+
return [
|
|
423
|
+
'// Generated by `ekanos dev` at a repo root. Each integration package owns its own harness.config.ts.',
|
|
424
|
+
"import { defineHarnessConfig } from '@ekanos/harness/config';",
|
|
425
|
+
...imports,
|
|
426
|
+
'',
|
|
427
|
+
`export const harnessIntegrations = defineHarnessConfig([${spread}]);`,
|
|
428
|
+
'',
|
|
429
|
+
].join('\n');
|
|
430
|
+
}
|
|
431
|
+
/** From `.ekanos/harness/` (where the shell registry sits) up to the repo root. */
|
|
432
|
+
const SHELL_TO_PROJECT_REGISTRY = '../../';
|
|
282
433
|
/**
|
|
283
434
|
* Turn validated `sourceGlobs` into the `@source` lines the generated
|
|
284
435
|
* stylesheet carries, each relative to the shell's `styles/` directory.
|
|
@@ -294,6 +445,33 @@ function renderSourceGlobs(globs) {
|
|
|
294
445
|
const lines = globs.map((glob) => `@source '${SHELL_TO_PROJECT}${glob}';`);
|
|
295
446
|
return `\n/* From "sourceGlobs" in ekanos.json. */\n${lines.join('\n')}\n`;
|
|
296
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* From `.ekanos/harness/app/experience/` back up to the project root: the
|
|
450
|
+
* experience layout imports the entry by this relative path.
|
|
451
|
+
*/
|
|
452
|
+
const SHELL_APP_TO_PROJECT = '../../../../';
|
|
453
|
+
/** The shell file set: the legacy shell + console, plus the Experience view for an experience. */
|
|
454
|
+
export function shellFilesFor(experience) {
|
|
455
|
+
if (!experience)
|
|
456
|
+
return SHELL_FILES;
|
|
457
|
+
const replaced = new Set(EXPERIENCE_SHELL_FILES.map((f) => f.dest));
|
|
458
|
+
return [
|
|
459
|
+
...SHELL_FILES.filter((f) => !replaced.has(f.dest)),
|
|
460
|
+
...EXPERIENCE_SHELL_FILES,
|
|
461
|
+
];
|
|
462
|
+
}
|
|
463
|
+
/** The repo shell file set. */
|
|
464
|
+
export function repoShellFiles() {
|
|
465
|
+
return [
|
|
466
|
+
...SHELL_FILES.filter((f) => !REPO_REPLACED_DESTS.has(f.dest)),
|
|
467
|
+
...REPO_SHELL_ONLY_FILES,
|
|
468
|
+
...REPO_EXPERIENCE_PAGES,
|
|
469
|
+
{
|
|
470
|
+
template: 'harness/repo/app/repo-experiences.ts.tmpl',
|
|
471
|
+
dest: 'app/repo-experiences.ts',
|
|
472
|
+
},
|
|
473
|
+
];
|
|
474
|
+
}
|
|
297
475
|
/** From `.ekanos/harness/styles/` back up to the project root. */
|
|
298
476
|
const SHELL_TO_PROJECT = '../../../';
|
|
299
477
|
/**
|
|
@@ -371,7 +549,7 @@ export function entryImportSpecifier(entry) {
|
|
|
371
549
|
* unsandboxed anyway — but "the templates cannot be injected into" is a claim
|
|
372
550
|
* we make, and it should be true.
|
|
373
551
|
*/
|
|
374
|
-
export function entryImportLiteral(entry) {
|
|
552
|
+
export function entryImportLiteral(entry, prefix = './') {
|
|
375
553
|
const specifier = entryImportSpecifier(entry);
|
|
376
554
|
// eslint-disable-next-line no-control-regex
|
|
377
555
|
if (/["'`\\\n\r\u0000-\u001f]/.test(specifier)) {
|
|
@@ -379,7 +557,7 @@ export function entryImportLiteral(entry) {
|
|
|
379
557
|
`an import specifier: ${JSON.stringify(specifier)}.`, 'Rename the file so its path has no quotes, backslashes or control ' +
|
|
380
558
|
'characters, then update "entry" in ekanos.json to match.');
|
|
381
559
|
}
|
|
382
|
-
return JSON.stringify(
|
|
560
|
+
return JSON.stringify(`${prefix}${specifier}`);
|
|
383
561
|
}
|
|
384
562
|
/**
|
|
385
563
|
* Write a starter `harness.config.ts` at the project root — ONCE.
|
|
@@ -390,6 +568,8 @@ export function entryImportLiteral(entry) {
|
|
|
390
568
|
* shell, never this.
|
|
391
569
|
*/
|
|
392
570
|
export function bootstrapHarnessConfig(projectDir, integrations) {
|
|
571
|
+
// An experience project has no integration of its own to register: the
|
|
572
|
+
// harness serves its integrations from `ekanos.json` through /__ekanos/api.
|
|
393
573
|
const configPath = path.join(projectDir, HARNESS_CONFIG_FILENAME);
|
|
394
574
|
const kind = classifyPath(configPath);
|
|
395
575
|
// A symlink here — including a dangling one, which `existsSync` reports as
|
|
@@ -1 +1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E,CAAC;SAC1B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { cliVersion, templatesFingerprint } from './compatibility';\nimport { invalidStateError, preconditionError } from './errors';\nimport {\n appendFileNoFollow,\n classifyPath,\n readFileNoFollow,\n writeFileNoFollow,\n} from './safe-fs';\nimport { readTemplate } from './templates';\n\n/** The dependency that owns every line of harness behaviour. */\nexport const HARNESS_PACKAGE = '@ekanos/harness';\n\n/** Where the generated shell lives, relative to the project root. */\nexport const HARNESS_DIR = path.join('.ekanos', 'harness');\n\n/** The single `.gitignore` line that covers the whole generated tree. */\nexport const GITIGNORE_ENTRY = '.ekanos/';\n\n/**\n * The staleness marker, inside the generated tree so deleting the tree also\n * deletes the marker. Holds the `@ekanos/harness` version that generated the\n * shell — a version bump means the shell may be wired against an older export\n * surface, so it is regenerated.\n */\n/** Next's dev/build cache inside the generated shell. */\nexport const BUILD_CACHE_DIR = '.next';\n\nexport const VERSION_MARKER = '.ekanos-version';\n\n/** The partner-owned registry, at the PROJECT ROOT. Never regenerated. */\nexport const HARNESS_CONFIG_FILENAME = 'harness.config.ts';\n\n/**\n * Every file in the generated shell: bundled template → path inside\n * `.ekanos/harness/`. The ten route files are mechanically derivable from the\n * export map alone — which is the test of whether the package boundary is in\n * the right place. If a shell file ever needs a judgment call, the boundary\n * has moved, not the template.\n *\n * `app/api/integrations/[slug]/[...path]/route.ts` is the shell's one SERVER\n * route: it injects the registry into `@ekanos/harness/api`, which serves the\n * live-mode OAuth loop, storage bridge and trigger route over a server-held\n * context. It is the third registry injection point, beside the two pages.\n *\n * `app/harness-shell.tsx` exists because a `HarnessIntegration` holds React\n * component references and MCP `run` functions. Next cannot serialize those\n * across a server→client boundary, so the `'use client'` mark has to sit ABOVE\n * the point where the registry is injected — hence a client shell of its own\n * rather than a client `RootLayout` called from a server layout. Keeping\n * `app/page.tsx` a server component is what lets `/` prerender static.\n */\nexport const SHELL_FILES: readonly { template: string; dest: string }[] = [\n { template: 'harness/app/layout.tsx.tmpl', dest: 'app/layout.tsx' },\n {\n template: 'harness/app/harness-shell.tsx.tmpl',\n dest: 'app/harness-shell.tsx',\n },\n { template: 'harness/app/page.tsx.tmpl', dest: 'app/page.tsx' },\n {\n template: 'harness/app/[slug]/layout.tsx.tmpl',\n dest: 'app/[slug]/layout.tsx',\n },\n {\n template: 'harness/app/[slug]/page.tsx.tmpl',\n dest: 'app/[slug]/page.tsx',\n },\n {\n template: 'harness/app/[slug]/widgets/page.tsx.tmpl',\n dest: 'app/[slug]/widgets/page.tsx',\n },\n {\n template: 'harness/app/[slug]/widgets/[widgetId]/page.tsx.tmpl',\n dest: 'app/[slug]/widgets/[widgetId]/page.tsx',\n },\n {\n template: 'harness/app/[slug]/tile/page.tsx.tmpl',\n dest: 'app/[slug]/tile/page.tsx',\n },\n {\n template: 'harness/app/[slug]/activation/page.tsx.tmpl',\n dest: 'app/[slug]/activation/page.tsx',\n },\n {\n template: 'harness/app/[slug]/triggers/page.tsx.tmpl',\n dest: 'app/[slug]/triggers/page.tsx',\n },\n {\n template: 'harness/app/api/integrations/[slug]/[...path]/route.ts.tmpl',\n dest: 'app/api/integrations/[slug]/[...path]/route.ts',\n },\n { template: 'harness/next.config.mjs.tmpl', dest: 'next.config.mjs' },\n { template: 'harness/postcss.config.mjs.tmpl', dest: 'postcss.config.mjs' },\n { template: 'harness/tsconfig.json.tmpl', dest: 'tsconfig.json' },\n { template: 'harness/styles/globals.css.tmpl', dest: 'styles/globals.css' },\n { template: 'harness/package.json.tmpl', dest: 'package.json' },\n {\n template: 'harness/types/team-accounts.d.ts.tmpl',\n dest: 'types/team-accounts.d.ts',\n },\n];\n\n/**\n * Packages the shell needs to resolve upward out of the partner's own\n * `node_modules`. The shell declares no dependencies of its own by design, so\n * a missing one shows up as an opaque Next resolution error at dev-server\n * start; checking here turns that into one precondition with one fix.\n */\nexport const REQUIRED_DEPENDENCIES = [\n HARNESS_PACKAGE,\n 'next',\n 'react',\n 'react-dom',\n 'tailwindcss',\n '@tailwindcss/postcss',\n] as const;\n\nexport interface WrittenFiles {\n created: string[];\n updated: string[];\n unchanged: string[];\n}\n\n/**\n * Read an installed package's `package.json` out of a project's TOP-LEVEL\n * `node_modules`. Resolved by direct path join rather than `require.resolve`\n * on purpose, for two independent reasons:\n *\n * - The CLI runs from its own install and must read the version of the copy\n * in THE CALLER'S project, not one hoisted next to itself.\n * - Several of the packages this reads (`@ekanos/integration-schema`\n * included) declare an `exports` map with no `./package.json` subpath, so\n * `require.resolve('<pkg>/package.json')` throws\n * `ERR_PACKAGE_PATH_NOT_EXPORTED` under Node's ESM resolver. A plain file\n * read is not subject to the export map at all.\n *\n * Shared by every \"what does this project have installed?\" check in the\n * CLI — `readInstalledHarness` below, the schema-skew gate, and `upgrade`'s\n * current-toolchain report — so there is exactly one implementation of \"read\n * a package's on-disk version\", not a subtly different one per call site.\n */\nexport interface InstalledPackage {\n version: string;\n /** The raw package.json, for callers that need more than the version. */\n manifest: unknown;\n}\n\nexport function readInstalledPackageManifest(\n projectDir: string,\n packageName: string,\n): InstalledPackage | null {\n const manifestPath = path.join(\n projectDir,\n 'node_modules',\n ...packageName.split('/'),\n 'package.json',\n );\n if (!fs.existsSync(manifestPath)) return null;\n\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n const version =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { version?: unknown }).version\n : undefined;\n if (typeof version !== 'string' || version.length === 0) return null;\n return { version, manifest: parsed };\n } catch (error) {\n throw preconditionError(\n `${packageName}'s package.json in node_modules is unreadable: ${\n error instanceof Error ? error.message : String(error)\n }`,\n `Reinstall dependencies in ${projectDir} so ${packageName} resolves.`,\n );\n }\n}\n\n/** Read the installed `@ekanos/harness` version out of the partner's project. */\nexport type InstalledHarness = InstalledPackage;\n\nexport function readInstalledHarness(\n projectDir: string,\n): InstalledHarness | null {\n return readInstalledPackageManifest(projectDir, HARNESS_PACKAGE);\n}\n\n/** Just the installed version, for callers that need nothing else. */\nexport function readInstalledHarnessVersion(projectDir: string): string | null {\n return readInstalledHarness(projectDir)?.version ?? null;\n}\n\n/** Which of `REQUIRED_DEPENDENCIES` are not installed in the project root. */\nexport function missingDependencies(projectDir: string): string[] {\n return REQUIRED_DEPENDENCIES.filter(\n (name) =>\n !fs.existsSync(\n path.join(projectDir, 'node_modules', name, 'package.json'),\n ),\n );\n}\n\n/**\n * What generated an existing shell.\n *\n * All three fields matter, and recording only `harness` was a real hole: the\n * templates ship with the CLI, so a shell can be stale because the CLI changed\n * while the harness did not. `templates` is the authoritative one — it is a\n * hash of the template sources, so it moves whenever what we generate moves,\n * including for a CLI build that never shipped a version bump.\n */\nexport interface ShellMarker {\n harness: string;\n /** null for a legacy bare-version marker written before this was recorded. */\n cli: string | null;\n templates: string | null;\n}\n\n/**\n * Three outcomes, not two, because \"no marker\" and \"unreadable marker\" call\n * for opposite responses.\n *\n * A marker's PRESENCE is itself evidence the tree is ours — a squatter does\n * not write `.ekanos-version` — and the likeliest cause of an unreadable one\n * is our own interrupted write. Everything under `.ekanos/harness/` is\n * CLI-owned, gitignored and reproducible from the templates, so regenerating\n * destroys nothing: there is no value at risk to justify charging a partner a\n * confusing `--force` to recover from our own bad write.\n *\n * An ABSENT marker over a non-empty tree is the opposite: nothing says the\n * files are ours, so we refuse. That is the L1 rule and it stays.\n */\nexport type MarkerState =\n | { kind: 'missing' }\n | { kind: 'corrupt' }\n | { kind: 'ok'; marker: ShellMarker };\n\nexport function readShellMarkerState(harnessDir: string): MarkerState {\n const marker = path.join(harnessDir, VERSION_MARKER);\n if (classifyPath(marker) !== 'file') return { kind: 'missing' };\n\n const raw = (readFileNoFollow(harnessDir, marker) ?? '').trim();\n if (raw.length === 0) return { kind: 'corrupt' };\n\n const parsed = parseMarker(raw);\n return parsed === null ? { kind: 'corrupt' } : { kind: 'ok', marker: parsed };\n}\n\nfunction parseMarker(raw: string): ShellMarker | null {\n // v1 markers were a bare version string. Read them rather than crashing, and\n // report the unknown fields as null so the shell counts as stale and is\n // regenerated once — which is the correct outcome for an upgrade.\n //\n // It must actually LOOK like a version: without this, any garbage that does\n // not happen to start with `{` — a truncated write, a stray word — reads as\n // a legacy marker named after the garbage, and the corrupt-marker path never\n // fires. That is how a truncated `.ekanos-version` was silently reported as\n // \"@ekanos/harness truncat → 0.1.0\" instead of \"unreadable\".\n if (!raw.startsWith('{')) {\n return /^\\d+\\.\\d+/.test(raw)\n ? { harness: raw, cli: null, templates: null }\n : null;\n }\n\n try {\n const parsed: unknown = JSON.parse(raw);\n if (typeof parsed !== 'object' || parsed === null) return null;\n const record = parsed as Record<string, unknown>;\n const harness = record.harness;\n if (typeof harness !== 'string') return null;\n return {\n harness,\n cli: typeof record.cli === 'string' ? record.cli : null,\n templates: typeof record.templates === 'string' ? record.templates : null,\n };\n } catch {\n return null;\n }\n}\n\n/** The parsed marker, or null when it is absent OR unreadable. */\nexport function readShellMarker(harnessDir: string): ShellMarker | null {\n const state = readShellMarkerState(harnessDir);\n return state.kind === 'ok' ? state.marker : null;\n}\n\n/** The `@ekanos/harness` version an existing shell was generated against. */\nexport function readShellVersion(harnessDir: string): string | null {\n return readShellMarker(harnessDir)?.harness ?? null;\n}\n\nfunction serializeMarker(marker: ShellMarker): string {\n return `${JSON.stringify(marker, null, 2)}\\n`;\n}\n\n/**\n * Write a generated file, but ONLY when its bytes would change.\n *\n * This is what makes a re-run cheap and a watcher quiet: an unchanged file is\n * not rewritten, so its mtime does not move and Next's dev server does not\n * rebuild. It also means a hand-edit inside the CLI-owned tree is silently\n * corrected on the next run, which is the intended contract for `.ekanos/`.\n */\nexport function writeIfChanged(\n root: string,\n destPath: string,\n contents: string,\n into: WrittenFiles,\n label: string,\n force: boolean,\n): void {\n // `classifyPath` uses lstat, so a symlink here is reported as a symlink\n // rather than as whatever it points at — including a DANGLING one, which\n // `existsSync` would call absent and a plain write would then materialize\n // outside the project.\n const kind = classifyPath(destPath);\n const exists = kind !== 'missing';\n\n if (\n !force &&\n kind === 'file' &&\n readFileNoFollow(root, destPath) === contents\n ) {\n into.unchanged.push(label);\n return;\n }\n\n writeFileNoFollow(root, destPath, contents);\n (exists ? into.updated : into.created).push(label);\n}\n\nexport interface ScaffoldShellArgs {\n projectDir: string;\n slug: string;\n harnessVersion: string;\n /** Rewrite every file even when its bytes already match. */\n force: boolean;\n /** Extra Tailwind @source globs from ekanos.json, already validated. */\n sourceGlobs?: readonly string[];\n}\n\nexport interface ScaffoldShellResult extends WrittenFiles {\n harnessDir: string;\n /** The version the shell carried before this run — null on a first run. */\n previousVersion: string | null;\n /** What generated the previous shell, or null on a first run. */\n previousMarker: ShellMarker | null;\n /** True when anything that generated the shell has since changed. */\n stale: boolean;\n /** `.next` under the shell was deleted because the shell was stale. */\n buildCacheCleared: boolean;\n /**\n * Which of harness / cli / templates moved. Empty on a first run; this is\n * what lets `dev` say WHY it regenerated rather than just that it did.\n */\n staleReasons: string[];\n}\n\n/**\n * Generate `.ekanos/harness/**` for `harnessVersion`. Every file here is\n * CLI-owned and gitignored, so regeneration needs no permission and asks no\n * question — the partner owns `harness.config.ts` and their integration\n * source, and nothing else.\n */\nexport function scaffoldShell(args: ScaffoldShellArgs): ScaffoldShellResult {\n const harnessDir = path.join(args.projectDir, HARNESS_DIR);\n assertShellDirIsOurs(harnessDir, args.force);\n\n const markerState = readShellMarkerState(harnessDir);\n const previousMarker = markerState.kind === 'ok' ? markerState.marker : null;\n const previousVersion = previousMarker?.harness ?? null;\n const marker: ShellMarker = {\n harness: args.harnessVersion,\n cli: cliVersion(),\n templates: templatesFingerprint(SHELL_FILES.map((f) => f.template)),\n };\n\n // A shell is current only if EVERYTHING that produced it is unchanged.\n // Checking the harness version alone certified shells generated by an older\n // CLI, against templates that had since moved, as up to date.\n const staleReasons: string[] = [];\n if (markerState.kind === 'corrupt') {\n staleReasons.push(\n `${VERSION_MARKER} was unreadable, so the existing shell could not be ` +\n 'certified',\n );\n }\n if (previousMarker !== null) {\n if (previousMarker.harness !== marker.harness) {\n staleReasons.push(\n `@ekanos/harness ${previousMarker.harness} → ${marker.harness}`,\n );\n }\n if (previousMarker.cli !== marker.cli) {\n staleReasons.push(\n `@ekanos/cli ${previousMarker.cli ?? 'unknown'} → ${marker.cli}`,\n );\n }\n if (previousMarker.templates !== marker.templates) {\n staleReasons.push('the shell templates changed');\n }\n }\n const stale = staleReasons.length > 0;\n\n // Next's persistent dev cache was built from the OLD shell and the OLD\n // toolchain. Keeping it across a regeneration served a corrupted Tailwind\n // candidate on the 0.1 → 0.4 jump (every page a build-error overlay until\n // someone deleted the directory by hand). The shell knows it is stale; the\n // cache goes with it.\n const buildCacheDir = path.join(harnessDir, BUILD_CACHE_DIR);\n const buildCacheCleared = stale && fs.existsSync(buildCacheDir);\n if (buildCacheCleared) {\n fs.rmSync(buildCacheDir, { recursive: true, force: true });\n }\n\n const files: WrittenFiles = { created: [], updated: [], unchanged: [] };\n const vars = {\n SLUG: args.slug,\n SOURCE_GLOBS: renderSourceGlobs(args.sourceGlobs ?? []),\n };\n\n for (const { template, dest } of SHELL_FILES) {\n writeIfChanged(\n args.projectDir,\n path.join(harnessDir, dest),\n readTemplate(template, vars),\n files,\n dest,\n args.force,\n );\n }\n\n writeIfChanged(\n args.projectDir,\n path.join(harnessDir, VERSION_MARKER),\n serializeMarker(marker),\n files,\n VERSION_MARKER,\n args.force,\n );\n\n return {\n ...files,\n harnessDir,\n previousVersion,\n previousMarker,\n stale,\n staleReasons,\n buildCacheCleared,\n };\n}\n\n/**\n * Turn validated `sourceGlobs` into the `@source` lines the generated\n * stylesheet carries, each relative to the shell's `styles/` directory.\n *\n * Tailwind never scans what it is not pointed at, and a glob that matches\n * nothing fails silently — so an integration living outside the default\n * layout renders completely unstyled with no error anywhere. That is what\n * `sourceGlobs` is for, and until now it was parsed and thrown away.\n */\nfunction renderSourceGlobs(globs: readonly string[]): string {\n if (globs.length === 0) return '';\n const lines = globs.map((glob) => `@source '${SHELL_TO_PROJECT}${glob}';`);\n return `\\n/* From \"sourceGlobs\" in ekanos.json. */\\n${lines.join('\\n')}\\n`;\n}\n\n/** From `.ekanos/harness/styles/` back up to the project root. */\nconst SHELL_TO_PROJECT = '../../../';\n\n/**\n * Establish that `.ekanos/harness` is a tree WE generated before writing a\n * single byte into it, and return the version marker it carried.\n *\n * Path location alone is not ownership. A directory that exists but carries no\n * `.ekanos-version` was put there by something else — a partner, another tool,\n * a symlink — and clobbering it because it happens to sit at the path we like\n * is the same class of mistake as following a symlink. An empty directory is\n * fine (that is just `mkdir -p` having run), and `--force` is the explicit\n * override.\n *\n * Runs BEFORE `bootstrapHarnessConfig` in `dev`, so a shell that cannot be\n * written leaves the project completely untouched rather than half-scaffolded.\n */\nexport function assertShellDirIsOurs(\n harnessDir: string,\n force: boolean,\n): string | null {\n // `.ekanos` first: through a symlinked `.ekanos`, the lstat below would\n // describe the link's target, and the build-cache `rmSync` would delete\n // outside the project.\n const ekanosDir = path.dirname(harnessDir);\n const parentKind = classifyPath(ekanosDir);\n if (parentKind === 'symlink') {\n throw invalidStateError(\n `${ekanosDir} is a symlink, so \"ekanos dev\" will not write through it.`,\n `Delete the ${ekanosDir} link and re-run \"ekanos dev\" — the shell is ` +\n 'generated, so nothing is lost.',\n );\n }\n if (parentKind !== 'missing' && parentKind !== 'directory') {\n throw invalidStateError(\n `${ekanosDir} exists and is not a directory.`,\n `Move or delete ${ekanosDir}, then re-run \"ekanos dev\".`,\n );\n }\n\n const kind = classifyPath(harnessDir);\n\n if (kind === 'symlink') {\n throw invalidStateError(\n `${harnessDir} is a symlink, so \"ekanos dev\" will not write through it.`,\n `Delete ${harnessDir} and re-run \"ekanos dev\" — the shell is generated, ` +\n 'so nothing is lost.',\n );\n }\n\n if (kind !== 'missing' && kind !== 'directory') {\n throw invalidStateError(\n `${harnessDir} exists and is not a directory.`,\n `Move or delete ${harnessDir}, then re-run \"ekanos dev\".`,\n );\n }\n\n if (kind === 'missing') return null;\n\n const state = readShellMarkerState(harnessDir);\n\n // A marker we wrote, however mangled, still identifies the tree as ours.\n if (state.kind === 'ok') return state.marker.harness;\n if (state.kind === 'corrupt' || force) return null;\n\n if (fs.readdirSync(harnessDir).length === 0) return null;\n\n throw invalidStateError(\n `${harnessDir} already contains files but no ${VERSION_MARKER} marker, ` +\n 'so it was not generated by \"ekanos dev\".',\n `Delete ${harnessDir} if you do not need it, or pass --force to ` +\n 'overwrite it. Everything \"ekanos dev\" generates is reproducible; ' +\n 'anything else in there is not.',\n );\n}\n\n/**\n * The module specifier `harness.config.ts` uses to import the partner's\n * integration: the `entry` from ekanos.json, made relative and extension-free.\n * \"src/integration.ts\" → \"src/integration\".\n */\nexport function entryImportSpecifier(entry: string): string {\n const normalized = entry.split(path.sep).join('/').replace(/^\\.\\//, '');\n return normalized.replace(/\\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/, '');\n}\n\n/**\n * The same specifier as a JavaScript string LITERAL, ready to drop into a\n * generated `import` statement.\n *\n * `entry` is attacker-influenced data from `ekanos.json`, and a POSIX filename\n * may legally contain a quote or a newline. Interpolating it raw would let a\n * crafted-but-valid path close the string and append statements to the module\n * we generate. `JSON.stringify` produces a correctly escaped literal, which is\n * the actual fix; the explicit rejection below is a second line that also\n * gives the partner a comprehensible error instead of a bizarre filename\n * silently appearing, escaped, in their config.\n *\n * This does not cross a trust boundary on its own — a partner's own code runs\n * unsandboxed anyway — but \"the templates cannot be injected into\" is a claim\n * we make, and it should be true.\n */\nexport function entryImportLiteral(entry: string): string {\n const specifier = entryImportSpecifier(entry);\n\n // eslint-disable-next-line no-control-regex\n if (/[\"'`\\\\\\n\\r\\u0000-\\u001f]/.test(specifier)) {\n throw preconditionError(\n `The \"entry\" in ekanos.json contains characters that cannot appear in ` +\n `an import specifier: ${JSON.stringify(specifier)}.`,\n 'Rename the file so its path has no quotes, backslashes or control ' +\n 'characters, then update \"entry\" in ekanos.json to match.',\n );\n }\n\n return JSON.stringify(`./${specifier}`);\n}\n\nexport interface BootstrapConfigResult {\n /** True only when this run created the file. */\n bootstrapped: boolean;\n configPath: string;\n}\n\n/**\n * Write a starter `harness.config.ts` at the project root — ONCE.\n *\n * An existing file is left strictly alone, byte for byte, and no flag changes\n * that: it is the one harness file the partner owns, it is git-tracked, and\n * regenerating it would throw away their fixtures. `--force` regenerates the\n * shell, never this.\n */\nexport function bootstrapHarnessConfig(\n projectDir: string,\n integrations: readonly { slug: string; entry: string }[],\n): BootstrapConfigResult {\n const configPath = path.join(projectDir, HARNESS_CONFIG_FILENAME);\n const kind = classifyPath(configPath);\n\n // A symlink here — including a dangling one, which `existsSync` reports as\n // absent — would have us write through to its target. Since this file is the\n // partner's to own, the only safe answer is to touch nothing and say why.\n if (kind === 'symlink') {\n throw invalidStateError(\n `${configPath} is a symlink, so \"ekanos dev\" will not write through it.`,\n `Replace ${configPath} with a real file (or delete it to have one ` +\n 'generated), then re-run \"ekanos dev\".',\n );\n }\n\n if (kind !== 'missing') {\n return { bootstrapped: false, configPath };\n }\n\n writeFileNoFollow(projectDir, configPath, renderHarnessConfig(integrations));\n\n return { bootstrapped: true, configPath };\n}\n\n/**\n * Render the starter registry for EVERY integration the project declares.\n *\n * The harness registry is an array and `ekanos.json` can now hold a list, so a\n * project's second integration reaches the harness the same way its first\n * does. Each entry imports the definition under a distinct local identifier\n * derived from its slug, because two `integration` imports in one module do\n * not compile.\n */\nfunction renderHarnessConfig(\n integrations: readonly { slug: string; entry: string }[],\n): string {\n const imports: string[] = [];\n const entries: string[] = [];\n\n for (const integration of integrations) {\n const ident = identifierForSlug(integration.slug);\n imports.push(\n `import { integration as ${ident} } from ${entryImportLiteral(\n integration.entry,\n )};`,\n );\n entries.push(\n readTemplate('harness.config.entry.ts.tmpl', {\n IDENT: ident,\n SLUG: integration.slug,\n }),\n );\n }\n\n return readTemplate('harness.config.ts.tmpl', {\n INTEGRATION_IMPORTS: imports.join('\\n'),\n INTEGRATION_ENTRIES: entries.join(''),\n });\n}\n\n/**\n * \"acme-crm\" → \"acmeCrm\". A slug is kebab-case by schema, so this only has to\n * handle hyphens, and a leading digit is impossible.\n */\nexport function identifierForSlug(slug: string): string {\n const camel = slug.replace(/-([a-z0-9])/g, (_, char: string) =>\n char.toUpperCase(),\n );\n return /^[0-9]/.test(camel) ? `i${camel}` : camel;\n}\n\n/**\n * Add `.ekanos/` to the project `.gitignore`, exactly once.\n *\n * Matching is line-wise over the spellings git treats as the same rule\n * (`.ekanos`, `.ekanos/`, `/.ekanos/`), so re-running never appends a\n * duplicate — the thing that makes a scaffold verb safe to run in a loop.\n * A negation (`!.ekanos/`) is deliberately NOT treated as a match: the\n * partner meant to un-ignore it, and we do not fight that silently.\n */\nexport function ensureGitignoreEntry(projectDir: string): boolean {\n const gitignorePath = path.join(projectDir, '.gitignore');\n const block = `# Ekanos dev harness — generated by \"ekanos dev\", never edited by hand\\n${GITIGNORE_ENTRY}\\n`;\n\n const kind = classifyPath(gitignorePath);\n\n if (kind === 'symlink') {\n throw invalidStateError(\n `${gitignorePath} is a symlink, so \"ekanos dev\" will not append to it.`,\n `Add \"${GITIGNORE_ENTRY}\" to your real .gitignore yourself, or replace ` +\n `${gitignorePath} with a regular file, then re-run \"ekanos dev\".`,\n );\n }\n\n if (kind === 'missing') {\n writeFileNoFollow(projectDir, gitignorePath, block);\n return true;\n }\n\n const existing = readFileNoFollow(projectDir, gitignorePath) ?? '';\n if (gitignoreCovers(existing)) return false;\n\n const separator =\n existing.length === 0 || existing.endsWith('\\n') ? '' : '\\n';\n appendFileNoFollow(projectDir, gitignorePath, `${separator}\\n${block}`);\n return true;\n}\n\nfunction gitignoreCovers(source: string): boolean {\n const equivalents = new Set(['.ekanos', '.ekanos/', '/.ekanos', '/.ekanos/']);\n return source\n .split('\\n')\n .map((line) => line.trim())\n .some((line) => equivalents.has(line));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"harness-scaffold.js","sourceRoot":"","sources":["../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,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/D,kBAAkB,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,SAAS,KAAK,KAAK,EAAE,CAAC,CAAC;IACxE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,eAAe,CAAC,MAAc;IACrC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAC9E,OAAO,MAAM;SACV,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { cliVersion, templatesFingerprint } from './compatibility';\nimport { invalidStateError, preconditionError } from './errors';\nimport {\n appendFileNoFollow,\n classifyPath,\n readFileNoFollow,\n writeFileNoFollow,\n} from './safe-fs';\nimport { readTemplate } from './templates';\n\n/** The dependency that owns every line of harness behaviour. */\nexport const HARNESS_PACKAGE = '@ekanos/harness';\n\n/** Where the generated shell lives, relative to the project root. */\nexport const HARNESS_DIR = path.join('.ekanos', 'harness');\n\n/** The single `.gitignore` line that covers the whole generated tree. */\nexport const GITIGNORE_ENTRY = '.ekanos/';\n\n/**\n * The staleness marker, inside the generated tree so deleting the tree also\n * deletes the marker. Holds the `@ekanos/harness` version that generated the\n * shell — a version bump means the shell may be wired against an older export\n * surface, so it is regenerated.\n */\n/** Next's dev/build cache inside the generated shell. */\nexport const BUILD_CACHE_DIR = '.next';\n\nexport const VERSION_MARKER = '.ekanos-version';\n\n/** The partner-owned registry, at the PROJECT ROOT. Never regenerated. */\nexport const HARNESS_CONFIG_FILENAME = 'harness.config.ts';\n\n/** An experience's generated, empty registry, inside the shell. */\nexport const SHELL_REGISTRY_FILENAME = 'harness.config.ts';\n\n/**\n * Re-point a shell file's import of the project-root registry at the shell's\n * own: the shell sits two directories below the root, so the specifier loses\n * exactly two `../`.\n */\nfunction pointAtShellRegistry(source: string): string {\n return source.replace(\n /((?:\\.\\.\\/){3,})harness\\.config(['\"])/g,\n (_match, ups: string, quote: string) =>\n `${ups.slice(6)}harness.config${quote}`,\n );\n}\n\n/**\n * Every file in the generated shell: bundled template → path inside\n * `.ekanos/harness/`. The ten route files are mechanically derivable from the\n * export map alone — which is the test of whether the package boundary is in\n * the right place. If a shell file ever needs a judgment call, the boundary\n * has moved, not the template.\n *\n * `app/api/integrations/[slug]/[...path]/route.ts` is the shell's one SERVER\n * route: it injects the registry into `@ekanos/harness/api`, which serves the\n * live-mode OAuth loop, storage bridge and trigger route over a server-held\n * context. It is the third registry injection point, beside the two pages.\n *\n * `app/harness-shell.tsx` exists because a `HarnessIntegration` holds React\n * component references and MCP `run` functions. Next cannot serialize those\n * across a server→client boundary, so the `'use client'` mark has to sit ABOVE\n * the point where the registry is injected — hence a client shell of its own\n * rather than a client `RootLayout` called from a server layout. Keeping\n * `app/page.tsx` a server component is what lets `/` prerender static.\n */\nconst consolePage = (dest: string) => ({\n template: `harness/app/${dest}.tmpl`,\n dest: `app/${dest}`,\n});\n\n/**\n * The Integration console (`/integrations/**`). Generated for every project:\n * an integration repo's home, and half of an experience repo's.\n */\nexport const CONSOLE_SHELL_FILES: readonly {\n template: string;\n dest: string;\n}[] = [\n 'integrations/layout.tsx',\n 'integrations/page.tsx',\n 'integrations/[slug]/page.tsx',\n 'integrations/[slug]/connect/page.tsx',\n 'integrations/[slug]/operations/page.tsx',\n 'integrations/[slug]/operations/[kind]/[name]/page.tsx',\n 'integrations/[slug]/events/page.tsx',\n 'integrations/[slug]/health/page.tsx',\n 'integrations/[slug]/runs/page.tsx',\n 'integrations/[slug]/preview/layout.tsx',\n 'integrations/[slug]/preview/page.tsx',\n 'integrations/[slug]/preview/widgets/page.tsx',\n 'integrations/[slug]/preview/widgets/[widgetId]/page.tsx',\n 'integrations/[slug]/preview/tile/page.tsx',\n 'integrations/[slug]/preview/activation/page.tsx',\n 'integrations/[slug]/preview/triggers/page.tsx',\n].map(consolePage);\n\n/**\n * The Experience view (`/experience/**`), generated only for `kind:\n * \"experience\"`. Its layout imports the experience entry (the widgets and\n * pages are React components that only the project's own module holds), and\n * the home page redirects here.\n */\nexport const EXPERIENCE_SHELL_FILES: readonly {\n template: string;\n dest: string;\n}[] = [\n ...[\n 'experience/layout.tsx',\n 'experience/page.tsx',\n 'experience/widgets/page.tsx',\n 'experience/widgets/[id]/page.tsx',\n 'experience/pages/[id]/page.tsx',\n 'experience/workflows/page.tsx',\n 'experience/workflows/[id]/page.tsx',\n 'experience/review-queue/page.tsx',\n 'experience/runs/page.tsx',\n ].map(consolePage),\n { template: 'harness/app/page.experience.tsx.tmpl', dest: 'app/page.tsx' },\n];\n\n/**\n * The repo shell (`ekanos dev` at a repo root). It is the ordinary shell with\n * the single-project home, console layout and API route swapped for the repo's:\n * the repo home and Connections under a `(repo)` route group, each integration\n * package's console under `/integrations/<name>`, each experience package's\n * view under `/experiences/<name>`, and one API route that answers the repo\n * overview and forwards to a package's own harness API.\n */\nconst REPO_REPLACED_DESTS = new Set([\n 'app/page.tsx',\n 'app/harness-shell.tsx',\n 'app/integrations/layout.tsx',\n 'app/integrations/page.tsx',\n 'app/%5F%5Fekanos/api/[...path]/route.ts',\n]);\n\nconst repoTemplate = (dest: string) => ({\n template: `harness/repo/app/${dest}.tmpl`,\n dest: `app/${dest}`,\n});\n\nexport const REPO_SHELL_ONLY_FILES: readonly {\n template: string;\n dest: string;\n}[] = [\n 'harness-shell.tsx',\n '(repo)/layout.tsx',\n '(repo)/page.tsx',\n '(repo)/connections/page.tsx',\n 'integrations/page.tsx',\n 'integrations/[slug]/layout.tsx',\n 'experiences/page.tsx',\n 'experiences/[name]/layout.tsx',\n 'experiences/[name]/connect/page.tsx',\n '%5F%5Fekanos/api/[...path]/route.ts',\n].map(repoTemplate);\n\n/** The Experience view's pages, re-homed under `/experiences/[name]`. */\nconst REPO_EXPERIENCE_PAGES = EXPERIENCE_SHELL_FILES.filter(\n (file) =>\n file.dest.startsWith('app/experience/') &&\n file.dest !== 'app/experience/layout.tsx',\n).map((file) => ({\n template: file.template,\n dest: file.dest.replace('app/experience/', 'app/experiences/[name]/'),\n}));\n\nexport const SHELL_FILES: readonly { template: string; dest: string }[] = [\n { template: 'harness/app/layout.tsx.tmpl', dest: 'app/layout.tsx' },\n {\n template: 'harness/app/harness-shell.tsx.tmpl',\n dest: 'app/harness-shell.tsx',\n },\n { template: 'harness/app/page.tsx.tmpl', dest: 'app/page.tsx' },\n {\n template: 'harness/app/[slug]/layout.tsx.tmpl',\n dest: 'app/[slug]/layout.tsx',\n },\n {\n template: 'harness/app/[slug]/page.tsx.tmpl',\n dest: 'app/[slug]/page.tsx',\n },\n {\n template: 'harness/app/[slug]/widgets/page.tsx.tmpl',\n dest: 'app/[slug]/widgets/page.tsx',\n },\n {\n template: 'harness/app/[slug]/widgets/[widgetId]/page.tsx.tmpl',\n dest: 'app/[slug]/widgets/[widgetId]/page.tsx',\n },\n {\n template: 'harness/app/[slug]/tile/page.tsx.tmpl',\n dest: 'app/[slug]/tile/page.tsx',\n },\n {\n template: 'harness/app/[slug]/activation/page.tsx.tmpl',\n dest: 'app/[slug]/activation/page.tsx',\n },\n {\n template: 'harness/app/[slug]/triggers/page.tsx.tmpl',\n dest: 'app/[slug]/triggers/page.tsx',\n },\n {\n template: 'harness/app/api/integrations/[slug]/[...path]/route.ts.tmpl',\n dest: 'app/api/integrations/[slug]/[...path]/route.ts',\n },\n {\n template: 'harness/app/%5F%5Fekanos/api/[...path]/route.ts.tmpl',\n dest: 'app/%5F%5Fekanos/api/[...path]/route.ts',\n },\n ...CONSOLE_SHELL_FILES,\n { template: 'harness/next.config.mjs.tmpl', dest: 'next.config.mjs' },\n { template: 'harness/postcss.config.mjs.tmpl', dest: 'postcss.config.mjs' },\n { template: 'harness/tsconfig.json.tmpl', dest: 'tsconfig.json' },\n { template: 'harness/styles/globals.css.tmpl', dest: 'styles/globals.css' },\n { template: 'harness/package.json.tmpl', dest: 'package.json' },\n {\n template: 'harness/types/team-accounts.d.ts.tmpl',\n dest: 'types/team-accounts.d.ts',\n },\n];\n\n/**\n * Packages the shell needs to resolve upward out of the partner's own\n * `node_modules`. The shell declares no dependencies of its own by design, so\n * a missing one shows up as an opaque Next resolution error at dev-server\n * start; checking here turns that into one precondition with one fix.\n */\nexport const REQUIRED_DEPENDENCIES = [\n HARNESS_PACKAGE,\n 'next',\n 'react',\n 'react-dom',\n 'tailwindcss',\n '@tailwindcss/postcss',\n] as const;\n\nexport interface WrittenFiles {\n created: string[];\n updated: string[];\n unchanged: string[];\n}\n\n/**\n * Read an installed package's `package.json` out of a project's TOP-LEVEL\n * `node_modules`. Resolved by direct path join rather than `require.resolve`\n * on purpose, for two independent reasons:\n *\n * - The CLI runs from its own install and must read the version of the copy\n * in THE CALLER'S project, not one hoisted next to itself.\n * - Several of the packages this reads (`@ekanos/integration-schema`\n * included) declare an `exports` map with no `./package.json` subpath, so\n * `require.resolve('<pkg>/package.json')` throws\n * `ERR_PACKAGE_PATH_NOT_EXPORTED` under Node's ESM resolver. A plain file\n * read is not subject to the export map at all.\n *\n * Shared by every \"what does this project have installed?\" check in the\n * CLI — `readInstalledHarness` below, the schema-skew gate, and `upgrade`'s\n * current-toolchain report — so there is exactly one implementation of \"read\n * a package's on-disk version\", not a subtly different one per call site.\n */\nexport interface InstalledPackage {\n version: string;\n /** The raw package.json, for callers that need more than the version. */\n manifest: unknown;\n}\n\nexport function readInstalledPackageManifest(\n projectDir: string,\n packageName: string,\n): InstalledPackage | null {\n const manifestPath = path.join(\n projectDir,\n 'node_modules',\n ...packageName.split('/'),\n 'package.json',\n );\n if (!fs.existsSync(manifestPath)) return null;\n\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n const version =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { version?: unknown }).version\n : undefined;\n if (typeof version !== 'string' || version.length === 0) return null;\n return { version, manifest: parsed };\n } catch (error) {\n throw preconditionError(\n `${packageName}'s package.json in node_modules is unreadable: ${\n error instanceof Error ? error.message : String(error)\n }`,\n `Reinstall dependencies in ${projectDir} so ${packageName} resolves.`,\n );\n }\n}\n\n/** Read the installed `@ekanos/harness` version out of the partner's project. */\nexport type InstalledHarness = InstalledPackage;\n\nexport function readInstalledHarness(\n projectDir: string,\n): InstalledHarness | null {\n return readInstalledPackageManifest(projectDir, HARNESS_PACKAGE);\n}\n\n/** Just the installed version, for callers that need nothing else. */\nexport function readInstalledHarnessVersion(projectDir: string): string | null {\n return readInstalledHarness(projectDir)?.version ?? null;\n}\n\n/** Which of `REQUIRED_DEPENDENCIES` are not installed in the project root. */\nexport function missingDependencies(projectDir: string): string[] {\n return REQUIRED_DEPENDENCIES.filter(\n (name) =>\n !fs.existsSync(\n path.join(projectDir, 'node_modules', name, 'package.json'),\n ),\n );\n}\n\n/**\n * What generated an existing shell.\n *\n * All three fields matter, and recording only `harness` was a real hole: the\n * templates ship with the CLI, so a shell can be stale because the CLI changed\n * while the harness did not. `templates` is the authoritative one — it is a\n * hash of the template sources, so it moves whenever what we generate moves,\n * including for a CLI build that never shipped a version bump.\n */\nexport interface ShellMarker {\n harness: string;\n /** null for a legacy bare-version marker written before this was recorded. */\n cli: string | null;\n templates: string | null;\n}\n\n/**\n * Three outcomes, not two, because \"no marker\" and \"unreadable marker\" call\n * for opposite responses.\n *\n * A marker's PRESENCE is itself evidence the tree is ours — a squatter does\n * not write `.ekanos-version` — and the likeliest cause of an unreadable one\n * is our own interrupted write. Everything under `.ekanos/harness/` is\n * CLI-owned, gitignored and reproducible from the templates, so regenerating\n * destroys nothing: there is no value at risk to justify charging a partner a\n * confusing `--force` to recover from our own bad write.\n *\n * An ABSENT marker over a non-empty tree is the opposite: nothing says the\n * files are ours, so we refuse. That is the L1 rule and it stays.\n */\nexport type MarkerState =\n | { kind: 'missing' }\n | { kind: 'corrupt' }\n | { kind: 'ok'; marker: ShellMarker };\n\nexport function readShellMarkerState(harnessDir: string): MarkerState {\n const marker = path.join(harnessDir, VERSION_MARKER);\n if (classifyPath(marker) !== 'file') return { kind: 'missing' };\n\n const raw = (readFileNoFollow(harnessDir, marker) ?? '').trim();\n if (raw.length === 0) return { kind: 'corrupt' };\n\n const parsed = parseMarker(raw);\n return parsed === null ? { kind: 'corrupt' } : { kind: 'ok', marker: parsed };\n}\n\nfunction parseMarker(raw: string): ShellMarker | null {\n // v1 markers were a bare version string. Read them rather than crashing, and\n // report the unknown fields as null so the shell counts as stale and is\n // regenerated once — which is the correct outcome for an upgrade.\n //\n // It must actually LOOK like a version: without this, any garbage that does\n // not happen to start with `{` — a truncated write, a stray word — reads as\n // a legacy marker named after the garbage, and the corrupt-marker path never\n // fires. That is how a truncated `.ekanos-version` was silently reported as\n // \"@ekanos/harness truncat → 0.1.0\" instead of \"unreadable\".\n if (!raw.startsWith('{')) {\n return /^\\d+\\.\\d+/.test(raw)\n ? { harness: raw, cli: null, templates: null }\n : null;\n }\n\n try {\n const parsed: unknown = JSON.parse(raw);\n if (typeof parsed !== 'object' || parsed === null) return null;\n const record = parsed as Record<string, unknown>;\n const harness = record.harness;\n if (typeof harness !== 'string') return null;\n return {\n harness,\n cli: typeof record.cli === 'string' ? record.cli : null,\n templates: typeof record.templates === 'string' ? record.templates : null,\n };\n } catch {\n return null;\n }\n}\n\n/** The parsed marker, or null when it is absent OR unreadable. */\nexport function readShellMarker(harnessDir: string): ShellMarker | null {\n const state = readShellMarkerState(harnessDir);\n return state.kind === 'ok' ? state.marker : null;\n}\n\n/** The `@ekanos/harness` version an existing shell was generated against. */\nexport function readShellVersion(harnessDir: string): string | null {\n return readShellMarker(harnessDir)?.harness ?? null;\n}\n\nfunction serializeMarker(marker: ShellMarker): string {\n return `${JSON.stringify(marker, null, 2)}\\n`;\n}\n\n/**\n * Write a generated file, but ONLY when its bytes would change.\n *\n * This is what makes a re-run cheap and a watcher quiet: an unchanged file is\n * not rewritten, so its mtime does not move and Next's dev server does not\n * rebuild. It also means a hand-edit inside the CLI-owned tree is silently\n * corrected on the next run, which is the intended contract for `.ekanos/`.\n */\nexport function writeIfChanged(\n root: string,\n destPath: string,\n contents: string,\n into: WrittenFiles,\n label: string,\n force: boolean,\n): void {\n // `classifyPath` uses lstat, so a symlink here is reported as a symlink\n // rather than as whatever it points at — including a DANGLING one, which\n // `existsSync` would call absent and a plain write would then materialize\n // outside the project.\n const kind = classifyPath(destPath);\n const exists = kind !== 'missing';\n\n if (\n !force &&\n kind === 'file' &&\n readFileNoFollow(root, destPath) === contents\n ) {\n into.unchanged.push(label);\n return;\n }\n\n writeFileNoFollow(root, destPath, contents);\n (exists ? into.updated : into.created).push(label);\n}\n\nexport interface ScaffoldShellArgs {\n projectDir: string;\n slug: string;\n harnessVersion: string;\n /** Rewrite every file even when its bytes already match. */\n force: boolean;\n /** Extra Tailwind @source globs from ekanos.json, already validated. */\n sourceGlobs?: readonly string[];\n /**\n * Set for a `kind: \"experience\"` project: its entry (project-relative). The\n * Experience view is generated, and mounts the entry's widgets and pages.\n */\n experienceEntry?: string;\n /** Set when `projectDir` is a repo root: the packages the shell serves. */\n repo?: RepoShellPackages;\n}\n\n/** Package directories and entries are relative to the repo root. */\nexport interface RepoShellPackages {\n integrations: readonly { name: string; dir: string }[];\n experiences: readonly { name: string; dir: string; entry: string }[];\n}\n\nexport interface ScaffoldShellResult extends WrittenFiles {\n harnessDir: string;\n /** The version the shell carried before this run — null on a first run. */\n previousVersion: string | null;\n /** What generated the previous shell, or null on a first run. */\n previousMarker: ShellMarker | null;\n /** True when anything that generated the shell has since changed. */\n stale: boolean;\n /** `.next` under the shell was deleted because the shell was stale. */\n buildCacheCleared: boolean;\n /**\n * Which of harness / cli / templates moved. Empty on a first run; this is\n * what lets `dev` say WHY it regenerated rather than just that it did.\n */\n staleReasons: string[];\n}\n\n/**\n * Generate `.ekanos/harness/**` for `harnessVersion`. Every file here is\n * CLI-owned and gitignored, so regeneration needs no permission and asks no\n * question — the partner owns `harness.config.ts` and their integration\n * source, and nothing else.\n */\nexport function scaffoldShell(args: ScaffoldShellArgs): ScaffoldShellResult {\n const harnessDir = path.join(args.projectDir, HARNESS_DIR);\n assertShellDirIsOurs(harnessDir, args.force);\n\n const markerState = readShellMarkerState(harnessDir);\n const previousMarker = markerState.kind === 'ok' ? markerState.marker : null;\n const previousVersion = previousMarker?.harness ?? null;\n const shellFiles = args.repo\n ? repoShellFiles()\n : shellFilesFor(args.experienceEntry !== undefined);\n const marker: ShellMarker = {\n harness: args.harnessVersion,\n cli: cliVersion(),\n templates: templatesFingerprint(shellFiles.map((f) => f.template)),\n };\n\n // A shell is current only if EVERYTHING that produced it is unchanged.\n // Checking the harness version alone certified shells generated by an older\n // CLI, against templates that had since moved, as up to date.\n const staleReasons: string[] = [];\n if (markerState.kind === 'corrupt') {\n staleReasons.push(\n `${VERSION_MARKER} was unreadable, so the existing shell could not be ` +\n 'certified',\n );\n }\n if (previousMarker !== null) {\n if (previousMarker.harness !== marker.harness) {\n staleReasons.push(\n `@ekanos/harness ${previousMarker.harness} → ${marker.harness}`,\n );\n }\n if (previousMarker.cli !== marker.cli) {\n staleReasons.push(\n `@ekanos/cli ${previousMarker.cli ?? 'unknown'} → ${marker.cli}`,\n );\n }\n if (previousMarker.templates !== marker.templates) {\n staleReasons.push('the shell templates changed');\n }\n }\n const stale = staleReasons.length > 0;\n\n // Next's persistent dev cache was built from the OLD shell and the OLD\n // toolchain. Keeping it across a regeneration served a corrupted Tailwind\n // candidate on the 0.1 → 0.4 jump (every page a build-error overlay until\n // someone deleted the directory by hand). The shell knows it is stale; the\n // cache goes with it.\n const buildCacheDir = path.join(harnessDir, BUILD_CACHE_DIR);\n const buildCacheCleared = stale && fs.existsSync(buildCacheDir);\n if (buildCacheCleared) {\n fs.rmSync(buildCacheDir, { recursive: true, force: true });\n }\n\n const files: WrittenFiles = { created: [], updated: [], unchanged: [] };\n const vars = {\n SLUG: args.slug,\n SOURCE_GLOBS: renderSourceGlobs(args.sourceGlobs ?? []),\n EXPERIENCE_ENTRY:\n args.experienceEntry === undefined\n ? '\"\"'\n : entryImportLiteral(args.experienceEntry, SHELL_APP_TO_PROJECT),\n ...(args.repo ? renderRepoExperiences(args.repo) : {}),\n };\n\n const experience =\n args.experienceEntry !== undefined || args.repo !== undefined;\n for (const { template, dest } of shellFiles) {\n const rendered = readTemplate(template, vars);\n writeIfChanged(\n args.projectDir,\n path.join(harnessDir, dest),\n experience ? pointAtShellRegistry(rendered) : rendered,\n files,\n dest,\n args.force,\n );\n }\n\n // An experience registers no integration, so it has no project-root\n // `harness.config.ts` to own: the shell carries its own (generated, empty)\n // registry and the files above import that instead.\n if (experience) {\n writeIfChanged(\n args.projectDir,\n path.join(harnessDir, SHELL_REGISTRY_FILENAME),\n args.repo ? renderRepoRegistry(args.repo) : renderHarnessConfig([]),\n files,\n SHELL_REGISTRY_FILENAME,\n args.force,\n );\n }\n\n writeIfChanged(\n args.projectDir,\n path.join(harnessDir, VERSION_MARKER),\n serializeMarker(marker),\n files,\n VERSION_MARKER,\n args.force,\n );\n\n return {\n ...files,\n harnessDir,\n previousVersion,\n previousMarker,\n stale,\n staleReasons,\n buildCacheCleared,\n };\n}\n\n/**\n * `app/repo-experiences.ts`: the experience entries, imported statically (they\n * hold React components, which cannot cross the server/client boundary).\n */\nfunction renderRepoExperiences(repo: RepoShellPackages): {\n EXPERIENCE_IMPORTS: string;\n EXPERIENCE_ENTRIES: string;\n} {\n const imports: string[] = [];\n const entries: string[] = [];\n repo.experiences.forEach((experience, index) => {\n const ident = `experience${index}`;\n imports.push(\n `import ${ident} from ${entryImportLiteral(\n `${experience.dir}/${experience.entry}`,\n // app/repo-experiences.ts sits one level above app/experience/.\n '../../../',\n )};`,\n );\n entries.push(\n ` ${JSON.stringify(experience.name)}: { widgets: ${ident}.widgets ?? [], pages: ${ident}.pages ?? [] },\\n`,\n );\n });\n return {\n EXPERIENCE_IMPORTS: imports.join('\\n'),\n EXPERIENCE_ENTRIES: entries.join(''),\n };\n}\n\n/**\n * The shell's registry at a repo root: every integration package's own\n * `harness.config.ts`, concatenated, so each integration's widgets, tile and\n * activation surfaces and its OAuth routes keep working.\n */\nfunction renderRepoRegistry(repo: RepoShellPackages): string {\n const imports = repo.integrations.map((integration, index) => {\n const specifier = JSON.stringify(\n `${SHELL_TO_PROJECT_REGISTRY}${integration.dir}/${path.basename(HARNESS_CONFIG_FILENAME, '.ts')}`,\n );\n return `import { harnessIntegrations as integration${index} } from ${specifier};`;\n });\n const spread = repo.integrations\n .map((_, index) => `...integration${index}`)\n .join(', ');\n return [\n '// Generated by `ekanos dev` at a repo root. Each integration package owns its own harness.config.ts.',\n \"import { defineHarnessConfig } from '@ekanos/harness/config';\",\n ...imports,\n '',\n `export const harnessIntegrations = defineHarnessConfig([${spread}]);`,\n '',\n ].join('\\n');\n}\n\n/** From `.ekanos/harness/` (where the shell registry sits) up to the repo root. */\nconst SHELL_TO_PROJECT_REGISTRY = '../../';\n\n/**\n * Turn validated `sourceGlobs` into the `@source` lines the generated\n * stylesheet carries, each relative to the shell's `styles/` directory.\n *\n * Tailwind never scans what it is not pointed at, and a glob that matches\n * nothing fails silently — so an integration living outside the default\n * layout renders completely unstyled with no error anywhere. That is what\n * `sourceGlobs` is for, and until now it was parsed and thrown away.\n */\nfunction renderSourceGlobs(globs: readonly string[]): string {\n if (globs.length === 0) return '';\n const lines = globs.map((glob) => `@source '${SHELL_TO_PROJECT}${glob}';`);\n return `\\n/* From \"sourceGlobs\" in ekanos.json. */\\n${lines.join('\\n')}\\n`;\n}\n\n/**\n * From `.ekanos/harness/app/experience/` back up to the project root: the\n * experience layout imports the entry by this relative path.\n */\nconst SHELL_APP_TO_PROJECT = '../../../../';\n\n/** The shell file set: the legacy shell + console, plus the Experience view for an experience. */\nexport function shellFilesFor(\n experience: boolean,\n): readonly { template: string; dest: string }[] {\n if (!experience) return SHELL_FILES;\n const replaced = new Set(EXPERIENCE_SHELL_FILES.map((f) => f.dest));\n return [\n ...SHELL_FILES.filter((f) => !replaced.has(f.dest)),\n ...EXPERIENCE_SHELL_FILES,\n ];\n}\n\n/** The repo shell file set. */\nexport function repoShellFiles(): readonly {\n template: string;\n dest: string;\n}[] {\n return [\n ...SHELL_FILES.filter((f) => !REPO_REPLACED_DESTS.has(f.dest)),\n ...REPO_SHELL_ONLY_FILES,\n ...REPO_EXPERIENCE_PAGES,\n {\n template: 'harness/repo/app/repo-experiences.ts.tmpl',\n dest: 'app/repo-experiences.ts',\n },\n ];\n}\n\n/** From `.ekanos/harness/styles/` back up to the project root. */\nconst SHELL_TO_PROJECT = '../../../';\n\n/**\n * Establish that `.ekanos/harness` is a tree WE generated before writing a\n * single byte into it, and return the version marker it carried.\n *\n * Path location alone is not ownership. A directory that exists but carries no\n * `.ekanos-version` was put there by something else — a partner, another tool,\n * a symlink — and clobbering it because it happens to sit at the path we like\n * is the same class of mistake as following a symlink. An empty directory is\n * fine (that is just `mkdir -p` having run), and `--force` is the explicit\n * override.\n *\n * Runs BEFORE `bootstrapHarnessConfig` in `dev`, so a shell that cannot be\n * written leaves the project completely untouched rather than half-scaffolded.\n */\nexport function assertShellDirIsOurs(\n harnessDir: string,\n force: boolean,\n): string | null {\n // `.ekanos` first: through a symlinked `.ekanos`, the lstat below would\n // describe the link's target, and the build-cache `rmSync` would delete\n // outside the project.\n const ekanosDir = path.dirname(harnessDir);\n const parentKind = classifyPath(ekanosDir);\n if (parentKind === 'symlink') {\n throw invalidStateError(\n `${ekanosDir} is a symlink, so \"ekanos dev\" will not write through it.`,\n `Delete the ${ekanosDir} link and re-run \"ekanos dev\" — the shell is ` +\n 'generated, so nothing is lost.',\n );\n }\n if (parentKind !== 'missing' && parentKind !== 'directory') {\n throw invalidStateError(\n `${ekanosDir} exists and is not a directory.`,\n `Move or delete ${ekanosDir}, then re-run \"ekanos dev\".`,\n );\n }\n\n const kind = classifyPath(harnessDir);\n\n if (kind === 'symlink') {\n throw invalidStateError(\n `${harnessDir} is a symlink, so \"ekanos dev\" will not write through it.`,\n `Delete ${harnessDir} and re-run \"ekanos dev\" — the shell is generated, ` +\n 'so nothing is lost.',\n );\n }\n\n if (kind !== 'missing' && kind !== 'directory') {\n throw invalidStateError(\n `${harnessDir} exists and is not a directory.`,\n `Move or delete ${harnessDir}, then re-run \"ekanos dev\".`,\n );\n }\n\n if (kind === 'missing') return null;\n\n const state = readShellMarkerState(harnessDir);\n\n // A marker we wrote, however mangled, still identifies the tree as ours.\n if (state.kind === 'ok') return state.marker.harness;\n if (state.kind === 'corrupt' || force) return null;\n\n if (fs.readdirSync(harnessDir).length === 0) return null;\n\n throw invalidStateError(\n `${harnessDir} already contains files but no ${VERSION_MARKER} marker, ` +\n 'so it was not generated by \"ekanos dev\".',\n `Delete ${harnessDir} if you do not need it, or pass --force to ` +\n 'overwrite it. Everything \"ekanos dev\" generates is reproducible; ' +\n 'anything else in there is not.',\n );\n}\n\n/**\n * The module specifier `harness.config.ts` uses to import the partner's\n * integration: the `entry` from ekanos.json, made relative and extension-free.\n * \"src/integration.ts\" → \"src/integration\".\n */\nexport function entryImportSpecifier(entry: string): string {\n const normalized = entry.split(path.sep).join('/').replace(/^\\.\\//, '');\n return normalized.replace(/\\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/, '');\n}\n\n/**\n * The same specifier as a JavaScript string LITERAL, ready to drop into a\n * generated `import` statement.\n *\n * `entry` is attacker-influenced data from `ekanos.json`, and a POSIX filename\n * may legally contain a quote or a newline. Interpolating it raw would let a\n * crafted-but-valid path close the string and append statements to the module\n * we generate. `JSON.stringify` produces a correctly escaped literal, which is\n * the actual fix; the explicit rejection below is a second line that also\n * gives the partner a comprehensible error instead of a bizarre filename\n * silently appearing, escaped, in their config.\n *\n * This does not cross a trust boundary on its own — a partner's own code runs\n * unsandboxed anyway — but \"the templates cannot be injected into\" is a claim\n * we make, and it should be true.\n */\nexport function entryImportLiteral(entry: string, prefix = './'): string {\n const specifier = entryImportSpecifier(entry);\n\n // eslint-disable-next-line no-control-regex\n if (/[\"'`\\\\\\n\\r\\u0000-\\u001f]/.test(specifier)) {\n throw preconditionError(\n `The \"entry\" in ekanos.json contains characters that cannot appear in ` +\n `an import specifier: ${JSON.stringify(specifier)}.`,\n 'Rename the file so its path has no quotes, backslashes or control ' +\n 'characters, then update \"entry\" in ekanos.json to match.',\n );\n }\n\n return JSON.stringify(`${prefix}${specifier}`);\n}\n\nexport interface BootstrapConfigResult {\n /** True only when this run created the file. */\n bootstrapped: boolean;\n configPath: string;\n}\n\n/**\n * Write a starter `harness.config.ts` at the project root — ONCE.\n *\n * An existing file is left strictly alone, byte for byte, and no flag changes\n * that: it is the one harness file the partner owns, it is git-tracked, and\n * regenerating it would throw away their fixtures. `--force` regenerates the\n * shell, never this.\n */\nexport function bootstrapHarnessConfig(\n projectDir: string,\n integrations: readonly { slug: string; entry: string }[],\n): BootstrapConfigResult {\n // An experience project has no integration of its own to register: the\n // harness serves its integrations from `ekanos.json` through /__ekanos/api.\n const configPath = path.join(projectDir, HARNESS_CONFIG_FILENAME);\n const kind = classifyPath(configPath);\n\n // A symlink here — including a dangling one, which `existsSync` reports as\n // absent — would have us write through to its target. Since this file is the\n // partner's to own, the only safe answer is to touch nothing and say why.\n if (kind === 'symlink') {\n throw invalidStateError(\n `${configPath} is a symlink, so \"ekanos dev\" will not write through it.`,\n `Replace ${configPath} with a real file (or delete it to have one ` +\n 'generated), then re-run \"ekanos dev\".',\n );\n }\n\n if (kind !== 'missing') {\n return { bootstrapped: false, configPath };\n }\n\n writeFileNoFollow(projectDir, configPath, renderHarnessConfig(integrations));\n\n return { bootstrapped: true, configPath };\n}\n\n/**\n * Render the starter registry for EVERY integration the project declares.\n *\n * The harness registry is an array and `ekanos.json` can now hold a list, so a\n * project's second integration reaches the harness the same way its first\n * does. Each entry imports the definition under a distinct local identifier\n * derived from its slug, because two `integration` imports in one module do\n * not compile.\n */\nfunction renderHarnessConfig(\n integrations: readonly { slug: string; entry: string }[],\n): string {\n const imports: string[] = [];\n const entries: string[] = [];\n\n for (const integration of integrations) {\n const ident = identifierForSlug(integration.slug);\n imports.push(\n `import { integration as ${ident} } from ${entryImportLiteral(\n integration.entry,\n )};`,\n );\n entries.push(\n readTemplate('harness.config.entry.ts.tmpl', {\n IDENT: ident,\n SLUG: integration.slug,\n }),\n );\n }\n\n return readTemplate('harness.config.ts.tmpl', {\n INTEGRATION_IMPORTS: imports.join('\\n'),\n INTEGRATION_ENTRIES: entries.join(''),\n });\n}\n\n/**\n * \"acme-crm\" → \"acmeCrm\". A slug is kebab-case by schema, so this only has to\n * handle hyphens, and a leading digit is impossible.\n */\nexport function identifierForSlug(slug: string): string {\n const camel = slug.replace(/-([a-z0-9])/g, (_, char: string) =>\n char.toUpperCase(),\n );\n return /^[0-9]/.test(camel) ? `i${camel}` : camel;\n}\n\n/**\n * Add `.ekanos/` to the project `.gitignore`, exactly once.\n *\n * Matching is line-wise over the spellings git treats as the same rule\n * (`.ekanos`, `.ekanos/`, `/.ekanos/`), so re-running never appends a\n * duplicate — the thing that makes a scaffold verb safe to run in a loop.\n * A negation (`!.ekanos/`) is deliberately NOT treated as a match: the\n * partner meant to un-ignore it, and we do not fight that silently.\n */\nexport function ensureGitignoreEntry(projectDir: string): boolean {\n const gitignorePath = path.join(projectDir, '.gitignore');\n const block = `# Ekanos dev harness — generated by \"ekanos dev\", never edited by hand\\n${GITIGNORE_ENTRY}\\n`;\n\n const kind = classifyPath(gitignorePath);\n\n if (kind === 'symlink') {\n throw invalidStateError(\n `${gitignorePath} is a symlink, so \"ekanos dev\" will not append to it.`,\n `Add \"${GITIGNORE_ENTRY}\" to your real .gitignore yourself, or replace ` +\n `${gitignorePath} with a regular file, then re-run \"ekanos dev\".`,\n );\n }\n\n if (kind === 'missing') {\n writeFileNoFollow(projectDir, gitignorePath, block);\n return true;\n }\n\n const existing = readFileNoFollow(projectDir, gitignorePath) ?? '';\n if (gitignoreCovers(existing)) return false;\n\n const separator =\n existing.length === 0 || existing.endsWith('\\n') ? '' : '\\n';\n appendFileNoFollow(projectDir, gitignorePath, `${separator}\\n${block}`);\n return true;\n}\n\nfunction gitignoreCovers(source: string): boolean {\n const equivalents = new Set(['.ekanos', '.ekanos/', '/.ekanos', '/.ekanos/']);\n return source\n .split('\\n')\n .map((line) => line.trim())\n .some((line) => equivalents.has(line));\n}\n"]}
|