@karmaniverous/jeeves-meta 0.15.3 → 0.15.5
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/archive/index.d.ts +10 -0
- package/dist/archive/listArchive.d.ts +12 -0
- package/dist/archive/prune.d.ts +14 -0
- package/dist/archive/readArchive.d.ts +30 -0
- package/dist/archive/readLatest.d.ts +13 -0
- package/dist/archive/snapshot.d.ts +17 -0
- package/dist/bootstrap.d.ts +15 -0
- package/dist/cache.d.ts +22 -0
- package/dist/cli/jeeves-meta/architect.md +17 -0
- package/dist/cli/jeeves-meta/index.js +811 -734
- package/dist/cli.d.ts +10 -0
- package/dist/configHotReload.d.ts +30 -0
- package/dist/configLoader.d.ts +37 -0
- package/dist/constants.d.ts +13 -0
- package/dist/customCliCommands.d.ts +13 -0
- package/dist/descriptor.d.ts +19 -0
- package/dist/discovery/buildMinimalNode.d.ts +22 -0
- package/dist/discovery/computeSummary.d.ts +17 -0
- package/dist/discovery/discoverMetas.d.ts +19 -0
- package/dist/discovery/index.d.ts +11 -0
- package/dist/discovery/listMetas.d.ts +63 -0
- package/dist/discovery/ownershipTree.d.ts +25 -0
- package/dist/discovery/scope.d.ts +47 -0
- package/dist/discovery/types.d.ts +25 -0
- package/dist/ema.d.ts +14 -0
- package/dist/errors.d.ts +15 -0
- package/dist/escapeGlob.d.ts +23 -0
- package/dist/executor/GatewayExecutor.d.ts +48 -0
- package/dist/executor/SpawnAbortedError.d.ts +9 -0
- package/dist/executor/SpawnTimeoutError.d.ts +13 -0
- package/dist/executor/index.d.ts +8 -0
- package/dist/index.d.ts +34 -1660
- package/dist/index.js +1434 -1767
- package/dist/interfaces/MetaContext.d.ts +36 -0
- package/dist/interfaces/MetaExecutor.d.ts +46 -0
- package/dist/interfaces/WatcherClient.d.ts +75 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/lock.d.ts +70 -0
- package/dist/logger/index.d.ts +27 -0
- package/dist/mtimeFilter.d.ts +26 -0
- package/dist/normalizePath.d.ts +6 -0
- package/dist/orchestrator/buildTask.d.ts +38 -0
- package/dist/orchestrator/contextPackage.d.ts +30 -0
- package/dist/orchestrator/index.d.ts +10 -0
- package/dist/orchestrator/orchestratePhase.d.ts +38 -0
- package/dist/orchestrator/parseOutput.d.ts +41 -0
- package/dist/orchestrator/runPhase.d.ts +40 -0
- package/dist/phaseState/derivePhaseState.d.ts +41 -0
- package/dist/phaseState/index.d.ts +9 -0
- package/dist/phaseState/invalidate.d.ts +41 -0
- package/dist/phaseState/phaseScheduler.d.ts +57 -0
- package/dist/phaseState/phaseTransitions.d.ts +83 -0
- package/dist/progress/index.d.ts +38 -0
- package/dist/prompts/architect.md +17 -0
- package/dist/prompts/index.d.ts +15 -0
- package/dist/queue/index.d.ts +131 -0
- package/dist/readMetaJson.d.ts +17 -0
- package/dist/routes/__testUtils.d.ts +37 -0
- package/dist/routes/config.d.ts +11 -0
- package/dist/routes/configApply.d.ts +13 -0
- package/dist/routes/index.d.ts +50 -0
- package/dist/routes/metas.d.ts +9 -0
- package/dist/routes/metasUpdate.d.ts +11 -0
- package/dist/routes/preview.d.ts +8 -0
- package/dist/routes/queue.d.ts +13 -0
- package/dist/routes/seed.d.ts +8 -0
- package/dist/routes/status.d.ts +13 -0
- package/dist/routes/synthesize.d.ts +12 -0
- package/dist/routes/unlock.d.ts +8 -0
- package/dist/rules/healthCheck.d.ts +36 -0
- package/dist/rules/index.d.ts +39 -0
- package/dist/rules/verify.d.ts +22 -0
- package/dist/scheduler/index.d.ts +66 -0
- package/dist/scheduling/index.d.ts +7 -0
- package/dist/scheduling/staleness.d.ts +68 -0
- package/dist/scheduling/weightedFormula.d.ts +38 -0
- package/dist/schema/config.d.ts +54 -0
- package/dist/schema/error.d.ts +6 -0
- package/dist/schema/index.d.ts +8 -0
- package/dist/schema/meta.d.ts +71 -0
- package/dist/seed/autoSeed.d.ts +30 -0
- package/dist/seed/createMeta.d.ts +38 -0
- package/dist/seed/index.d.ts +7 -0
- package/dist/server.d.ts +24 -0
- package/dist/shutdown/index.d.ts +33 -0
- package/dist/structureHash.d.ts +15 -0
- package/dist/watcher-client/HttpWatcherClient.d.ts +38 -0
- package/dist/watcher-client/index.d.ts +6 -0
- package/package.json +17 -27
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-cycle context package computed by the orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Shared inputs that multiple subprocesses need are computed once
|
|
5
|
+
* and serialized into each subprocess's task prompt.
|
|
6
|
+
*
|
|
7
|
+
* @module interfaces/MetaContext
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Context package for a single synthesis cycle.
|
|
11
|
+
*
|
|
12
|
+
* The orchestrator computes this once per cycle from the meta path,
|
|
13
|
+
* ownership tree, watcher walk results, and filesystem reads.
|
|
14
|
+
*/
|
|
15
|
+
export interface MetaContext {
|
|
16
|
+
/** Absolute path to the .meta directory. */
|
|
17
|
+
path: string;
|
|
18
|
+
/** All files in scope (absolute paths). */
|
|
19
|
+
scopeFiles: string[];
|
|
20
|
+
/** Files changed since _generatedAt (absolute paths). */
|
|
21
|
+
deltaFiles: string[];
|
|
22
|
+
/** Child _content outputs, keyed by relative path. */
|
|
23
|
+
childMetas: Record<string, unknown>;
|
|
24
|
+
/** Cross-referenced meta _content outputs, keyed by owner path. */
|
|
25
|
+
crossRefMetas: Record<string, unknown>;
|
|
26
|
+
/** _content from the last cycle, or null on first run. */
|
|
27
|
+
previousContent: string | null;
|
|
28
|
+
/** _feedback from the last cycle, or null on first run. */
|
|
29
|
+
previousFeedback: string | null;
|
|
30
|
+
/** Current _steer value, or null if unset. */
|
|
31
|
+
steer: string | null;
|
|
32
|
+
/** _state from the last cycle, or null on first run. */
|
|
33
|
+
previousState: unknown;
|
|
34
|
+
/** Archive snapshot file paths (for steer change detection, etc.). */
|
|
35
|
+
archives: string[];
|
|
36
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable executor interface for LLM subprocess invocation.
|
|
3
|
+
*
|
|
4
|
+
* @module interfaces/MetaExecutor
|
|
5
|
+
*/
|
|
6
|
+
/** Options for spawning a synthesis subprocess. */
|
|
7
|
+
export interface MetaSpawnOptions {
|
|
8
|
+
/** Model override for this subprocess. */
|
|
9
|
+
model?: string;
|
|
10
|
+
/** Timeout in seconds. */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Label for the spawned session. */
|
|
13
|
+
label?: string;
|
|
14
|
+
/** Thinking level (e.g. "low", "medium", "high"). */
|
|
15
|
+
thinking?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Result of a spawn call, including optional token usage. */
|
|
18
|
+
export interface MetaSpawnResult {
|
|
19
|
+
/** Subprocess output text. */
|
|
20
|
+
output: string;
|
|
21
|
+
/** Token count for this call, if available from the executor. */
|
|
22
|
+
tokens?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Interface for spawning synthesis subprocesses.
|
|
26
|
+
*
|
|
27
|
+
* The executor abstracts the LLM invocation mechanism. The orchestrator
|
|
28
|
+
* calls spawn() sequentially for architect, builder, and critic steps.
|
|
29
|
+
* Each call blocks until the subprocess completes and returns its result.
|
|
30
|
+
*/
|
|
31
|
+
export interface MetaExecutor {
|
|
32
|
+
/**
|
|
33
|
+
* Spawn a subprocess with the given task prompt.
|
|
34
|
+
*
|
|
35
|
+
* @param task - Full task prompt for the subprocess.
|
|
36
|
+
* @param options - Optional model and timeout overrides.
|
|
37
|
+
* @returns The subprocess result with output and optional token count.
|
|
38
|
+
*/
|
|
39
|
+
spawn(task: string, options?: MetaSpawnOptions): Promise<MetaSpawnResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the executor has been aborted by the operator.
|
|
42
|
+
* When true, runPhase catch blocks should skip persisting _error
|
|
43
|
+
* because the abort route has already written the correct state.
|
|
44
|
+
*/
|
|
45
|
+
readonly aborted?: boolean;
|
|
46
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstraction over the jeeves-watcher HTTP API.
|
|
3
|
+
*
|
|
4
|
+
* The service uses this for filesystem enumeration (POST /walk),
|
|
5
|
+
* virtual rule registration (POST /rules/register), and archive reads
|
|
6
|
+
* via filter-only point scans (POST /scan).
|
|
7
|
+
*
|
|
8
|
+
* @module interfaces/WatcherClient
|
|
9
|
+
*/
|
|
10
|
+
/** An inference rule to register with the watcher. */
|
|
11
|
+
export interface InferenceRuleSpec {
|
|
12
|
+
/** Rule name. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Rule description. */
|
|
15
|
+
description: string;
|
|
16
|
+
/** JSON Schema match criteria. */
|
|
17
|
+
match: Record<string, unknown>;
|
|
18
|
+
/** Schema array with set keywords. */
|
|
19
|
+
schema: unknown[];
|
|
20
|
+
/** Declarative render config. */
|
|
21
|
+
render?: Record<string, unknown>;
|
|
22
|
+
/** Handlebars template name. */
|
|
23
|
+
template?: string;
|
|
24
|
+
/** Render output format. */
|
|
25
|
+
renderAs?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Request shape for watcher scan queries. */
|
|
28
|
+
export interface WatcherScanRequest {
|
|
29
|
+
filter: Record<string, unknown>;
|
|
30
|
+
limit?: number;
|
|
31
|
+
cursor?: string;
|
|
32
|
+
fields?: string[];
|
|
33
|
+
countOnly?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** A single point returned from watcher scan. */
|
|
36
|
+
export interface WatcherScanPoint {
|
|
37
|
+
id?: string | number;
|
|
38
|
+
payload?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/** Response shape for watcher scan queries. */
|
|
41
|
+
export interface WatcherScanResult {
|
|
42
|
+
points: WatcherScanPoint[];
|
|
43
|
+
cursor: string | null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Interface for watcher HTTP operations.
|
|
47
|
+
*
|
|
48
|
+
* Implementations handle retry with backoff internally.
|
|
49
|
+
*/
|
|
50
|
+
export interface WatcherClient {
|
|
51
|
+
/**
|
|
52
|
+
* Register virtual inference rules with the watcher.
|
|
53
|
+
*
|
|
54
|
+
* @param source - Source identifier (e.g. 'jeeves-meta').
|
|
55
|
+
* @param rules - Array of inference rules to register.
|
|
56
|
+
*/
|
|
57
|
+
registerRules(source: string, rules: InferenceRuleSpec[]): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Walk filesystem using glob patterns.
|
|
60
|
+
*
|
|
61
|
+
* @param globs - Array of glob patterns to match against.
|
|
62
|
+
* @returns Promise resolving to array of matching file paths.
|
|
63
|
+
*/
|
|
64
|
+
walk(globs: string[]): Promise<string[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Run a filter-only point scan against the watcher index.
|
|
67
|
+
*
|
|
68
|
+
* Optional so narrow test doubles do not need to implement archive-read
|
|
69
|
+
* support unless a test exercises that path.
|
|
70
|
+
*
|
|
71
|
+
* @param request - Scan filter, pagination, and projection options.
|
|
72
|
+
* @returns Matching points and the next cursor.
|
|
73
|
+
*/
|
|
74
|
+
scan?(request: WatcherScanRequest): Promise<WatcherScanResult>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports for all interface modules.
|
|
3
|
+
*
|
|
4
|
+
* @module interfaces
|
|
5
|
+
*/
|
|
6
|
+
export type { MetaContext } from './MetaContext.js';
|
|
7
|
+
export type { MetaExecutor, MetaSpawnOptions, MetaSpawnResult, } from './MetaExecutor.js';
|
|
8
|
+
export type { InferenceRuleSpec, WatcherClient, WatcherScanPoint, WatcherScanRequest, WatcherScanResult, } from './WatcherClient.js';
|
package/dist/lock.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File-system lock for preventing concurrent synthesis on the same meta.
|
|
3
|
+
*
|
|
4
|
+
* Lock file: .meta/.lock containing `_lockPid` + `_lockStartedAt` (underscore-prefixed
|
|
5
|
+
* reserved keys, consistent with meta.json conventions).
|
|
6
|
+
* Stale timeout: 30 minutes.
|
|
7
|
+
*
|
|
8
|
+
* @module lock
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Resolve a path to a .meta directory.
|
|
12
|
+
*
|
|
13
|
+
* If the path already ends with '.meta', returns it as-is.
|
|
14
|
+
* Otherwise, appends '.meta' as a subdirectory.
|
|
15
|
+
*
|
|
16
|
+
* @param inputPath - Path that may or may not end with '.meta'.
|
|
17
|
+
* @returns The resolved .meta directory path.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveMetaDir(inputPath: string): string;
|
|
20
|
+
/** Parsed state of a .lock file. */
|
|
21
|
+
export interface LockState {
|
|
22
|
+
/** Whether the lock file exists. */
|
|
23
|
+
exists: boolean;
|
|
24
|
+
/** Whether the lock contains a staged synthesis result. */
|
|
25
|
+
staged: boolean;
|
|
26
|
+
/** Whether the lock is actively held (non-stale PID lock). */
|
|
27
|
+
active: boolean;
|
|
28
|
+
/** Raw parsed data, or null if missing/corrupt. */
|
|
29
|
+
data: Record<string, unknown> | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Read and classify the state of a .meta/.lock file.
|
|
33
|
+
*
|
|
34
|
+
* @param metaPath - Absolute path to the .meta directory.
|
|
35
|
+
* @returns Parsed lock state.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readLockState(metaPath: string): LockState;
|
|
38
|
+
/**
|
|
39
|
+
* Attempt to acquire a lock on a .meta directory.
|
|
40
|
+
*
|
|
41
|
+
* @param metaPath - Absolute path to the .meta directory.
|
|
42
|
+
* @returns True if lock was acquired, false if already locked (non-stale).
|
|
43
|
+
*/
|
|
44
|
+
export declare function acquireLock(metaPath: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Release a lock on a .meta directory.
|
|
47
|
+
*
|
|
48
|
+
* @param metaPath - Absolute path to the .meta directory.
|
|
49
|
+
*/
|
|
50
|
+
export declare function releaseLock(metaPath: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Check if a .meta directory is currently locked (non-stale).
|
|
53
|
+
*
|
|
54
|
+
* @param metaPath - Absolute path to the .meta directory.
|
|
55
|
+
* @returns True if locked and not stale.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isLocked(metaPath: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Clean up stale lock files on startup.
|
|
60
|
+
*
|
|
61
|
+
* For each .meta directory found via the provided paths:
|
|
62
|
+
* - If lock contains PID-only data (synthesis incomplete), delete it.
|
|
63
|
+
* - If lock contains staged result (_id present), log warning and delete.
|
|
64
|
+
*
|
|
65
|
+
* @param metaPaths - Array of .meta directory paths to check.
|
|
66
|
+
* @param logger - Optional logger for warnings.
|
|
67
|
+
*/
|
|
68
|
+
export declare function cleanupStaleLocks(metaPaths: string[], logger?: {
|
|
69
|
+
warn: (obj: Record<string, unknown>, msg: string) => void;
|
|
70
|
+
}): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pino logger factory.
|
|
3
|
+
*
|
|
4
|
+
* @module logger
|
|
5
|
+
*/
|
|
6
|
+
import pino from 'pino';
|
|
7
|
+
/** Minimal logger interface accepted by library functions. */
|
|
8
|
+
export interface MinimalLogger {
|
|
9
|
+
debug: (obj: Record<string, unknown>, msg: string) => void;
|
|
10
|
+
info: (obj: Record<string, unknown>, msg: string) => void;
|
|
11
|
+
warn: (obj: Record<string, unknown>, msg: string) => void;
|
|
12
|
+
error: (obj: Record<string, unknown>, msg: string) => void;
|
|
13
|
+
}
|
|
14
|
+
/** Logger configuration options. */
|
|
15
|
+
export interface LoggerConfig {
|
|
16
|
+
/** Log level (default: 'info'). */
|
|
17
|
+
level?: string;
|
|
18
|
+
/** Optional file path to write logs to. */
|
|
19
|
+
file?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a pino logger instance.
|
|
23
|
+
*
|
|
24
|
+
* @param config - Optional logger configuration.
|
|
25
|
+
* @returns Configured pino logger.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createLogger(config?: LoggerConfig): pino.Logger;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter file paths by modification time.
|
|
3
|
+
*
|
|
4
|
+
* Shared utility for staleness detection and delta file enumeration.
|
|
5
|
+
* Uses `fs.statSync` for fast local mtime checks on known paths.
|
|
6
|
+
*
|
|
7
|
+
* @module mtimeFilter
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Check if any file in the list was modified after the given timestamp.
|
|
11
|
+
*
|
|
12
|
+
* Short-circuits on first match for efficiency (staleness checks).
|
|
13
|
+
*
|
|
14
|
+
* @param files - Array of file paths to check.
|
|
15
|
+
* @param afterMs - Timestamp in milliseconds. Files with `mtimeMs > afterMs` match.
|
|
16
|
+
* @returns True if any file was modified after the timestamp.
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasModifiedAfter(files: string[], afterMs: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Filter files to only those modified after the given timestamp.
|
|
21
|
+
*
|
|
22
|
+
* @param files - Array of file paths to filter.
|
|
23
|
+
* @param afterMs - Timestamp in milliseconds. Files with `mtimeMs > afterMs` are included.
|
|
24
|
+
* @returns Filtered array of file paths.
|
|
25
|
+
*/
|
|
26
|
+
export declare function filterModifiedAfter(files: string[], afterMs: number): string[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build task prompts for each synthesis step.
|
|
3
|
+
*
|
|
4
|
+
* Prompts are compiled as Handlebars templates with access to config,
|
|
5
|
+
* meta, and scope context. The architect can write template expressions
|
|
6
|
+
* into its _builder output; these resolve when the builder task is compiled.
|
|
7
|
+
*
|
|
8
|
+
* @module orchestrator/buildTask
|
|
9
|
+
*/
|
|
10
|
+
import type { MetaContext } from '../interfaces/index.js';
|
|
11
|
+
import type { MetaConfig, MetaJson } from '../schema/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Build the architect task prompt.
|
|
14
|
+
*
|
|
15
|
+
* @param ctx - Synthesis context.
|
|
16
|
+
* @param meta - Current meta.json.
|
|
17
|
+
* @param config - Synthesis config.
|
|
18
|
+
* @returns The architect task prompt string.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildArchitectTask(ctx: MetaContext, meta: MetaJson, config: MetaConfig): string;
|
|
21
|
+
/**
|
|
22
|
+
* Build the builder task prompt.
|
|
23
|
+
*
|
|
24
|
+
* @param ctx - Synthesis context.
|
|
25
|
+
* @param meta - Current meta.json.
|
|
26
|
+
* @param config - Synthesis config.
|
|
27
|
+
* @returns The builder task prompt string.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildBuilderTask(ctx: MetaContext, meta: MetaJson, config: MetaConfig): string;
|
|
30
|
+
/**
|
|
31
|
+
* Build the critic task prompt.
|
|
32
|
+
*
|
|
33
|
+
* @param ctx - Synthesis context.
|
|
34
|
+
* @param meta - Current meta.json (with _content already set by builder).
|
|
35
|
+
* @param config - Synthesis config.
|
|
36
|
+
* @returns The critic task prompt string.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildCriticTask(ctx: MetaContext, meta: MetaJson, config: MetaConfig): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the MetaContext for a synthesis cycle.
|
|
3
|
+
*
|
|
4
|
+
* Computes shared inputs once: scope files, delta files, child meta outputs,
|
|
5
|
+
* previous content/feedback, steer, and archive paths.
|
|
6
|
+
*
|
|
7
|
+
* @module orchestrator/contextPackage
|
|
8
|
+
*/
|
|
9
|
+
import { type MetaNode } from '../discovery/index.js';
|
|
10
|
+
import type { MetaContext, WatcherClient } from '../interfaces/index.js';
|
|
11
|
+
import type { MinimalLogger } from '../logger/index.js';
|
|
12
|
+
import type { MetaJson } from '../schema/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* Condense a file list into glob-like summaries.
|
|
15
|
+
* Groups by directory + extension pattern.
|
|
16
|
+
*
|
|
17
|
+
* @param files - Array of file paths.
|
|
18
|
+
* @param maxIndividual - Show individual files up to this count.
|
|
19
|
+
* @returns Condensed summary string.
|
|
20
|
+
*/
|
|
21
|
+
export declare function condenseScopeFiles(files: string[], maxIndividual?: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Build the context package for a synthesis cycle.
|
|
24
|
+
*
|
|
25
|
+
* @param node - The meta node being synthesized.
|
|
26
|
+
* @param meta - Current meta.json content.
|
|
27
|
+
* @param watcher - WatcherClient for scope enumeration.
|
|
28
|
+
* @returns The computed context package.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildContextPackage(node: MetaNode, meta: MetaJson, watcher: WatcherClient, logger?: MinimalLogger): Promise<MetaContext>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orchestrator module — the main synthesis cycle.
|
|
3
|
+
*
|
|
4
|
+
* @module orchestrator
|
|
5
|
+
*/
|
|
6
|
+
export { buildArchitectTask, buildBuilderTask, buildCriticTask, } from './buildTask.js';
|
|
7
|
+
export { buildContextPackage } from './contextPackage.js';
|
|
8
|
+
export { orchestratePhase, type OrchestratePhaseResult, type PhaseProgressCallback, } from './orchestratePhase.js';
|
|
9
|
+
export { type BuilderOutput, parseArchitectOutput, parseBuilderOutput, parseCriticOutput, } from './parseOutput.js';
|
|
10
|
+
export { type PhaseResult, runArchitect, runBuilder, runCritic, } from './runPhase.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase-aware orchestration entry point.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the old staleness-based orchestrate() with phase-state-machine
|
|
5
|
+
* scheduling: each tick discovers all metas, computes invalidation,
|
|
6
|
+
* auto-retries failed phases, selects the best phase candidate, and
|
|
7
|
+
* executes exactly one phase.
|
|
8
|
+
*
|
|
9
|
+
* @module orchestrator/orchestratePhase
|
|
10
|
+
*/
|
|
11
|
+
import type { MetaExecutor, WatcherClient } from '../interfaces/index.js';
|
|
12
|
+
import type { MinimalLogger } from '../logger/index.js';
|
|
13
|
+
import type { ProgressEvent } from '../progress/index.js';
|
|
14
|
+
import type { MetaConfig, PhaseName } from '../schema/index.js';
|
|
15
|
+
import { type PhaseResult } from './runPhase.js';
|
|
16
|
+
/** Callback for synthesis progress events. */
|
|
17
|
+
export type PhaseProgressCallback = (event: ProgressEvent) => void | Promise<void>;
|
|
18
|
+
/** Result of a single phase-aware orchestration tick. */
|
|
19
|
+
export interface OrchestratePhaseResult {
|
|
20
|
+
/** Whether a phase was executed. */
|
|
21
|
+
executed: boolean;
|
|
22
|
+
/** Path to the meta that was selected. */
|
|
23
|
+
metaPath?: string;
|
|
24
|
+
/** Which phase was run. */
|
|
25
|
+
phase?: PhaseName;
|
|
26
|
+
/** The phase result (if executed). */
|
|
27
|
+
phaseResult?: PhaseResult;
|
|
28
|
+
/** Whether a full synthesis cycle completed (all phases fresh). */
|
|
29
|
+
cycleComplete?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Run a single phase-aware orchestration tick.
|
|
33
|
+
*
|
|
34
|
+
* When targetPath is provided (override entry), runs the owed phase for
|
|
35
|
+
* that specific meta. Otherwise, discovers all metas, computes invalidation,
|
|
36
|
+
* and selects the best phase candidate corpus-wide.
|
|
37
|
+
*/
|
|
38
|
+
export declare function orchestratePhase(config: MetaConfig, executor: MetaExecutor, watcher: WatcherClient, targetPath?: string, onProgress?: PhaseProgressCallback, logger?: MinimalLogger): Promise<OrchestratePhaseResult>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse subprocess outputs for each synthesis step.
|
|
3
|
+
*
|
|
4
|
+
* - Architect: returns text \> _builder
|
|
5
|
+
* - Builder: returns JSON \> _content + structured fields
|
|
6
|
+
* - Critic: returns text \> _feedback
|
|
7
|
+
*
|
|
8
|
+
* @module orchestrator/parseOutput
|
|
9
|
+
*/
|
|
10
|
+
/** Parsed builder output. */
|
|
11
|
+
export interface BuilderOutput {
|
|
12
|
+
/** Narrative synthesis content. */
|
|
13
|
+
content: string;
|
|
14
|
+
/** Additional structured fields (non-underscore keys). */
|
|
15
|
+
fields: Record<string, unknown>;
|
|
16
|
+
/** Opaque state for progressive synthesis, if provided by the builder. */
|
|
17
|
+
state?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse architect output. The architect returns a task brief as text.
|
|
21
|
+
*
|
|
22
|
+
* @param output - Raw subprocess output.
|
|
23
|
+
* @returns The task brief string.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseArchitectOutput(output: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Parse builder output. The builder returns JSON with _content and optional fields.
|
|
28
|
+
*
|
|
29
|
+
* Attempts JSON parse first. If that fails, treats the entire output as _content.
|
|
30
|
+
*
|
|
31
|
+
* @param output - Raw subprocess output.
|
|
32
|
+
* @returns Parsed builder output with content and structured fields.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseBuilderOutput(output: string): BuilderOutput;
|
|
35
|
+
/**
|
|
36
|
+
* Parse critic output. The critic returns evaluation text.
|
|
37
|
+
*
|
|
38
|
+
* @param output - Raw subprocess output.
|
|
39
|
+
* @returns The feedback string.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseCriticOutput(output: string): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-phase executors for the phase-state machine.
|
|
3
|
+
*
|
|
4
|
+
* Each function runs exactly one phase on one meta, updates _phaseState
|
|
5
|
+
* via pure transitions, and persists via the lock-staged write.
|
|
6
|
+
*
|
|
7
|
+
* @module orchestrator/runPhase
|
|
8
|
+
*/
|
|
9
|
+
import type { MetaNode } from '../discovery/index.js';
|
|
10
|
+
import type { MetaExecutor, WatcherClient } from '../interfaces/index.js';
|
|
11
|
+
import type { MinimalLogger } from '../logger/index.js';
|
|
12
|
+
import type { ProgressEvent } from '../progress/index.js';
|
|
13
|
+
import type { MetaConfig, MetaError, MetaJson, PhaseState } from '../schema/index.js';
|
|
14
|
+
/** Callback for synthesis progress events. */
|
|
15
|
+
export type ProgressCallback = (event: ProgressEvent) => void | Promise<void>;
|
|
16
|
+
/** Result of running a single phase. */
|
|
17
|
+
export interface PhaseResult {
|
|
18
|
+
/** Whether the phase executed (vs. was skipped). */
|
|
19
|
+
executed: boolean;
|
|
20
|
+
/** Updated phase state after execution. */
|
|
21
|
+
phaseState: PhaseState;
|
|
22
|
+
/** Updated meta.json content (if written). */
|
|
23
|
+
updatedMeta?: MetaJson;
|
|
24
|
+
/** Error if the phase failed. */
|
|
25
|
+
error?: MetaError;
|
|
26
|
+
/** Whether the full cycle is now complete (all phases fresh). */
|
|
27
|
+
cycleComplete?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Shared base options for all finalize calls. */
|
|
30
|
+
export interface FinalizeBase {
|
|
31
|
+
metaPath: string;
|
|
32
|
+
current: MetaJson;
|
|
33
|
+
config: MetaConfig;
|
|
34
|
+
structureHash: string;
|
|
35
|
+
}
|
|
36
|
+
/** Write updated meta with phase state via lock staging. */
|
|
37
|
+
export declare function persistPhaseState(base: FinalizeBase, phaseState: PhaseState, updates: Partial<MetaJson>): Promise<MetaJson>;
|
|
38
|
+
export declare function runArchitect(node: MetaNode, currentMeta: MetaJson, phaseState: PhaseState, config: MetaConfig, executor: MetaExecutor, watcher: WatcherClient, structureHash: string, onProgress?: ProgressCallback, logger?: MinimalLogger): Promise<PhaseResult>;
|
|
39
|
+
export declare function runBuilder(node: MetaNode, currentMeta: MetaJson, phaseState: PhaseState, config: MetaConfig, executor: MetaExecutor, watcher: WatcherClient, structureHash: string, onProgress?: ProgressCallback, logger?: MinimalLogger): Promise<PhaseResult>;
|
|
40
|
+
export declare function runCritic(node: MetaNode, currentMeta: MetaJson, phaseState: PhaseState, config: MetaConfig, executor: MetaExecutor, watcher: WatcherClient, structureHash: string, onProgress?: ProgressCallback, logger?: MinimalLogger): Promise<PhaseResult>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backward-compatible derivation of _phaseState from existing meta fields.
|
|
3
|
+
*
|
|
4
|
+
* When a meta is loaded from disk without _phaseState, this reconstructs
|
|
5
|
+
* the phase state from _content, _builder, _state, _error.step, and
|
|
6
|
+
* the architect-invalidating inputs.
|
|
7
|
+
*
|
|
8
|
+
* @module phaseState/derivePhaseState
|
|
9
|
+
*/
|
|
10
|
+
import type { MetaJson, PhaseState } from '../schema/index.js';
|
|
11
|
+
/** Inputs needed to determine architect invalidation for derivation. */
|
|
12
|
+
export interface DerivationInputs {
|
|
13
|
+
/** Whether _structureHash has changed vs. computed value. */
|
|
14
|
+
structureChanged: boolean;
|
|
15
|
+
/** Whether _steer changed vs. latest archive. */
|
|
16
|
+
steerChanged: boolean;
|
|
17
|
+
/** Whether _architect prompt changed. */
|
|
18
|
+
architectChanged: boolean;
|
|
19
|
+
/** Whether _crossRefs declaration changed. */
|
|
20
|
+
crossRefsChanged: boolean;
|
|
21
|
+
/** architectEvery config value. */
|
|
22
|
+
architectEvery: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Derive _phaseState from existing meta fields.
|
|
26
|
+
*
|
|
27
|
+
* If the meta already has _phaseState, returns it as-is.
|
|
28
|
+
*
|
|
29
|
+
* Otherwise, reconstructs from available fields:
|
|
30
|
+
* - Never-synthesized meta (no _content, no _builder): all phases start pending/stale.
|
|
31
|
+
* - Errored meta: the failed phase is mapped from _error.step.
|
|
32
|
+
* - Mid-cycle meta with cached _builder but no _content: builder pending.
|
|
33
|
+
* - Fully-fresh meta: all phases fresh.
|
|
34
|
+
* - Meta with stale architect inputs: architect pending, downstream stale.
|
|
35
|
+
*
|
|
36
|
+
* @param meta - The meta.json content.
|
|
37
|
+
* @param inputs - Optional derivation inputs. If not provided, a simpler
|
|
38
|
+
* heuristic is used (no architect invalidation check).
|
|
39
|
+
* @returns The derived PhaseState.
|
|
40
|
+
*/
|
|
41
|
+
export declare function derivePhaseState(meta: MetaJson, inputs?: DerivationInputs): PhaseState;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase-state machine module.
|
|
3
|
+
*
|
|
4
|
+
* @module phaseState
|
|
5
|
+
*/
|
|
6
|
+
export { type DerivationInputs, derivePhaseState } from './derivePhaseState.js';
|
|
7
|
+
export { type ArchitectInvalidator, computeInvalidation, type InvalidationResult, type StalenessInputs, } from './invalidate.js';
|
|
8
|
+
export { buildPhaseCandidates, type PhaseCandidate, type PhaseCandidateInput, rankPhaseCandidates, selectPhaseCandidate, } from './phaseScheduler.js';
|
|
9
|
+
export { architectSuccess, builderSuccess, criticSuccess, enforceInvariant, freshPhaseState, getOwedPhase, getPriorityBand, initialPhaseState, invalidateArchitect, invalidateBuilder, isFullyFresh, phaseFailed, phaseRunning, retryAllFailed, retryPhase, } from './phaseTransitions.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-tick invalidation pass.
|
|
3
|
+
*
|
|
4
|
+
* Computes architect-invalidating and builder-invalidating inputs for a meta,
|
|
5
|
+
* then applies the cascade to update _phaseState.
|
|
6
|
+
*
|
|
7
|
+
* @module phaseState/invalidate
|
|
8
|
+
*/
|
|
9
|
+
import type { MetaNode } from '../discovery/types.js';
|
|
10
|
+
import type { MetaConfig, MetaJson, PhaseState } from '../schema/index.js';
|
|
11
|
+
/** Architect-level invalidation reasons. */
|
|
12
|
+
export type ArchitectInvalidator = 'structureHash' | 'steer' | '_architect' | '_crossRefs' | 'architectEvery';
|
|
13
|
+
/** Staleness inputs for a meta (exposed in /preview). */
|
|
14
|
+
export interface StalenessInputs {
|
|
15
|
+
structureHash: string;
|
|
16
|
+
steerChanged: boolean;
|
|
17
|
+
architectChanged: boolean;
|
|
18
|
+
crossRefsDeclChanged: boolean;
|
|
19
|
+
scopeMtimeMax: string | null;
|
|
20
|
+
crossRefContentChanged: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Result of computing invalidation for a single meta. */
|
|
23
|
+
export interface InvalidationResult {
|
|
24
|
+
phaseState: PhaseState;
|
|
25
|
+
architectInvalidators: ArchitectInvalidator[];
|
|
26
|
+
stalenessInputs: StalenessInputs;
|
|
27
|
+
structureHash: string;
|
|
28
|
+
steerChanged: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Compute invalidation inputs and apply cascade for a single meta.
|
|
32
|
+
*
|
|
33
|
+
* @param meta - Current meta.json content with existing _phaseState.
|
|
34
|
+
* @param scopeFiles - Sorted file list from scope.
|
|
35
|
+
* @param config - MetaConfig for architectEvery.
|
|
36
|
+
* @param node - MetaNode for archive access.
|
|
37
|
+
* @param crossRefMetas - Map of cross-ref owner paths to their current _content.
|
|
38
|
+
* @param archiveCrossRefContent - Map of cross-ref owner paths to their archived _content.
|
|
39
|
+
* @returns Updated phase state and invalidation details.
|
|
40
|
+
*/
|
|
41
|
+
export declare function computeInvalidation(meta: MetaJson, scopeFiles: string[], config: MetaConfig, node: MetaNode, crossRefMetas?: Map<string, string | undefined>, archiveCrossRefContent?: Map<string, string | undefined>): Promise<InvalidationResult>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Corpus-wide phase scheduler.
|
|
3
|
+
*
|
|
4
|
+
* Selects the highest-priority ready phase across all metas.
|
|
5
|
+
* Priority: critic (band 1) \> builder (band 2) \> architect (band 3).
|
|
6
|
+
* Tiebreak within band: weighted staleness (§3.9).
|
|
7
|
+
*
|
|
8
|
+
* @module phaseState/phaseScheduler
|
|
9
|
+
*/
|
|
10
|
+
import type { MetaEntry } from '../discovery/listMetas.js';
|
|
11
|
+
import type { MetaNode } from '../discovery/types.js';
|
|
12
|
+
import type { MetaJson, PhaseName, PhaseState } from '../schema/index.js';
|
|
13
|
+
/** Input for phase candidate selection (from listMetas entries). */
|
|
14
|
+
export interface PhaseCandidateInput {
|
|
15
|
+
node: MetaNode;
|
|
16
|
+
meta: MetaJson;
|
|
17
|
+
phaseState: PhaseState;
|
|
18
|
+
actualStaleness: number;
|
|
19
|
+
locked: boolean;
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
isOverride?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Build phase candidates from listMetas entries.
|
|
25
|
+
*
|
|
26
|
+
* Derives phase state, auto-retries failed phases, and applies Tier 1
|
|
27
|
+
* cheap-invalidation (no I/O) for metas with persisted _phaseState.
|
|
28
|
+
* Used by orchestratePhase, queue route, and status route.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildPhaseCandidates(entries: MetaEntry[], architectEvery: number): PhaseCandidateInput[];
|
|
31
|
+
/** A candidate for phase-level scheduling. */
|
|
32
|
+
export interface PhaseCandidate {
|
|
33
|
+
node: MetaNode;
|
|
34
|
+
meta: MetaJson;
|
|
35
|
+
phaseState: PhaseState;
|
|
36
|
+
owedPhase: PhaseName;
|
|
37
|
+
band: 1 | 2 | 3;
|
|
38
|
+
actualStaleness: number;
|
|
39
|
+
effectiveStaleness: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Rank all eligible phase candidates by priority.
|
|
43
|
+
*
|
|
44
|
+
* Filters to pending phases, computes effective staleness, and sorts by
|
|
45
|
+
* band (ascending: critic first) then effective staleness (descending).
|
|
46
|
+
*
|
|
47
|
+
* Used by selectPhaseCandidate (returns first) and the queue route (returns all).
|
|
48
|
+
*/
|
|
49
|
+
export declare function rankPhaseCandidates(metas: PhaseCandidateInput[], depthWeight: number): PhaseCandidate[];
|
|
50
|
+
/**
|
|
51
|
+
* Select the best phase candidate across the corpus.
|
|
52
|
+
*
|
|
53
|
+
* @param metas - Array of (node, meta, phaseState, stalenessSeconds) tuples.
|
|
54
|
+
* @param depthWeight - Config depthWeight for staleness tiebreak.
|
|
55
|
+
* @returns The winning candidate, or null if no phase is ready.
|
|
56
|
+
*/
|
|
57
|
+
export declare function selectPhaseCandidate(metas: PhaseCandidateInput[], depthWeight: number): PhaseCandidate | null;
|