@powerhousedao/ph-clint-cli 0.1.0-dev.53 → 0.1.0-dev.55

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.
@@ -1,85 +1 @@
1
- /**
2
- * Registry of file builders. Each entry knows its own relative path (within
3
- * the CLI sub-tree) and a function that builds its content from the spec.
4
- *
5
- * Orchestrated by `codegen/index.ts` — it walks this registry, adjusts paths
6
- * for flat vs split layouts, and writes the files.
7
- */
8
- import { buildCliPackageJson } from './cli-package-json.js';
9
- import { buildCliTs } from './cli-ts.js';
10
- import { buildConfigTs } from './config-ts.js';
11
- import { buildMainTs } from './main-ts.js';
12
- import { buildTsconfigJson } from './tsconfig-json.js';
13
- import { buildJestConfigJs } from './jest-config-js.js';
14
- import { buildEslintConfigJs } from './eslint-config-js.js';
15
- import { buildGitignore } from './gitignore.js';
16
- import { buildMastraIndexTs } from './mastra-index-ts.js';
17
- import { buildBuildSkillsScript } from './build-skills-ts.js';
18
- import { buildAgentBaseMd } from './agent-base-md.js';
19
- import { buildAgentTs } from './agent-ts.js';
20
- import { buildDemoAgentTs } from './demo-agent-ts.js';
21
- import { buildFrameworkGenTs } from './framework-gen-ts.js';
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
- }
38
- export const CLI_FILE_BUILDERS = [
39
- { relativePath: 'powerhouse.manifest.json', build: buildManifestJson },
40
- { relativePath: 'package.json', build: buildCliPackageJson },
41
- { relativePath: 'tsconfig.json', build: () => buildTsconfigJson() },
42
- { relativePath: 'jest.config.js', build: () => buildJestConfigJs() },
43
- { relativePath: 'eslint.config.js', build: () => buildEslintConfigJs() },
44
- { relativePath: '.gitignore', build: () => buildGitignore() },
45
- { relativePath: 'src/main.ts', build: () => buildMainTs() },
46
- { relativePath: 'src/cli.ts', build: buildCliTs },
47
- { relativePath: 'src/config.ts', build: buildConfigTs },
48
- // User-owned outside markers; generated config/secrets inside markers.
49
- { relativePath: 'src/framework.ts', build: buildFrameworkTs },
50
- // Machine-owned; regenerated on every run. Null when no document types.
51
- { relativePath: 'src/framework.gen.ts', build: buildFrameworkGenTs },
52
- { relativePath: 'src/mastra/index.ts', build: buildMastraIndexTs },
53
- { relativePath: 'scripts/build-skills.ts', build: () => buildBuildSkillsScript() },
54
- {
55
- relativePath: 'prompts/agent-profiles/AgentBase.md',
56
- build: (spec) => (spec.features.mastra.profiles.length > 0 ? null : buildAgentBaseMd(spec)),
57
- },
58
- {
59
- relativePath: 'src/agents/agent.ts',
60
- build: (spec) => (spec.features.mastra.enabled ? buildAgentTs(spec) : null),
61
- },
62
- {
63
- relativePath: 'src/agents/demo-agent.ts',
64
- build: buildDemoAgentTs,
65
- },
66
- // Gitkeep placeholders so directories are tracked in git when otherwise empty.
67
- { relativePath: 'src/commands/.gitkeep', build: () => '' },
68
- { relativePath: 'src/services/.gitkeep', build: () => '' },
69
- {
70
- relativePath: 'src/triggers/.gitkeep',
71
- build: (spec) => (spec.features.routine.enabled ? '' : ''),
72
- },
73
- {
74
- relativePath: 'src/agents/.gitkeep',
75
- build: (spec) => (spec.features.mastra.enabled ? null : ''),
76
- },
77
- { relativePath: 'prompts/skills-tpl/.gitkeep', build: () => '' },
78
- { relativePath: 'prompts/skills-ext/.gitkeep', build: () => '' },
79
- { relativePath: 'tests/smoke.test.ts', build: buildSmokeTestTs, initOnly: true },
80
- ];
81
- export { buildCliPackageJson, buildCliTs, buildConfigTs, buildMainTs, buildTsconfigJson, buildJestConfigJs, buildEslintConfigJs, buildGitignore, buildMastraIndexTs, buildBuildSkillsScript, buildAgentBaseMd, buildAgentTs, buildDemoAgentTs, buildFrameworkGenTs, buildFrameworkTs, buildManifestJson, buildSmokeTestTs, };
82
- export { buildRootPackageJson } from './root-package-json.js';
83
- export { buildPublishConfigJs } from './publish-config-js.js';
84
- export { buildReadme } from './readme-md.js';
85
- export { buildAppIndexTs } from './app-index-ts.js';
1
+ export { CLI_FILE_BUILDERS, getProfileFileBuilders, buildCliPackageJson, buildCliTs, buildConfigTs, buildMainTs, buildTsconfigJson, buildJestConfigJs, buildEslintConfigJs, buildGitignore, buildMastraIndexTs, buildBuildSkillsScript, buildAgentBaseMd, buildAgentTs, buildDemoAgentTs, buildFrameworkGenTs, buildFrameworkTs, buildManifestJson, buildSmokeTestTs, buildRootPackageJson, buildPublishConfigJs, buildReadme, buildAppIndexTs, } from '@powerhousedao/ph-clint-dev/codegen/builders';
@@ -1,2 +1 @@
1
- /** Returns true if `command` is on PATH. */
2
- export declare function hasCommandOnPath(command: string): Promise<boolean>;
1
+ export { hasCommandOnPath, getPhVersion, } from '@powerhousedao/ph-clint-dev/codegen/exec';
@@ -1,14 +1 @@
1
- /**
2
- * Small helpers for invoking external commands during code generation.
3
- */
4
- import { spawn } from 'node:child_process';
5
- /** Returns true if `command` is on PATH. */
6
- export async function hasCommandOnPath(command) {
7
- return new Promise((resolve) => {
8
- const child = spawn(process.platform === 'win32' ? 'where' : 'which', [command], {
9
- stdio: 'ignore',
10
- });
11
- child.once('error', () => resolve(false));
12
- child.once('close', (code) => resolve(code === 0));
13
- });
14
- }
1
+ export { hasCommandOnPath, getPhVersion, } from '@powerhousedao/ph-clint-dev/codegen/exec';
@@ -1,17 +1 @@
1
- import { type ClintProjectSpec } from '../spec/types.js';
2
- export interface GeneratedState {
3
- name: string;
4
- scope: string | undefined;
5
- cliFolderName: string;
6
- appFolderName: string;
7
- /** True once `ph init` has run successfully in the app dir. */
8
- appInitialized: boolean;
9
- }
10
- export declare function getGeneratedPath(targetDir: string): string;
11
- export declare function readGeneratedState(targetDir: string): Promise<GeneratedState | null>;
12
- export declare function writeGeneratedState(targetDir: string, state: GeneratedState): Promise<void>;
13
- /**
14
- * Derive a `GeneratedState` from a spec. The `appInitialized` flag must be
15
- * supplied by the caller (it depends on filesystem state, not the spec).
16
- */
17
- export declare function generatedStateFromSpec(spec: ClintProjectSpec, appInitialized: boolean): GeneratedState;
1
+ export { type GeneratedState, getGeneratedPath, readGeneratedState, writeGeneratedState, generatedStateFromSpec, } from '@powerhousedao/ph-clint-dev/codegen/generated';
@@ -1,49 +1 @@
1
- /**
2
- * Tracks the derived state from the last successful code generation.
3
- *
4
- * Stored at `{targetDir}/.ph/ph-clint-cli/generated.json`. Used to detect
5
- * folder renames (name/scope changes) and re-apply patches that depend on
6
- * the project identity.
7
- */
8
- import fs from 'node:fs/promises';
9
- import path from 'node:path';
10
- import { getAppFolderName, getCliFolderName, } from '../spec/types.js';
11
- const GEN_DIR = path.join('.ph', 'ph-clint-cli');
12
- const GEN_FILE = 'generated.json';
13
- export function getGeneratedPath(targetDir) {
14
- return path.join(targetDir, GEN_DIR, GEN_FILE);
15
- }
16
- export async function readGeneratedState(targetDir) {
17
- try {
18
- const raw = await fs.readFile(getGeneratedPath(targetDir), 'utf8');
19
- return JSON.parse(raw);
20
- }
21
- catch (err) {
22
- if (err &&
23
- typeof err === 'object' &&
24
- 'code' in err &&
25
- err.code === 'ENOENT') {
26
- return null;
27
- }
28
- throw err;
29
- }
30
- }
31
- export async function writeGeneratedState(targetDir, state) {
32
- const file = getGeneratedPath(targetDir);
33
- await fs.mkdir(path.dirname(file), { recursive: true });
34
- await fs.writeFile(file, JSON.stringify(state, null, 2) + '\n', 'utf8');
35
- }
36
- /**
37
- * Derive a `GeneratedState` from a spec. The `appInitialized` flag must be
38
- * supplied by the caller (it depends on filesystem state, not the spec).
39
- */
40
- export function generatedStateFromSpec(spec, appInitialized) {
41
- const split = spec.features.powerhouse !== 'Disabled';
42
- return {
43
- name: spec.name,
44
- scope: spec.scope,
45
- cliFolderName: split ? getCliFolderName(spec) : '',
46
- appFolderName: split ? getAppFolderName(spec) : '',
47
- appInitialized,
48
- };
49
- }
1
+ export { getGeneratedPath, readGeneratedState, writeGeneratedState, generatedStateFromSpec, } from '@powerhousedao/ph-clint-dev/codegen/generated';
@@ -1,6 +1 @@
1
- export type HashRecord = Record<string, string>;
2
- export declare function getHashesPath(targetDir: string): string;
3
- export declare function hashContent(content: string): string;
4
- export declare function hashFile(filePath: string): Promise<string | null>;
5
- export declare function readHashes(targetDir: string): Promise<HashRecord>;
6
- export declare function writeHashes(targetDir: string, hashes: HashRecord): Promise<void>;
1
+ export { type HashRecord, getHashesPath, hashContent, hashFile, readHashes, writeHashes, } from '@powerhousedao/ph-clint-dev/codegen/hashes';
@@ -1,60 +1 @@
1
- /**
2
- * Per-file content hashes written by the generator so subsequent runs can
3
- * detect whether a previously-generated file has been hand-edited.
4
- *
5
- * Stored at `{targetDir}/.ph/ph-clint-cli/.hashes.json` alongside the project
6
- * spec. Keys are paths relative to the project root.
7
- */
8
- import crypto from 'node:crypto';
9
- import fs from 'node:fs/promises';
10
- import path from 'node:path';
11
- const HASHES_DIR = path.join('.ph', 'ph-clint-cli');
12
- const HASHES_FILE = '.hashes.json';
13
- export function getHashesPath(targetDir) {
14
- return path.join(targetDir, HASHES_DIR, HASHES_FILE);
15
- }
16
- export function hashContent(content) {
17
- return crypto.createHash('sha256').update(content, 'utf8').digest('hex');
18
- }
19
- function isEnoent(err) {
20
- return (!!err &&
21
- typeof err === 'object' &&
22
- 'code' in err &&
23
- err.code === 'ENOENT');
24
- }
25
- export async function hashFile(filePath) {
26
- try {
27
- const content = await fs.readFile(filePath, 'utf8');
28
- return hashContent(content);
29
- }
30
- catch (err) {
31
- if (isEnoent(err))
32
- return null;
33
- throw err;
34
- }
35
- }
36
- export async function readHashes(targetDir) {
37
- try {
38
- const raw = await fs.readFile(getHashesPath(targetDir), 'utf8');
39
- const parsed = JSON.parse(raw);
40
- if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
41
- return parsed;
42
- }
43
- return {};
44
- }
45
- catch (err) {
46
- if (isEnoent(err))
47
- return {};
48
- throw err;
49
- }
50
- }
51
- export async function writeHashes(targetDir, hashes) {
52
- const file = getHashesPath(targetDir);
53
- await fs.mkdir(path.dirname(file), { recursive: true });
54
- // Sort keys for stable output across runs.
55
- const sorted = {};
56
- for (const key of Object.keys(hashes).sort()) {
57
- sorted[key] = hashes[key];
58
- }
59
- await fs.writeFile(file, JSON.stringify(sorted, null, 2) + '\n', 'utf8');
60
- }
1
+ export { getHashesPath, hashContent, hashFile, readHashes, writeHashes, } from '@powerhousedao/ph-clint-dev/codegen/hashes';
@@ -1,42 +1,11 @@
1
- import { type ClintProjectSpec } from '../spec/types.js';
2
- import { type PostGenAction } from './actions.js';
3
- export type GenerateMode = 'create' | 'update' | 'auto';
4
- export interface GenerateProjectOptions {
5
- /** Absolute path to the project root. */
6
- targetDir: string;
7
- spec: ClintProjectSpec;
8
- /** Defaults to `'auto'` — create if no persisted spec, else update. */
9
- mode?: GenerateMode;
10
- /** Create mode: allow writing into a non-empty directory. */
11
- allowNonEmpty?: boolean;
12
- /**
13
- * Update mode: overwrite user-edited files (hash-mismatch) anyway.
14
- * Also relaxes the git-dirty guard on flat → split migration.
15
- */
16
- force?: boolean;
17
- /** Optional warning sink (diagnostics, not errors). */
18
- onWarn?: (msg: string) => void;
19
- }
20
- export interface GeneratedFile {
21
- absolutePath: string;
22
- relativePath: string;
23
- }
24
- export interface GenerateProjectResult {
25
- mode: 'create' | 'update';
26
- /** Files newly written or rewritten. */
27
- files: GeneratedFile[];
28
- /** Files skipped because the user had edited them. */
29
- skipped: GeneratedFile[];
30
- /** Files removed because the new spec no longer emits them. */
31
- deleted: GeneratedFile[];
32
- /** True if a flat → split migration ran. */
33
- migrated: boolean;
34
- cliDir: string;
35
- appDir: string | null;
36
- /** Pending post-generation actions derived from what changed. */
37
- pendingActions: PostGenAction[];
38
- }
39
1
  /**
40
- * Generate / reconcile a project at `targetDir` from the given spec.
2
+ * Re-exports from @powerhousedao/ph-clint-dev/codegen with CLI_VERSION default.
41
3
  */
4
+ import { type GenerateProjectOptions as DevGenerateProjectOptions, type GenerateProjectResult, type GenerateMode, type GeneratedFile } from '@powerhousedao/ph-clint-dev/codegen';
5
+ import type { CodegenContext } from '@powerhousedao/ph-clint-dev/codegen/types';
6
+ export type { GenerateProjectResult, GenerateMode, GeneratedFile, CodegenContext };
7
+ export interface GenerateProjectOptions extends Omit<DevGenerateProjectOptions, 'context'> {
8
+ /** Codegen context; defaults to CLI_VERSION when omitted. */
9
+ context?: CodegenContext;
10
+ }
42
11
  export declare function generateProject(options: GenerateProjectOptions): Promise<GenerateProjectResult>;