Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/symphony/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
},
"dependencies": {
"@archon/core": "workspace:*",
"@archon/paths": "workspace:*"
"@archon/paths": "workspace:*",
"@octokit/rest": "^22.0.0",
"graphql-request": "^7.2.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand Down
40 changes: 40 additions & 0 deletions packages/symphony/src/cli/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bun
/**
* Thin Bun entrypoint for running the Symphony service standalone (no Archon
* HTTP server). Used for the Phase 2 manual smoke test:
*
* bun packages/symphony/src/cli/dev.ts ~/.archon/symphony.yaml
*
* Phase 3 will wire `startSymphonyService` into the Archon server process so
* this entrypoint becomes optional.
*/
import { startSymphonyService } from '../service';

async function main(): Promise<void> {
const argPath = process.argv[2];
const envPath = process.env.SYMPHONY_CONFIG;
const configPath = argPath ?? envPath;

const handle = await startSymphonyService(configPath ? { configPath } : {});

let stopping = false;
const shutdown = async (signal: string): Promise<void> => {
if (stopping) return;
stopping = true;
process.stderr.write(`\n[symphony] received ${signal}, stopping...\n`);
try {
await handle.stop();
} catch (e) {
process.stderr.write(`[symphony] stop failed: ${(e as Error).message}\n`);
}
process.exit(0);
};

process.on('SIGINT', () => void shutdown('SIGINT'));
process.on('SIGTERM', () => void shutdown('SIGTERM'));
}

main().catch((e: unknown) => {
process.stderr.write(`[symphony] fatal: ${(e as Error).message}\n`);
process.exit(1);
});
49 changes: 49 additions & 0 deletions packages/symphony/src/config/coerce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { homedir } from 'node:os';
import { isAbsolute, resolve } from 'node:path';

export function expandEnvAndHome(input: string, env: NodeJS.ProcessEnv = process.env): string {
if (typeof input !== 'string') return input;

let s = input;

if (s === '~') {
s = homedir();
} else if (s.startsWith('~/')) {
s = `${homedir()}${s.slice(1)}`;
}

s = s.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_, name) => env[name] ?? '');
s = s.replace(/(^|[^\\])\$([A-Za-z_][A-Za-z0-9_]*)/g, (_, prefix, name) => {
return `${prefix}${env[name] ?? ''}`;
});

return s;
}

/**
* Resolve `$VAR_NAME` indirection only. If the value is exactly `$VAR` or `${VAR}`,
* return the env value (or empty string when missing). Otherwise return the value as-is.
*/
export function resolveEnvIndirection(
value: unknown,
env: NodeJS.ProcessEnv = process.env
): string | undefined {
if (typeof value !== 'string') return undefined;
const trimmed = value.trim();
if (!trimmed) return '';
const m = /^\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?$/.exec(trimmed);
if (m) {
return env[m[1]] ?? '';
}
return trimmed;
}

export function resolvePath(
value: string,
baseDir: string,
env: NodeJS.ProcessEnv = process.env
): string {
const expanded = expandEnvAndHome(value, env);
if (isAbsolute(expanded)) return resolve(expanded);
return resolve(baseDir, expanded);
}
27 changes: 27 additions & 0 deletions packages/symphony/src/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Symphony runtime defaults. Only the blocks Phase 2 needs (polling,
* dispatch slots, retry backoff). Tracker defaults are per-tracker now —
* see `snapshot.ts`. The legacy agent/codex/claude blocks moved to
* per-workflow YAML inside Archon proper.
*/
export const DEFAULTS = {
polling: {
interval_ms: 30_000,
},
dispatch: {
max_concurrent: 10,
max_concurrent_by_state: {} as Record<string, number>,
retry: {
continuation_delay_ms: 1_000,
failure_base_delay_ms: 10_000,
max_backoff_ms: 300_000,
},
},
tracker: {
endpoint_linear: 'https://api.linear.app/graphql',
linear_active_states: ['Todo', 'In Progress'] as string[],
linear_terminal_states: ['Closed', 'Cancelled', 'Canceled', 'Duplicate', 'Done'] as string[],
github_active_states: ['open'] as string[],
github_terminal_states: ['closed'] as string[],
},
} as const;
38 changes: 38 additions & 0 deletions packages/symphony/src/config/parse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Symphony config parser. Wraps Bun's native YAML parser so the rest of the
* package can stay decoupled from a specific YAML library. Symphony config
* files are pure YAML (no Markdown front-matter), so this is just a thin
* wrapper with explicit error typing.
*/
export type ConfigErrorCode = 'config_parse_error' | 'config_not_a_map';

export class ConfigError extends Error {
constructor(
public readonly code: ConfigErrorCode,
message: string,
public override readonly cause?: unknown
) {
super(message);
this.name = 'ConfigError';
}
}

export function parseSymphonyConfig(content: string): Record<string, unknown> {
let parsed: unknown;
try {
parsed = Bun.YAML.parse(content);
} catch (e) {
throw new ConfigError(
'config_parse_error',
`Failed to parse symphony config YAML: ${(e as Error).message}`,
e
);
}
if (parsed === null || parsed === undefined) {
return {};
}
if (typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new ConfigError('config_not_a_map', 'symphony config must decode to a map/object');
}
return parsed as Record<string, unknown>;
}
Loading