@karmaniverous/jeeves-meta 0.15.4 → 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/index.js +199 -95
- 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 -1580
- package/dist/index.js +182 -109
- 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/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 +16 -26
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;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure phase-state transition functions.
|
|
3
|
+
*
|
|
4
|
+
* Implements every row of the §8 "Transitions and invalidation cascade" table.
|
|
5
|
+
* No I/O — pure functions over PhaseState and documented inputs.
|
|
6
|
+
*
|
|
7
|
+
* @module phaseState/phaseTransitions
|
|
8
|
+
*/
|
|
9
|
+
import type { PhaseState } from '../schema/meta.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create a fresh (fully-complete) phase state.
|
|
12
|
+
*/
|
|
13
|
+
export declare function freshPhaseState(): PhaseState;
|
|
14
|
+
/**
|
|
15
|
+
* Create a phase state for a never-synthesized meta (all pending from architect).
|
|
16
|
+
*/
|
|
17
|
+
export declare function initialPhaseState(): PhaseState;
|
|
18
|
+
/**
|
|
19
|
+
* Enforce the per-meta invariant: at most one phase is pending or running,
|
|
20
|
+
* and it is the first non-fresh phase in pipeline order.
|
|
21
|
+
*
|
|
22
|
+
* Stale phases that become the first non-fresh phase are promoted to pending.
|
|
23
|
+
*/
|
|
24
|
+
export declare function enforceInvariant(state: PhaseState): PhaseState;
|
|
25
|
+
/**
|
|
26
|
+
* Architect invalidated: architect → pending; builder, critic → stale.
|
|
27
|
+
* Triggers: _structureHash change, _steer change, _architect change,
|
|
28
|
+
* _crossRefs declaration change, _synthesisCount \>= architectEvery.
|
|
29
|
+
*/
|
|
30
|
+
export declare function invalidateArchitect(state: PhaseState): PhaseState;
|
|
31
|
+
/**
|
|
32
|
+
* Builder invalidated (scope mtime or cross-ref _content change):
|
|
33
|
+
* builder → pending; critic → stale.
|
|
34
|
+
* Only applies when architect is fresh; otherwise, builder stays stale.
|
|
35
|
+
*/
|
|
36
|
+
export declare function invalidateBuilder(state: PhaseState): PhaseState;
|
|
37
|
+
/**
|
|
38
|
+
* Architect completes successfully.
|
|
39
|
+
* architect → fresh; builder → pending; critic → stale.
|
|
40
|
+
*/
|
|
41
|
+
export declare function architectSuccess(state: PhaseState): PhaseState;
|
|
42
|
+
/**
|
|
43
|
+
* Builder completes successfully.
|
|
44
|
+
* builder → fresh; critic → pending.
|
|
45
|
+
*/
|
|
46
|
+
export declare function builderSuccess(state: PhaseState): PhaseState;
|
|
47
|
+
/**
|
|
48
|
+
* Critic completes successfully.
|
|
49
|
+
* critic → fresh. Meta becomes fully fresh.
|
|
50
|
+
*/
|
|
51
|
+
export declare function criticSuccess(state: PhaseState): PhaseState;
|
|
52
|
+
/**
|
|
53
|
+
* A phase fails (error, timeout, or abort).
|
|
54
|
+
* Target phase → failed; upstream and downstream unchanged.
|
|
55
|
+
*/
|
|
56
|
+
export declare function phaseFailed(state: PhaseState, phase: 'architect' | 'builder' | 'critic'): PhaseState;
|
|
57
|
+
/**
|
|
58
|
+
* Retry a failed phase: failed → pending.
|
|
59
|
+
* Only valid when the phase is currently failed.
|
|
60
|
+
*/
|
|
61
|
+
export declare function retryPhase(state: PhaseState, phase: 'architect' | 'builder' | 'critic'): PhaseState;
|
|
62
|
+
/**
|
|
63
|
+
* Retry all failed phases: each failed phase → pending.
|
|
64
|
+
* Used by scheduler ticks and queue reads to auto-promote failed phases.
|
|
65
|
+
*/
|
|
66
|
+
export declare function retryAllFailed(state: PhaseState): PhaseState;
|
|
67
|
+
/**
|
|
68
|
+
* Mark a phase as running (scheduler picks it).
|
|
69
|
+
*/
|
|
70
|
+
export declare function phaseRunning(state: PhaseState, phase: 'architect' | 'builder' | 'critic'): PhaseState;
|
|
71
|
+
/**
|
|
72
|
+
* Get the owed phase: first non-fresh phase in pipeline order, or null.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getOwedPhase(state: PhaseState): 'architect' | 'builder' | 'critic' | null;
|
|
75
|
+
/**
|
|
76
|
+
* Check if a meta is fully fresh (all phases fresh).
|
|
77
|
+
*/
|
|
78
|
+
export declare function isFullyFresh(state: PhaseState): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Get the scheduler priority band for a meta's owed phase.
|
|
81
|
+
* 1 = critic (highest), 2 = builder, 3 = architect, null = fully fresh.
|
|
82
|
+
*/
|
|
83
|
+
export declare function getPriorityBand(state: PhaseState): 1 | 2 | 3 | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Progress reporting via OpenClaw gateway `/tools/invoke` → `message` tool.
|
|
3
|
+
*
|
|
4
|
+
* @module progress
|
|
5
|
+
*/
|
|
6
|
+
import type { Logger } from 'pino';
|
|
7
|
+
export type ProgressPhase = 'architect' | 'builder' | 'critic';
|
|
8
|
+
export type ProgressEvent = {
|
|
9
|
+
type: 'synthesis_start' | 'phase_start' | 'phase_complete' | 'synthesis_complete' | 'error';
|
|
10
|
+
/** Owner path (not .meta path) of the entity being synthesized. */
|
|
11
|
+
path: string;
|
|
12
|
+
phase?: ProgressPhase;
|
|
13
|
+
tokens?: number;
|
|
14
|
+
durationMs?: number;
|
|
15
|
+
error?: string;
|
|
16
|
+
};
|
|
17
|
+
export type ProgressReporterConfig = {
|
|
18
|
+
gatewayUrl: string;
|
|
19
|
+
gatewayApiKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Messaging channel name (e.g. 'slack'). When set alongside reportTarget,
|
|
22
|
+
* included in the gateway message payload as `channel`.
|
|
23
|
+
* Legacy: if reportTarget is unset, reportChannel is used as the target
|
|
24
|
+
* (single-channel mode, backward compatible).
|
|
25
|
+
*/
|
|
26
|
+
reportChannel?: string;
|
|
27
|
+
/** Channel/user ID to send messages to. Takes priority over reportChannel as target. */
|
|
28
|
+
reportTarget?: string;
|
|
29
|
+
/** Optional base URL for the service, used to construct entity links. */
|
|
30
|
+
serverBaseUrl?: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function formatProgressEvent(event: ProgressEvent, serverBaseUrl?: string): string;
|
|
33
|
+
export declare class ProgressReporter {
|
|
34
|
+
private readonly config;
|
|
35
|
+
private readonly logger;
|
|
36
|
+
constructor(config: ProgressReporterConfig, logger: Logger);
|
|
37
|
+
report(event: ProgressEvent): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in default prompts for the synthesis pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Prompts ship as .md files bundled into dist/prompts/ via rollup-plugin-copy.
|
|
5
|
+
* Loaded at runtime relative to the compiled module location.
|
|
6
|
+
*
|
|
7
|
+
* Users can override via `defaultArchitect` / `defaultCritic` in the service
|
|
8
|
+
* config. Most installations should use the built-in defaults.
|
|
9
|
+
*
|
|
10
|
+
* @module prompts
|
|
11
|
+
*/
|
|
12
|
+
/** Built-in default architect prompt. */
|
|
13
|
+
export declare const DEFAULT_ARCHITECT_PROMPT: string;
|
|
14
|
+
/** Built-in default critic prompt. */
|
|
15
|
+
export declare const DEFAULT_CRITIC_PROMPT: string;
|