@powerhousedao/ph-clint-cli 0.1.0-dev.8 → 0.1.0-dev.80
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/dist/cli.js +52 -10
- package/dist/codegen/actions.d.ts +46 -0
- package/dist/codegen/actions.js +424 -0
- package/dist/codegen/builders/agent-ts.d.ts +4 -4
- package/dist/codegen/builders/agent-ts.js +92 -2
- package/dist/codegen/builders/app-index-ts.d.ts +3 -10
- package/dist/codegen/builders/app-index-ts.js +30 -20
- package/dist/codegen/builders/cli-package-json.js +46 -14
- package/dist/codegen/builders/cli-ts.js +87 -49
- package/dist/codegen/builders/config-ts.d.ts +1 -1
- package/dist/codegen/builders/config-ts.js +2 -8
- package/dist/codegen/builders/demo-agent-ts.d.ts +8 -0
- package/dist/codegen/builders/demo-agent-ts.js +50 -0
- package/dist/codegen/builders/eslint-config-js.d.ts +1 -1
- package/dist/codegen/builders/eslint-config-js.js +7 -4
- package/dist/codegen/builders/framework-gen-ts.d.ts +11 -6
- package/dist/codegen/builders/framework-gen-ts.js +73 -21
- package/dist/codegen/builders/framework-ts.js +33 -7
- package/dist/codegen/builders/index.d.ts +10 -2
- package/dist/codegen/builders/index.js +30 -6
- package/dist/codegen/builders/manifest-json.d.ts +6 -0
- package/dist/codegen/builders/manifest-json.js +31 -0
- package/dist/codegen/builders/mastra-index-ts.d.ts +3 -0
- package/dist/codegen/builders/mastra-index-ts.js +47 -5
- package/dist/codegen/builders/publish-config-js.d.ts +8 -0
- package/dist/codegen/builders/publish-config-js.js +33 -0
- package/dist/codegen/builders/readme-md.js +7 -6
- package/dist/codegen/builders/root-package-json.js +11 -12
- package/dist/codegen/builders/smoke-test-ts.d.ts +2 -0
- package/dist/codegen/builders/smoke-test-ts.js +15 -0
- package/dist/codegen/exec.d.ts +0 -18
- package/dist/codegen/exec.js +0 -27
- package/dist/codegen/generated.d.ts +17 -0
- package/dist/codegen/generated.js +49 -0
- package/dist/codegen/index.d.ts +8 -36
- package/dist/codegen/index.js +6 -293
- package/dist/codegen/scaffold.d.ts +41 -3
- package/dist/codegen/scaffold.js +106 -16
- package/dist/commands/clint-project-build.d.ts +77 -1
- package/dist/commands/clint-project-build.js +11 -28
- package/dist/commands/clint-project-init.d.ts +128 -10
- package/dist/commands/clint-project-init.js +72 -47
- package/dist/commands/clint-project-publish.d.ts +78 -1
- package/dist/commands/clint-project-publish.js +6 -4
- package/dist/commands/clint-project-regen.d.ts +77 -1
- package/dist/commands/clint-project-regen.js +26 -2
- package/dist/commands/clint-skills-sync.d.ts +86 -0
- package/dist/commands/clint-skills-sync.js +56 -0
- package/dist/framework.d.ts +322 -60
- package/dist/framework.gen.d.ts +50 -10
- package/dist/framework.js +1 -5
- package/{prompts/agent-profiles/AgentBase.md → dist/gen/agent-profiles/PhClintDevAgent.md} +1 -1
- package/dist/gen/skills/cli-setup/.cli-docs.md +135 -0
- package/dist/gen/skills/cli-setup/SKILL.md +125 -0
- package/dist/gen/skills/cli-setup/references/00.assess-cli-needs.md +53 -0
- package/dist/gen/skills/cli-setup/references/01.define-config-schema.md +78 -0
- package/dist/gen/skills/cli-setup/references/02.wire-cli.md +141 -0
- package/dist/gen/skills/cli-setup/references/03.add-entrypoint.md +128 -0
- package/dist/gen/skills/cli-setup/references/expected-outcome.md +3 -0
- package/dist/gen/skills/command-definition/.cli-docs.md +84 -0
- package/dist/gen/skills/command-definition/SKILL.md +99 -0
- package/dist/gen/skills/command-definition/references/00.assess-requirements.md +58 -0
- package/dist/gen/skills/command-definition/references/01.define-schema.md +72 -0
- package/dist/gen/skills/command-definition/references/02.implement-execute.md +118 -0
- package/dist/gen/skills/command-definition/references/03.add-prompting.md +54 -0
- package/dist/gen/skills/command-definition/references/expected-outcome.md +3 -0
- package/dist/gen/skills/service-definition/.cli-docs.md +214 -0
- package/dist/gen/skills/service-definition/SKILL.md +148 -0
- package/dist/gen/skills/service-definition/references/00.assess-service.md +69 -0
- package/dist/gen/skills/service-definition/references/01.define-service.md +166 -0
- package/dist/gen/skills/service-definition/references/02.add-preflight.md +132 -0
- package/dist/gen/skills/service-definition/references/03.add-project-scanner.md +82 -0
- package/dist/gen/skills/service-definition/references/04.wire-events.md +120 -0
- package/dist/gen/skills/service-definition/references/expected-outcome.md +3 -0
- package/dist/main.js +0 -0
- package/dist/services/clint-project.js +21 -0
- package/dist/skills/sync.d.ts +40 -0
- package/dist/skills/sync.js +119 -0
- package/dist/spec/ensure-document.d.ts +17 -0
- package/dist/spec/ensure-document.js +56 -0
- package/dist/spec/file.d.ts +1 -4
- package/dist/spec/file.js +1 -34
- package/dist/spec/from-document.d.ts +4 -1
- package/dist/spec/from-document.js +4 -16
- package/dist/spec/types.d.ts +1 -62
- package/dist/spec/types.js +1 -112
- package/dist/triggers/publish-trigger.d.ts +81 -0
- package/dist/triggers/publish-trigger.js +137 -0
- package/dist/triggers/spec-change.d.ts +60 -18
- package/dist/triggers/spec-change.js +154 -101
- package/package.json +13 -18
- package/dist/codegen/builders/publish-config-ts.d.ts +0 -6
- package/dist/codegen/builders/publish-config-ts.js +0 -18
- package/dist/commands/init.d.ts +0 -57
- package/dist/commands/init.js +0 -168
- package/dist/commands/regen.d.ts +0 -18
- package/dist/commands/regen.js +0 -68
- package/prompts/skills-ext/.gitkeep +0 -0
- package/prompts/skills-tpl/.gitkeep +0 -0
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Builds `src/framework.gen.ts` — the fully machine-owned half of the
|
|
3
3
|
* typed-binding split. Regenerated on every `init` and `update`; holds the
|
|
4
|
-
* `defineRegistry([...]
|
|
4
|
+
* `defineRegistry([...])` call that describes which document models
|
|
5
5
|
* are bound into `framework.ts`'s typed factories.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Iterates all packages' document types. The app package's modules are
|
|
8
|
+
* imported from the local `{name}-app` package; external packages' modules
|
|
9
|
+
* are imported from their npm package name.
|
|
10
|
+
*
|
|
11
|
+
* Document type entries may be explicit IDs (`powerhouse/ph-clint-project`)
|
|
12
|
+
* or glob patterns (`*/*`, `powerhouse/*`, `acme/doc-*`). Explicit IDs
|
|
13
|
+
* produce static named imports; glob patterns import the package's
|
|
14
|
+
* `documentModels` array and filter at runtime so newly-added document
|
|
15
|
+
* models are picked up without a codegen re-run.
|
|
11
16
|
*
|
|
12
17
|
* Emitted only when Powerhouse is enabled — flat-layout impls have no
|
|
13
18
|
* reactor package to import modules from and bind `createTypes` directly in
|
|
14
|
-
* `framework.ts`. When Powerhouse is on but no
|
|
19
|
+
* `framework.ts`. When Powerhouse is on but no document types are declared,
|
|
15
20
|
* we still emit this file with an empty `defineRegistry([])` so impl code's
|
|
16
21
|
* `import { registry } from './framework.gen.js'` keeps resolving across
|
|
17
22
|
* regens.
|
|
@@ -1,34 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Builds `src/framework.gen.ts` — the fully machine-owned half of the
|
|
3
3
|
* typed-binding split. Regenerated on every `init` and `update`; holds the
|
|
4
|
-
* `defineRegistry([...]
|
|
4
|
+
* `defineRegistry([...])` call that describes which document models
|
|
5
5
|
* are bound into `framework.ts`'s typed factories.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Iterates all packages' document types. The app package's modules are
|
|
8
|
+
* imported from the local `{name}-app` package; external packages' modules
|
|
9
|
+
* are imported from their npm package name.
|
|
10
|
+
*
|
|
11
|
+
* Document type entries may be explicit IDs (`powerhouse/ph-clint-project`)
|
|
12
|
+
* or glob patterns (`*/*`, `powerhouse/*`, `acme/doc-*`). Explicit IDs
|
|
13
|
+
* produce static named imports; glob patterns import the package's
|
|
14
|
+
* `documentModels` array and filter at runtime so newly-added document
|
|
15
|
+
* models are picked up without a codegen re-run.
|
|
11
16
|
*
|
|
12
17
|
* Emitted only when Powerhouse is enabled — flat-layout impls have no
|
|
13
18
|
* reactor package to import modules from and bind `createTypes` directly in
|
|
14
|
-
* `framework.ts`. When Powerhouse is on but no
|
|
19
|
+
* `framework.ts`. When Powerhouse is on but no document types are declared,
|
|
15
20
|
* we still emit this file with an empty `defineRegistry([])` so impl code's
|
|
16
21
|
* `import { registry } from './framework.gen.js'` keeps resolving across
|
|
17
22
|
* regens.
|
|
18
23
|
*/
|
|
19
|
-
import { getDocumentTypeModuleName, } from '../../spec/types.js';
|
|
20
|
-
/** Local package name of the reactor package for this project. */
|
|
21
|
-
function appPackageName(spec) {
|
|
22
|
-
return `${spec.name}-app`;
|
|
23
|
-
}
|
|
24
|
+
import { docTypeGlobToRegex, getAppPackageName, getDocumentTypeModuleName, getDocumentTypeSlug, isDocTypeGlob, phAtLeast, } from '../../spec/types.js';
|
|
24
25
|
export function buildFrameworkGenTs(spec) {
|
|
25
|
-
if (!spec.features.powerhouse
|
|
26
|
+
if (!phAtLeast(spec.features.powerhouse, 'Reactor'))
|
|
26
27
|
return null;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const appPkg = getAppPackageName(spec);
|
|
29
|
+
// Collect entries across packages. Each package may contribute both
|
|
30
|
+
// explicit named imports and glob-based runtime filters.
|
|
31
|
+
const entries = [];
|
|
32
|
+
let globCounter = 0;
|
|
33
|
+
for (const pkg of spec.packages) {
|
|
34
|
+
const isApp = pkg.packageName === appPkg;
|
|
35
|
+
// Collect glob patterns for this package (may be multiple).
|
|
36
|
+
const globs = pkg.documentTypes.filter(isDocTypeGlob);
|
|
37
|
+
const explicits = pkg.documentTypes.filter((dt) => !isDocTypeGlob(dt));
|
|
38
|
+
for (const docType of explicits) {
|
|
39
|
+
const slug = getDocumentTypeSlug(docType);
|
|
40
|
+
entries.push({
|
|
41
|
+
kind: 'explicit',
|
|
42
|
+
name: getDocumentTypeModuleName(docType),
|
|
43
|
+
importFrom: isApp ? appPkg : `${pkg.packageName}/document-models/${slug}`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (globs.length > 0) {
|
|
47
|
+
// Merge all globs for this package into a single regex alternation.
|
|
48
|
+
const combined = globs.length === 1
|
|
49
|
+
? docTypeGlobToRegex(globs[0])
|
|
50
|
+
: globs.map((g) => `(?:${docTypeGlobToRegex(g)})`).join('|');
|
|
51
|
+
const alias = globCounter === 0 ? 'globModels' : `globModels${globCounter}`;
|
|
52
|
+
globCounter++;
|
|
53
|
+
entries.push({
|
|
54
|
+
kind: 'glob',
|
|
55
|
+
modelsAlias: alias,
|
|
56
|
+
importFrom: isApp ? appPkg : pkg.packageName,
|
|
57
|
+
regexSource: combined,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const hasGlobs = entries.some((e) => e.kind === 'glob');
|
|
32
62
|
const lines = [];
|
|
33
63
|
lines.push('/**');
|
|
34
64
|
lines.push(' * THIS FILE IS GENERATED BY ph-clint-cli. DO NOT EDIT.');
|
|
@@ -38,24 +68,46 @@ export function buildFrameworkGenTs(spec) {
|
|
|
38
68
|
lines.push(' * this file will be overwritten.');
|
|
39
69
|
lines.push(' */');
|
|
40
70
|
lines.push(`import { defineRegistry } from '@powerhousedao/ph-clint';`);
|
|
71
|
+
// Emit imports — named imports for explicit entries, documentModels for globs.
|
|
41
72
|
for (const e of entries) {
|
|
42
|
-
|
|
73
|
+
if (e.kind === 'explicit') {
|
|
74
|
+
lines.push(`import { ${e.name} } from '${e.importFrom}';`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
lines.push(`import { documentModels as ${e.modelsAlias} } from '${e.importFrom}';`);
|
|
78
|
+
}
|
|
43
79
|
}
|
|
44
80
|
lines.push('');
|
|
45
81
|
lines.push('/**');
|
|
46
82
|
lines.push(' * Typed document registry derived from the reactor package\'s document models.');
|
|
47
|
-
lines.push(' * Regenerated whenever the spec\'s
|
|
83
|
+
lines.push(' * Regenerated whenever the spec\'s packages or document types change.');
|
|
48
84
|
lines.push(' */');
|
|
49
85
|
if (entries.length === 0) {
|
|
50
86
|
lines.push('export const registry = defineRegistry([] as const);');
|
|
51
87
|
}
|
|
52
|
-
else {
|
|
88
|
+
else if (!hasGlobs) {
|
|
89
|
+
// Pure explicit — use `as const` for full type inference.
|
|
53
90
|
lines.push('export const registry = defineRegistry([');
|
|
54
91
|
for (const e of entries) {
|
|
55
|
-
|
|
92
|
+
if (e.kind === 'explicit') {
|
|
93
|
+
lines.push(` ${e.name},`);
|
|
94
|
+
}
|
|
56
95
|
}
|
|
57
96
|
lines.push('] as const);');
|
|
58
97
|
}
|
|
98
|
+
else {
|
|
99
|
+
// Mix of explicit + glob — runtime filter loses `as const` inference.
|
|
100
|
+
lines.push('export const registry = defineRegistry([');
|
|
101
|
+
for (const e of entries) {
|
|
102
|
+
if (e.kind === 'explicit') {
|
|
103
|
+
lines.push(` ${e.name},`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
lines.push(` ...${e.modelsAlias}.filter((m) => /${e.regexSource}/.test(m.documentModel.global.id)),`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
lines.push(']);');
|
|
110
|
+
}
|
|
59
111
|
lines.push('');
|
|
60
112
|
lines.push('export type Registry = typeof registry;');
|
|
61
113
|
return lines.join('\n') + '\n';
|
|
@@ -1,6 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds `src/framework.ts` — the user-owned half of the typed-binding split.
|
|
3
|
+
*
|
|
4
|
+
* Emitted **only on create**. Once the file exists, codegen never overwrites
|
|
5
|
+
* it: users are expected to extend `configSchema` and `secretsSchema` here,
|
|
6
|
+
* and those edits must survive regens.
|
|
7
|
+
*
|
|
8
|
+
* Behavior differs by layout:
|
|
9
|
+
*
|
|
10
|
+
* - **Powerhouse enabled** — this file declares `configSchema`/`secretsSchema`
|
|
11
|
+
* and re-exports `registry`, `defineCommand`, `defineTrigger`,
|
|
12
|
+
* `defineService`, and `createDocumentChangeTrigger` from the companion
|
|
13
|
+
* `framework.gen.ts`. Adding a document type to the spec regenerates
|
|
14
|
+
* `framework.gen.ts`; this file keeps resolving its re-exports unchanged.
|
|
15
|
+
*
|
|
16
|
+
* - **Powerhouse disabled** — no reactor package exists to register modules
|
|
17
|
+
* against, so this file binds `createTypes({ configSchema })` directly and
|
|
18
|
+
* exports the typed factories from here. No `framework.gen.ts` is emitted.
|
|
19
|
+
*/
|
|
20
|
+
import { phAtLeast } from '../../spec/types.js';
|
|
1
21
|
export function buildFrameworkTs(spec) {
|
|
2
22
|
const { mastra, powerhouse } = spec.features;
|
|
3
|
-
const hasGen = powerhouse
|
|
23
|
+
const hasGen = phAtLeast(powerhouse, 'Reactor');
|
|
4
24
|
const lines = [];
|
|
5
25
|
lines.push('/**');
|
|
6
26
|
lines.push(' * Per-CLI typed framework binding.');
|
|
@@ -22,24 +42,30 @@ export function buildFrameworkTs(spec) {
|
|
|
22
42
|
}
|
|
23
43
|
lines.push('');
|
|
24
44
|
lines.push('export const configSchema = z.object({');
|
|
45
|
+
lines.push(' // @clint:begin framework-config');
|
|
25
46
|
if (mastra.enabled) {
|
|
26
|
-
|
|
47
|
+
const defaultModel = mastra.models.find(m => m.isDefault)?.id ?? 'anthropic/claude-sonnet-4-5';
|
|
48
|
+
lines.push(` model: z.string().default('${defaultModel}').describe('LLM model to use'),`, ` agentLogging: z.boolean().default(false).describe('Enable agent conversation logging'),`);
|
|
27
49
|
}
|
|
28
|
-
//
|
|
29
|
-
// Override via switchboard.port / connect.port in configureReactor() if required.
|
|
30
|
-
lines.push(' // Add your own config fields here — this file survives regens.');
|
|
50
|
+
lines.push(' // @clint:end framework-config');
|
|
31
51
|
lines.push('});');
|
|
32
52
|
lines.push('');
|
|
33
53
|
lines.push('export const secretsSchema = z.object({');
|
|
54
|
+
lines.push(' // @clint:begin framework-secrets');
|
|
34
55
|
if (mastra.enabled) {
|
|
35
|
-
|
|
56
|
+
const providers = [...new Set(mastra.models.map(m => m.id.split(/[:/]/)[0]))];
|
|
57
|
+
for (const provider of providers) {
|
|
58
|
+
const field = `${provider}ApiKey`;
|
|
59
|
+
lines.push(` ${field}: z.string().optional().describe('${provider} API key'),`);
|
|
60
|
+
}
|
|
36
61
|
}
|
|
62
|
+
lines.push(' // @clint:end framework-secrets');
|
|
37
63
|
lines.push('});');
|
|
38
64
|
lines.push('');
|
|
39
65
|
lines.push('export type Config = z.infer<typeof configSchema> &');
|
|
40
66
|
lines.push(' z.infer<typeof secretsSchema>;');
|
|
41
67
|
lines.push('');
|
|
42
|
-
lines.push('const fullConfigSchema = configSchema.
|
|
68
|
+
lines.push('const fullConfigSchema = configSchema.extend(secretsSchema.shape);');
|
|
43
69
|
lines.push('');
|
|
44
70
|
if (hasGen) {
|
|
45
71
|
lines.push('export const {');
|
|
@@ -17,8 +17,11 @@ import { buildMastraIndexTs } from './mastra-index-ts.js';
|
|
|
17
17
|
import { buildBuildSkillsScript } from './build-skills-ts.js';
|
|
18
18
|
import { buildAgentBaseMd } from './agent-base-md.js';
|
|
19
19
|
import { buildAgentTs } from './agent-ts.js';
|
|
20
|
+
import { buildDemoAgentTs } from './demo-agent-ts.js';
|
|
20
21
|
import { buildFrameworkGenTs } from './framework-gen-ts.js';
|
|
21
22
|
import { buildFrameworkTs } from './framework-ts.js';
|
|
23
|
+
import { buildManifestJson } from './manifest-json.js';
|
|
24
|
+
import { buildSmokeTestTs } from './smoke-test-ts.js';
|
|
22
25
|
import { type ClintProjectSpec } from '../../spec/types.js';
|
|
23
26
|
/**
|
|
24
27
|
* A spec-driven file builder. Returns `null` from `build` to indicate the
|
|
@@ -36,9 +39,14 @@ export interface FileBuilder {
|
|
|
36
39
|
*/
|
|
37
40
|
initOnly?: boolean;
|
|
38
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate dynamic file builders for agent profile markdown files.
|
|
44
|
+
* One file per profile in `prompts/agent-profiles/{id}.md`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getProfileFileBuilders(spec: ClintProjectSpec): FileBuilder[];
|
|
39
47
|
export declare const CLI_FILE_BUILDERS: FileBuilder[];
|
|
40
|
-
export { buildCliPackageJson, buildCliTs, buildConfigTs, buildMainTs, buildTsconfigJson, buildJestConfigJs, buildEslintConfigJs, buildGitignore, buildMastraIndexTs, buildBuildSkillsScript, buildAgentBaseMd, buildAgentTs, buildFrameworkGenTs, buildFrameworkTs, };
|
|
48
|
+
export { buildCliPackageJson, buildCliTs, buildConfigTs, buildMainTs, buildTsconfigJson, buildJestConfigJs, buildEslintConfigJs, buildGitignore, buildMastraIndexTs, buildBuildSkillsScript, buildAgentBaseMd, buildAgentTs, buildDemoAgentTs, buildFrameworkGenTs, buildFrameworkTs, buildManifestJson, buildSmokeTestTs, };
|
|
41
49
|
export { buildRootPackageJson } from './root-package-json.js';
|
|
42
|
-
export {
|
|
50
|
+
export { buildPublishConfigJs } from './publish-config-js.js';
|
|
43
51
|
export { buildReadme } from './readme-md.js';
|
|
44
52
|
export { buildAppIndexTs } from './app-index-ts.js';
|
|
@@ -17,9 +17,26 @@ import { buildMastraIndexTs } from './mastra-index-ts.js';
|
|
|
17
17
|
import { buildBuildSkillsScript } from './build-skills-ts.js';
|
|
18
18
|
import { buildAgentBaseMd } from './agent-base-md.js';
|
|
19
19
|
import { buildAgentTs } from './agent-ts.js';
|
|
20
|
+
import { buildDemoAgentTs } from './demo-agent-ts.js';
|
|
20
21
|
import { buildFrameworkGenTs } from './framework-gen-ts.js';
|
|
21
22
|
import { buildFrameworkTs } from './framework-ts.js';
|
|
23
|
+
import { buildManifestJson } from './manifest-json.js';
|
|
24
|
+
import { buildSmokeTestTs } from './smoke-test-ts.js';
|
|
25
|
+
/**
|
|
26
|
+
* Generate dynamic file builders for agent profile markdown files.
|
|
27
|
+
* One file per profile in `prompts/agent-profiles/{id}.md`.
|
|
28
|
+
*/
|
|
29
|
+
export function getProfileFileBuilders(spec) {
|
|
30
|
+
const { mastra } = spec.features;
|
|
31
|
+
if (!mastra.enabled || mastra.profiles.length === 0)
|
|
32
|
+
return [];
|
|
33
|
+
return mastra.profiles.map((profile) => ({
|
|
34
|
+
relativePath: `prompts/agent-profiles/${profile.id}.md`,
|
|
35
|
+
build: () => profile.content + '\n',
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
22
38
|
export const CLI_FILE_BUILDERS = [
|
|
39
|
+
{ relativePath: 'powerhouse.manifest.json', build: buildManifestJson },
|
|
23
40
|
{ relativePath: 'package.json', build: buildCliPackageJson },
|
|
24
41
|
{ relativePath: 'tsconfig.json', build: () => buildTsconfigJson() },
|
|
25
42
|
{ relativePath: 'jest.config.js', build: () => buildJestConfigJs() },
|
|
@@ -28,17 +45,24 @@ export const CLI_FILE_BUILDERS = [
|
|
|
28
45
|
{ relativePath: 'src/main.ts', build: () => buildMainTs() },
|
|
29
46
|
{ relativePath: 'src/cli.ts', build: buildCliTs },
|
|
30
47
|
{ relativePath: 'src/config.ts', build: buildConfigTs },
|
|
31
|
-
// User-owned
|
|
32
|
-
{ relativePath: 'src/framework.ts', build: buildFrameworkTs
|
|
48
|
+
// User-owned outside markers; generated config/secrets inside markers.
|
|
49
|
+
{ relativePath: 'src/framework.ts', build: buildFrameworkTs },
|
|
33
50
|
// Machine-owned; regenerated on every run. Null when no document types.
|
|
34
51
|
{ relativePath: 'src/framework.gen.ts', build: buildFrameworkGenTs },
|
|
35
52
|
{ relativePath: 'src/mastra/index.ts', build: buildMastraIndexTs },
|
|
36
53
|
{ relativePath: 'scripts/build-skills.ts', build: () => buildBuildSkillsScript() },
|
|
37
|
-
{
|
|
54
|
+
{
|
|
55
|
+
relativePath: 'prompts/agent-profiles/AgentBase.md',
|
|
56
|
+
build: (spec) => (spec.features.mastra.profiles.length > 0 ? null : buildAgentBaseMd(spec)),
|
|
57
|
+
},
|
|
38
58
|
{
|
|
39
59
|
relativePath: 'src/agents/agent.ts',
|
|
40
60
|
build: (spec) => (spec.features.mastra.enabled ? buildAgentTs(spec) : null),
|
|
41
61
|
},
|
|
62
|
+
{
|
|
63
|
+
relativePath: 'src/agents/demo-agent.ts',
|
|
64
|
+
build: buildDemoAgentTs,
|
|
65
|
+
},
|
|
42
66
|
// Gitkeep placeholders so directories are tracked in git when otherwise empty.
|
|
43
67
|
{ relativePath: 'src/commands/.gitkeep', build: () => '' },
|
|
44
68
|
{ relativePath: 'src/services/.gitkeep', build: () => '' },
|
|
@@ -52,10 +76,10 @@ export const CLI_FILE_BUILDERS = [
|
|
|
52
76
|
},
|
|
53
77
|
{ relativePath: 'prompts/skills-tpl/.gitkeep', build: () => '' },
|
|
54
78
|
{ relativePath: 'prompts/skills-ext/.gitkeep', build: () => '' },
|
|
55
|
-
{ relativePath: 'tests
|
|
79
|
+
{ relativePath: 'tests/smoke.test.ts', build: buildSmokeTestTs, initOnly: true },
|
|
56
80
|
];
|
|
57
|
-
export { buildCliPackageJson, buildCliTs, buildConfigTs, buildMainTs, buildTsconfigJson, buildJestConfigJs, buildEslintConfigJs, buildGitignore, buildMastraIndexTs, buildBuildSkillsScript, buildAgentBaseMd, buildAgentTs, buildFrameworkGenTs, buildFrameworkTs, };
|
|
81
|
+
export { buildCliPackageJson, buildCliTs, buildConfigTs, buildMainTs, buildTsconfigJson, buildJestConfigJs, buildEslintConfigJs, buildGitignore, buildMastraIndexTs, buildBuildSkillsScript, buildAgentBaseMd, buildAgentTs, buildDemoAgentTs, buildFrameworkGenTs, buildFrameworkTs, buildManifestJson, buildSmokeTestTs, };
|
|
58
82
|
export { buildRootPackageJson } from './root-package-json.js';
|
|
59
|
-
export {
|
|
83
|
+
export { buildPublishConfigJs } from './publish-config-js.js';
|
|
60
84
|
export { buildReadme } from './readme-md.js';
|
|
61
85
|
export { buildAppIndexTs } from './app-index-ts.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds `powerhouse.manifest.json` — a machine-readable manifest describing
|
|
3
|
+
* the CLI project's capabilities for service discovery and deployment.
|
|
4
|
+
*/
|
|
5
|
+
import { type ClintProjectSpec } from '../../spec/types.js';
|
|
6
|
+
export declare function buildManifestJson(spec: ClintProjectSpec): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds `powerhouse.manifest.json` — a machine-readable manifest describing
|
|
3
|
+
* the CLI project's capabilities for service discovery and deployment.
|
|
4
|
+
*/
|
|
5
|
+
import { getBinName, getAppPackageName, phAtLeast, } from '../../spec/types.js';
|
|
6
|
+
export function buildManifestJson(spec) {
|
|
7
|
+
const { mastra, powerhouse } = spec.features;
|
|
8
|
+
const agent = mastra.enabled
|
|
9
|
+
? {
|
|
10
|
+
id: mastra.agentId ?? spec.name,
|
|
11
|
+
name: mastra.agentName ?? spec.name,
|
|
12
|
+
description: mastra.agentDescription ?? null,
|
|
13
|
+
image: mastra.agentImage ?? null,
|
|
14
|
+
models: mastra.models.map((m) => ({ id: m.id, default: m.isDefault })),
|
|
15
|
+
}
|
|
16
|
+
: false;
|
|
17
|
+
const ph = phAtLeast(powerhouse, 'Reactor')
|
|
18
|
+
? {
|
|
19
|
+
support: powerhouse,
|
|
20
|
+
package: getAppPackageName(spec),
|
|
21
|
+
}
|
|
22
|
+
: false;
|
|
23
|
+
const manifest = {
|
|
24
|
+
type: 'clint-project',
|
|
25
|
+
features: { agent, powerhouse: ph },
|
|
26
|
+
serviceCommand: getBinName(spec),
|
|
27
|
+
proxyEnabled: spec.deployment.proxyEnabled,
|
|
28
|
+
supportedResources: spec.deployment.supportedResources,
|
|
29
|
+
};
|
|
30
|
+
return JSON.stringify(manifest, null, 2) + '\n';
|
|
31
|
+
}
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* When Mastra is off, emit a no-op placeholder so the directory still exists
|
|
5
5
|
* and `mastra dev` fails predictably rather than importing partial code.
|
|
6
|
+
*
|
|
7
|
+
* When Mastra is on with full agent config, bootstrap the CLI and re-export
|
|
8
|
+
* the configured Mastra Agent via `cli.bootstrap()`.
|
|
6
9
|
*/
|
|
7
10
|
import { type ClintProjectSpec } from '../../spec/types.js';
|
|
8
11
|
export declare function buildMastraIndexTs(spec: ClintProjectSpec): string;
|
|
@@ -1,28 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the `{PROVIDER}_API_KEY` env var name from a provider prefix
|
|
3
|
+
* (e.g. `anthropic` → `ANTHROPIC_API_KEY`).
|
|
4
|
+
*/
|
|
5
|
+
function getApiKeyEnvVar(provider) {
|
|
6
|
+
return `${provider.toUpperCase()}_API_KEY`;
|
|
7
|
+
}
|
|
1
8
|
export function buildMastraIndexTs(spec) {
|
|
2
9
|
const { mastra } = spec.features;
|
|
3
10
|
if (!mastra.enabled) {
|
|
4
11
|
return [
|
|
12
|
+
'// @clint:begin mastra-index',
|
|
5
13
|
'/**',
|
|
6
14
|
' * Mastra Studio entry point — placeholder. Enable the `mastra` feature to',
|
|
7
15
|
' * populate this file. Until then `mastra:*` scripts are effectively no-ops.',
|
|
8
16
|
' */',
|
|
9
|
-
'// @clint:begin mastra-index',
|
|
10
17
|
'export {};',
|
|
11
18
|
'// @clint:end mastra-index',
|
|
12
19
|
'',
|
|
13
20
|
].join('\n');
|
|
14
21
|
}
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
// Full agent config available — emit bootstrap-based Mastra instance
|
|
23
|
+
if (mastra.agentId && mastra.models.length > 0) {
|
|
24
|
+
const providers = [...new Set(mastra.models.map(m => m.id.split(/[:/]/)[0]))];
|
|
25
|
+
const lines = [
|
|
26
|
+
'// @clint:begin mastra-index',
|
|
27
|
+
'/**',
|
|
28
|
+
' * Mastra Studio entry point for `mastra dev` / `mastra build` / `mastra start`.',
|
|
29
|
+
' *',
|
|
30
|
+
' * Bootstraps the CLI to get the configured agent, then exports a Mastra',
|
|
31
|
+
' * instance for Studio integration.',
|
|
32
|
+
' */',
|
|
33
|
+
"import { Mastra } from '@mastra/core/mastra';",
|
|
34
|
+
"import type { Agent } from '@mastra/core/agent';",
|
|
35
|
+
"import path from 'node:path';",
|
|
36
|
+
"import { cli } from '../cli.js';",
|
|
37
|
+
"import { CLI_ROOT } from '../config.js';",
|
|
38
|
+
'',
|
|
39
|
+
"// Under `mastra dev`, CLI_ROOT points to .mastra/ (bundler output).",
|
|
40
|
+
'// The actual project root is its parent.',
|
|
41
|
+
"const projectRoot = path.basename(CLI_ROOT) === '.mastra'",
|
|
42
|
+
' ? path.dirname(CLI_ROOT)',
|
|
43
|
+
' : CLI_ROOT;',
|
|
44
|
+
'',
|
|
45
|
+
'const rt = await cli.bootstrap({ workdir: projectRoot });',
|
|
46
|
+
'',
|
|
47
|
+
];
|
|
48
|
+
// API key env bridge for Studio
|
|
49
|
+
lines.push(`// Workaround: Mastra Studio checks process.env for API keys directly.`, `// Bridge the ph-clint resolved keys so Studio's provider detection works.`);
|
|
50
|
+
for (const provider of providers) {
|
|
51
|
+
const field = `${provider}ApiKey`;
|
|
52
|
+
const envVar = getApiKeyEnvVar(provider);
|
|
53
|
+
lines.push(`{`, ` const key = rt.config.${field} as string | undefined;`, ` if (key && !process.env.${envVar}) process.env.${envVar} = key;`, `}`);
|
|
54
|
+
}
|
|
55
|
+
lines.push('');
|
|
56
|
+
lines.push('const mastraAgent = await rt.mastraAgent as Agent | undefined;', '', 'export const mastra = new Mastra({', ' agents: mastraAgent ? { [mastraAgent.id]: mastraAgent } : {},', '});', '// @clint:end mastra-index', '');
|
|
57
|
+
return lines.join('\n');
|
|
58
|
+
}
|
|
59
|
+
// Mastra enabled but no full agent config yet — placeholder
|
|
18
60
|
return [
|
|
61
|
+
'// @clint:begin mastra-index',
|
|
19
62
|
'/**',
|
|
20
63
|
' * Mastra Studio entry point for `mastra dev` / `mastra build` / `mastra start`.',
|
|
21
64
|
' *',
|
|
22
65
|
" * Re-export a configured `@mastra/core` Mastra instance from here once you",
|
|
23
66
|
" * replace the demo createAgent shim with a real Mastra Agent.",
|
|
24
67
|
' */',
|
|
25
|
-
'// @clint:begin mastra-index',
|
|
26
68
|
'export {};',
|
|
27
69
|
'// @clint:end mastra-index',
|
|
28
70
|
'',
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the root `publish.config.js`.
|
|
3
|
+
*
|
|
4
|
+
* Split-layout: a lockstep group with both app and cli packages.
|
|
5
|
+
* Single-layout: a single-package group at `.`.
|
|
6
|
+
*/
|
|
7
|
+
import { type ClintProjectSpec } from '../../spec/types.js';
|
|
8
|
+
export declare function buildPublishConfigJs(spec: ClintProjectSpec): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the root `publish.config.js`.
|
|
3
|
+
*
|
|
4
|
+
* Split-layout: a lockstep group with both app and cli packages.
|
|
5
|
+
* Single-layout: a single-package group at `.`.
|
|
6
|
+
*/
|
|
7
|
+
import { phAtLeast, getBinName, getAppFolderName, getCliFolderName, } from '../../spec/types.js';
|
|
8
|
+
export function buildPublishConfigJs(spec) {
|
|
9
|
+
const split = phAtLeast(spec.features.powerhouse, 'Reactor');
|
|
10
|
+
// The publish pipeline appends the prerelease suffix (e.g. -dev.0), so we
|
|
11
|
+
// only store the base semver (M.m.p) here.
|
|
12
|
+
const baseVersion = spec.version.replace(/-.*$/, '');
|
|
13
|
+
const binName = getBinName(spec);
|
|
14
|
+
const packages = split
|
|
15
|
+
? `[
|
|
16
|
+
{ path: '${getAppFolderName(spec)}', category: 'app' },
|
|
17
|
+
{ path: '${getCliFolderName(spec)}', category: 'cli' },
|
|
18
|
+
]`
|
|
19
|
+
: `[
|
|
20
|
+
{ path: '.', category: 'cli' },
|
|
21
|
+
]`;
|
|
22
|
+
return `// Publish config — loaded by ph-clint's publish pipeline.
|
|
23
|
+
// definePublishConfig is an identity function; a plain export is equivalent.
|
|
24
|
+
export default {
|
|
25
|
+
groups: {
|
|
26
|
+
'${binName}': {
|
|
27
|
+
version: '${baseVersion}',
|
|
28
|
+
packages: ${packages},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Builds the project README for a freshly-generated ph-clint project.
|
|
3
3
|
*/
|
|
4
|
-
import { getPackageName, } from '../../spec/types.js';
|
|
4
|
+
import { getPackageName, phAtLeast, } from '../../spec/types.js';
|
|
5
5
|
export function buildReadme(spec) {
|
|
6
6
|
const { mastra, routine, powerhouse } = spec.features;
|
|
7
|
+
const ph = powerhouse;
|
|
7
8
|
const title = getPackageName(spec);
|
|
8
9
|
const lines = [];
|
|
9
10
|
lines.push(`# ${title}`);
|
|
@@ -19,10 +20,10 @@ export function buildReadme(spec) {
|
|
|
19
20
|
lines.push('');
|
|
20
21
|
lines.push('## Enabled features');
|
|
21
22
|
lines.push('');
|
|
22
|
-
lines.push(`- **Powerhouse**: ${
|
|
23
|
-
if (
|
|
24
|
-
lines.push(` - Switchboard: ${
|
|
25
|
-
lines.push(` - Connect: ${
|
|
23
|
+
lines.push(`- **Powerhouse**: ${ph !== 'Disabled' ? `on (${ph})` : 'off'}`);
|
|
24
|
+
if (phAtLeast(ph, 'Reactor')) {
|
|
25
|
+
lines.push(` - Switchboard: ${phAtLeast(ph, 'Switchboard') ? 'on' : 'off'}`);
|
|
26
|
+
lines.push(` - Connect: ${phAtLeast(ph, 'Connect') ? 'on' : 'off'}`);
|
|
26
27
|
}
|
|
27
28
|
lines.push(`- **Mastra agent**: ${mastra.enabled ? 'on' : 'off'}`);
|
|
28
29
|
lines.push(`- **Routine loop**: ${routine.enabled ? 'on' : 'off'}`);
|
|
@@ -32,7 +33,7 @@ export function buildReadme(spec) {
|
|
|
32
33
|
lines.push('Toggle features or update metadata in `.ph/ph-clint-cli/project-spec.json`,');
|
|
33
34
|
lines.push('then re-run `ph-clint clint-project-regen` to regenerate.');
|
|
34
35
|
lines.push('');
|
|
35
|
-
if (
|
|
36
|
+
if (phAtLeast(ph, 'Reactor')) {
|
|
36
37
|
lines.push('## Split layout');
|
|
37
38
|
lines.push('');
|
|
38
39
|
lines.push(`This project is split into \`${spec.name}-cli/\` (the CLI) and \`${spec.name}-app/\` (the Powerhouse reactor package).`);
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* Uses `pnpm --prefix <dir>` for all orchestration scripts — no cwd mutation.
|
|
7
7
|
* Build order: app first, then cli (cli depends on app via `file:` dep).
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { getAppFolderName, getBinName, getCliFolderName, phAtLeast, } from '../../spec/types.js';
|
|
10
10
|
export function buildRootPackageJson(spec) {
|
|
11
|
-
const cli =
|
|
12
|
-
const app =
|
|
11
|
+
const cli = getCliFolderName(spec);
|
|
12
|
+
const app = getAppFolderName(spec);
|
|
13
13
|
const prefix = (dir, cmd) => `pnpm --prefix ${dir} ${cmd}`;
|
|
14
14
|
const both = (cmd) => `${prefix(app, cmd)} && ${prefix(cli, cmd)}`;
|
|
15
|
-
const connectEnabled = spec.features.powerhouse
|
|
15
|
+
const connectEnabled = phAtLeast(spec.features.powerhouse, 'Connect');
|
|
16
16
|
const buildScript = connectEnabled
|
|
17
|
-
? `${prefix(app, 'build')} && ${prefix(app, 'connect
|
|
17
|
+
? `${prefix(app, 'build')} && ${prefix(app, 'connect build --outDir dist/connect')} && ${prefix(cli, 'build')}`
|
|
18
18
|
: both('build');
|
|
19
19
|
const scripts = {
|
|
20
20
|
install: both('install'),
|
|
@@ -22,17 +22,16 @@ export function buildRootPackageJson(spec) {
|
|
|
22
22
|
test: both('test'),
|
|
23
23
|
dev: prefix(cli, 'dev'),
|
|
24
24
|
start: prefix(cli, 'start'),
|
|
25
|
-
lint:
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'publish:
|
|
29
|
-
'publish:staging': `${prefix(cli, 'exec ph-publish')} staging -c ./publish.config.ts`,
|
|
30
|
-
'publish:production': `${prefix(cli, 'exec ph-publish')} production -c ./publish.config.ts`,
|
|
25
|
+
lint: both('lint'),
|
|
26
|
+
'publish:dev': `${prefix(cli, 'exec ph-publish')} dev -c ../publish.config.js${connectEnabled ? ' --verify-connect' : ''}`,
|
|
27
|
+
'publish:staging': `${prefix(cli, 'exec ph-publish')} staging -c ../publish.config.js${connectEnabled ? ' --verify-connect' : ''}`,
|
|
28
|
+
'publish:production': `${prefix(cli, 'exec ph-publish')} production -c ../publish.config.js${connectEnabled ? ' --verify-connect' : ''}`,
|
|
31
29
|
};
|
|
32
30
|
const pkg = {
|
|
33
|
-
name:
|
|
31
|
+
name: spec.scope ? `${spec.scope}/${getBinName(spec)}` : getBinName(spec),
|
|
34
32
|
version: spec.version,
|
|
35
33
|
private: true,
|
|
34
|
+
type: 'module',
|
|
36
35
|
...(spec.description ? { description: spec.description } : {}),
|
|
37
36
|
scripts,
|
|
38
37
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getBinName } from '../../spec/types.js';
|
|
2
|
+
export function buildSmokeTestTs(spec) {
|
|
3
|
+
const bin = getBinName(spec);
|
|
4
|
+
return [
|
|
5
|
+
`import { describe, it, expect } from '@jest/globals';`,
|
|
6
|
+
``,
|
|
7
|
+
`describe('${bin}', () => {`,
|
|
8
|
+
` it('loads without error', async () => {`,
|
|
9
|
+
` const { cli } = await import('../src/cli.js');`,
|
|
10
|
+
` expect(cli).toBeDefined();`,
|
|
11
|
+
` });`,
|
|
12
|
+
`});`,
|
|
13
|
+
``,
|
|
14
|
+
].join('\n');
|
|
15
|
+
}
|
package/dist/codegen/exec.d.ts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
export interface RunCommandOptions {
|
|
2
|
-
cwd: string;
|
|
3
|
-
/** Override stdio; default `'inherit'`. Pass `'ignore'` for tests. */
|
|
4
|
-
stdio?: 'inherit' | 'ignore';
|
|
5
|
-
/** Extra env vars (merged with process.env). */
|
|
6
|
-
env?: Record<string, string>;
|
|
7
|
-
}
|
|
8
|
-
export interface RunCommandResult {
|
|
9
|
-
command: string;
|
|
10
|
-
args: string[];
|
|
11
|
-
cwd: string;
|
|
12
|
-
exitCode: number;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Run `command args` in `cwd`, forwarding stdio by default. Resolves to
|
|
16
|
-
* the exit code. Does NOT throw on non-zero — callers decide how to react.
|
|
17
|
-
*/
|
|
18
|
-
export declare function runCommand(command: string, args: string[], options: RunCommandOptions): Promise<RunCommandResult>;
|
|
19
1
|
/** Returns true if `command` is on PATH. */
|
|
20
2
|
export declare function hasCommandOnPath(command: string): Promise<boolean>;
|