@h-rig/core 0.0.6-alpha.13 → 0.0.6-alpha.130
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/src/define-config.d.ts +18 -0
- package/dist/src/define-config.js +20 -2
- package/dist/src/define-plugin.d.ts +9 -0
- package/dist/src/define-plugin.js +17 -0
- package/dist/src/engineReadModelReducer.d.ts +12 -0
- package/dist/src/engineReadModelReducer.js +17 -13
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +364 -31
- package/dist/src/load-config.d.ts +2 -0
- package/dist/src/load-config.js +257 -5
- package/dist/src/plugin-host.d.ts +40 -0
- package/dist/src/plugin-host.js +18 -0
- package/dist/src/plugin-runtime.d.ts +64 -0
- package/dist/src/rig-init-builder.d.ts +30 -0
- package/dist/src/rig-init-builder.js +2 -1
- package/dist/src/rigSelectors.d.ts +220 -0
- package/dist/src/rigSelectors.js +125 -4
- package/dist/src/taskGraph.d.ts +41 -0
- package/dist/src/taskGraph.js +164 -8
- package/dist/src/taskGraphCodes.d.ts +3 -0
- package/dist/src/taskGraphLayout.d.ts +60 -0
- package/dist/src/taskGraphLayout.js +22 -3
- package/package.json +6 -12
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RigConfig } from "@rig/contracts";
|
|
2
|
+
/**
|
|
3
|
+
* Author-facing config input: `plugins` and `workspace` are optional and
|
|
4
|
+
* default to a plugin-less worktree setup, so the minimal documented config
|
|
5
|
+
* (project + taskSource) works out of the box.
|
|
6
|
+
*/
|
|
7
|
+
export type RigConfigInput = Omit<RigConfig, "plugins" | "workspace"> & {
|
|
8
|
+
plugins?: RigConfig["plugins"];
|
|
9
|
+
workspace?: RigConfig["workspace"];
|
|
10
|
+
};
|
|
11
|
+
/** Fill optional top-level sections before Schema decode (which requires them). */
|
|
12
|
+
export declare function applyConfigDefaults(raw: unknown): unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Validate a Rig config and decode through Schema, preserving each plugin's
|
|
15
|
+
* `__runtime` channel. Schema decode strips unknown fields, so we capture
|
|
16
|
+
* the runtime objects before decoding and re-attach them after.
|
|
17
|
+
*/
|
|
18
|
+
export declare function defineConfig(cfg: RigConfigInput): RigConfig;
|
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
// packages/core/src/define-config.ts
|
|
3
3
|
import { Schema } from "effect";
|
|
4
4
|
import { RigConfig } from "@rig/contracts";
|
|
5
|
+
function normalizeWorkspaceConfig(raw) {
|
|
6
|
+
const workspace = raw && typeof raw === "object" && !Array.isArray(raw) ? { ...raw } : { mainRepo: "." };
|
|
7
|
+
workspace.checkout = workspace.checkout ?? workspace.isolation ?? "worktree";
|
|
8
|
+
workspace.isolation = workspace.isolation ?? workspace.checkout;
|
|
9
|
+
workspace.sandbox = workspace.sandbox ?? "enforce";
|
|
10
|
+
return workspace;
|
|
11
|
+
}
|
|
12
|
+
function applyConfigDefaults(raw) {
|
|
13
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
14
|
+
return raw;
|
|
15
|
+
const record = raw;
|
|
16
|
+
return {
|
|
17
|
+
...record,
|
|
18
|
+
plugins: Array.isArray(record.plugins) ? record.plugins : [],
|
|
19
|
+
workspace: normalizeWorkspaceConfig(record.workspace)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
5
22
|
function defineConfig(cfg) {
|
|
6
23
|
const runtimeByName = new Map;
|
|
7
24
|
const plugins = cfg.plugins ?? [];
|
|
@@ -10,7 +27,7 @@ function defineConfig(cfg) {
|
|
|
10
27
|
runtimeByName.set(plugin.name, plugin.__runtime);
|
|
11
28
|
}
|
|
12
29
|
}
|
|
13
|
-
const decoded = Schema.decodeUnknownSync(RigConfig)(cfg);
|
|
30
|
+
const decoded = Schema.decodeUnknownSync(RigConfig)(applyConfigDefaults(cfg));
|
|
14
31
|
const decodedPlugins = decoded.plugins.map((p) => {
|
|
15
32
|
const runtime = runtimeByName.get(p.name);
|
|
16
33
|
if (!runtime)
|
|
@@ -20,5 +37,6 @@ function defineConfig(cfg) {
|
|
|
20
37
|
return { ...decoded, plugins: decodedPlugins };
|
|
21
38
|
}
|
|
22
39
|
export {
|
|
23
|
-
defineConfig
|
|
40
|
+
defineConfig,
|
|
41
|
+
applyConfigDefaults
|
|
24
42
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RigPlugin } from "@rig/contracts";
|
|
2
|
+
import type { RigPluginRuntime, RigPluginWithRuntime } from "./plugin-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Define a Rig plugin. The first argument is the schema-validated metadata
|
|
5
|
+
* (id strings, version, contributions). The optional second argument carries
|
|
6
|
+
* executable bits (validator `run` functions, etc.) that Schema cannot
|
|
7
|
+
* represent — they travel alongside the validated metadata as `__runtime`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function definePlugin(meta: RigPlugin, runtime?: RigPluginRuntime): RigPluginWithRuntime;
|
|
@@ -43,6 +43,23 @@ function definePlugin(meta, runtime) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
const declaredHooks = new Map((validated.contributes?.hooks ?? []).map((h) => [h.id, h]));
|
|
47
|
+
for (const hookId of Object.keys(runtime.hooks ?? {})) {
|
|
48
|
+
const metadata = declaredHooks.get(hookId);
|
|
49
|
+
if (!metadata) {
|
|
50
|
+
throw new Error(`definePlugin(${validated.name}): typed hook "${hookId}" has no matching metadata entry in contributes.hooks`);
|
|
51
|
+
}
|
|
52
|
+
if (metadata.command) {
|
|
53
|
+
throw new Error(`definePlugin(${validated.name}): hook "${hookId}" has both a typed implementation and a command string \u2014 pick one`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (runtime.hooks) {
|
|
57
|
+
for (const h of declaredHooks.values()) {
|
|
58
|
+
if (!runtime.hooks[h.id] && !h.command) {
|
|
59
|
+
throw new Error(`definePlugin(${validated.name}): hook metadata "${h.id}" has no implementation (typed function or command)`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
46
63
|
return { ...validated, __runtime: runtime };
|
|
47
64
|
}
|
|
48
65
|
export {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EngineEvent, EngineReadModel, QueueEntry, RunSummary, TaskSummary } from "@rig/contracts";
|
|
2
|
+
type EngineApplyStatus = "applied" | "ignored" | "requires-resync";
|
|
3
|
+
export type ApplyStatus = EngineApplyStatus;
|
|
4
|
+
export interface EngineEventApplyResult {
|
|
5
|
+
readonly status: EngineApplyStatus;
|
|
6
|
+
readonly snapshot: EngineReadModel;
|
|
7
|
+
}
|
|
8
|
+
export declare function mapTaskStatusFromRunStatus(status: RunSummary["status"], fallback: TaskSummary["status"]): TaskSummary["status"];
|
|
9
|
+
export declare function applyEngineEvent(snapshot: EngineReadModel, event: EngineEvent): EngineEventApplyResult;
|
|
10
|
+
export declare function applyEngineEvents(snapshot: EngineReadModel, events: ReadonlyArray<EngineEvent>): EngineEventApplyResult;
|
|
11
|
+
export declare function pruneQueueEntries(snapshot: EngineReadModel): QueueEntry[];
|
|
12
|
+
export {};
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
WorkspaceId,
|
|
11
11
|
WorktreeId
|
|
12
12
|
} from "@rig/contracts";
|
|
13
|
+
var CANONICAL_RUNTIME_ADAPTER = "pi";
|
|
13
14
|
function isRecord(value) {
|
|
14
15
|
return typeof value === "object" && value !== null;
|
|
15
16
|
}
|
|
@@ -149,7 +150,7 @@ function mapLegacySessionStatusToRunStatus(status) {
|
|
|
149
150
|
case "error":
|
|
150
151
|
return "failed";
|
|
151
152
|
case "stopped":
|
|
152
|
-
return "
|
|
153
|
+
return "stopped";
|
|
153
154
|
default:
|
|
154
155
|
return "created";
|
|
155
156
|
}
|
|
@@ -185,12 +186,15 @@ function mapTaskStatusFromRunStatus(status, fallback) {
|
|
|
185
186
|
case "paused":
|
|
186
187
|
return "in_progress";
|
|
187
188
|
case "reviewing":
|
|
189
|
+
case "closing-out":
|
|
188
190
|
return "under_review";
|
|
191
|
+
case "needs-attention":
|
|
192
|
+
return "blocked";
|
|
189
193
|
case "completed":
|
|
190
194
|
return "completed";
|
|
191
195
|
case "failed":
|
|
192
196
|
return "ready";
|
|
193
|
-
case "
|
|
197
|
+
case "stopped":
|
|
194
198
|
return "cancelled";
|
|
195
199
|
}
|
|
196
200
|
}
|
|
@@ -374,7 +378,7 @@ function applySyntheticRuntimePreparation(snapshot, event) {
|
|
|
374
378
|
...existingRun,
|
|
375
379
|
taskId: existingRun.taskId ?? nextTaskId,
|
|
376
380
|
runKind: existingRun.runKind === "adhoc" && nextTaskId ? "task" : existingRun.runKind,
|
|
377
|
-
runtimeAdapter:
|
|
381
|
+
runtimeAdapter: CANONICAL_RUNTIME_ADAPTER,
|
|
378
382
|
initialPrompt: existingRun.initialPrompt ?? null,
|
|
379
383
|
executionTarget: existingRun.executionTarget ?? "local",
|
|
380
384
|
remoteHostId: existingRun.remoteHostId ?? null,
|
|
@@ -390,7 +394,7 @@ function applySyntheticRuntimePreparation(snapshot, event) {
|
|
|
390
394
|
...runtimeBase,
|
|
391
395
|
workspaceId: nextWorkspaceId,
|
|
392
396
|
runId: runtimeRunId,
|
|
393
|
-
adapterKind:
|
|
397
|
+
adapterKind: CANONICAL_RUNTIME_ADAPTER,
|
|
394
398
|
executionTarget: existingRun.executionTarget ?? "local",
|
|
395
399
|
remoteHostId: existingRun.remoteHostId ?? null,
|
|
396
400
|
status: failed ? "failed" : finished ? "prepared" : "starting",
|
|
@@ -439,7 +443,7 @@ function applySyntheticRuntimePrepared(snapshot, event) {
|
|
|
439
443
|
...snapshot.runtimes.find((runtime) => runtime.runId === runId) ?? makeRuntimeFromRun(existingRun, event.createdAt),
|
|
440
444
|
workspaceId: nextWorkspaceId,
|
|
441
445
|
runId: runtimeRunId,
|
|
442
|
-
adapterKind:
|
|
446
|
+
adapterKind: CANONICAL_RUNTIME_ADAPTER,
|
|
443
447
|
executionTarget: existingRun.executionTarget ?? "local",
|
|
444
448
|
remoteHostId: existingRun.remoteHostId ?? null,
|
|
445
449
|
status: "prepared",
|
|
@@ -482,7 +486,7 @@ function applyLegacyProjectEvent(snapshot, event) {
|
|
|
482
486
|
title,
|
|
483
487
|
rootPath,
|
|
484
488
|
sourceKind: "native",
|
|
485
|
-
defaultRuntimeAdapter:
|
|
489
|
+
defaultRuntimeAdapter: CANONICAL_RUNTIME_ADAPTER,
|
|
486
490
|
defaultModel: readNullableString(payload, "defaultModel") ?? null,
|
|
487
491
|
createdAt,
|
|
488
492
|
updatedAt
|
|
@@ -577,7 +581,7 @@ function applyLegacyThreadEvent(snapshot, event) {
|
|
|
577
581
|
runtimeMode: "full-access",
|
|
578
582
|
interactionMode: "default",
|
|
579
583
|
status: "created",
|
|
580
|
-
runtimeAdapter:
|
|
584
|
+
runtimeAdapter: CANONICAL_RUNTIME_ADAPTER,
|
|
581
585
|
model,
|
|
582
586
|
initialPrompt: null,
|
|
583
587
|
activeRuntimeId: null,
|
|
@@ -761,7 +765,7 @@ function applyLegacyThreadEvent(snapshot, event) {
|
|
|
761
765
|
const providerName = readNullableString(session, "providerName");
|
|
762
766
|
const nextRun = {
|
|
763
767
|
...existingRun,
|
|
764
|
-
runtimeAdapter:
|
|
768
|
+
runtimeAdapter: CANONICAL_RUNTIME_ADAPTER,
|
|
765
769
|
initialPrompt: existingRun.initialPrompt ?? null,
|
|
766
770
|
activeRuntimeId: runtimeIdFromRunId(asRunId(runId)),
|
|
767
771
|
status: mapLegacySessionStatusToRunStatus(readString(session, "status")),
|
|
@@ -774,7 +778,7 @@ function applyLegacyThreadEvent(snapshot, event) {
|
|
|
774
778
|
...snapshot.runtimes.find((runtime) => runtime.runId === runId) ?? makeRuntimeFromRun(nextRun, sessionUpdatedAt),
|
|
775
779
|
workspaceId: existingRun.workspaceId,
|
|
776
780
|
runId: asRunId(runId),
|
|
777
|
-
adapterKind:
|
|
781
|
+
adapterKind: CANONICAL_RUNTIME_ADAPTER,
|
|
778
782
|
status: mapLegacySessionStatusToRuntimeStatus(readString(session, "status")),
|
|
779
783
|
workspaceDir: existingRun.worktreePath,
|
|
780
784
|
isolationMode: existingRun.worktreePath ? "worktree" : "env",
|
|
@@ -1008,7 +1012,7 @@ function applyEngineEvent(snapshot, event) {
|
|
|
1008
1012
|
runtimeMode: payload.runtimeMode,
|
|
1009
1013
|
interactionMode: payload.interactionMode,
|
|
1010
1014
|
status: "created",
|
|
1011
|
-
runtimeAdapter:
|
|
1015
|
+
runtimeAdapter: CANONICAL_RUNTIME_ADAPTER,
|
|
1012
1016
|
model: payload.model ?? null,
|
|
1013
1017
|
initialPrompt: payload.initialPrompt ?? null,
|
|
1014
1018
|
executionTarget: payload.executionTarget ?? (payload.remoteHostId ? "remote" : "local"),
|
|
@@ -1040,7 +1044,7 @@ function applyEngineEvent(snapshot, event) {
|
|
|
1040
1044
|
...base,
|
|
1041
1045
|
runs: patchById(base.runs, payload.runId, (run) => ({
|
|
1042
1046
|
...run,
|
|
1043
|
-
status: "
|
|
1047
|
+
status: "stopped",
|
|
1044
1048
|
updatedAt: payload.createdAt,
|
|
1045
1049
|
completedAt: payload.createdAt
|
|
1046
1050
|
}))
|
|
@@ -1704,7 +1708,7 @@ function applyEngineEvent(snapshot, event) {
|
|
|
1704
1708
|
runtimeMode: "full-access",
|
|
1705
1709
|
interactionMode: "default",
|
|
1706
1710
|
status: "created",
|
|
1707
|
-
runtimeAdapter:
|
|
1711
|
+
runtimeAdapter: CANONICAL_RUNTIME_ADAPTER,
|
|
1708
1712
|
model: null,
|
|
1709
1713
|
initialPrompt: null,
|
|
1710
1714
|
activeRuntimeId: runtimeIdFromRunId(asRunId(runId)),
|
|
@@ -1724,7 +1728,7 @@ function applyEngineEvent(snapshot, event) {
|
|
|
1724
1728
|
workspaceId: asWorkspaceId(workspaceId),
|
|
1725
1729
|
taskId: asTaskId(taskId),
|
|
1726
1730
|
runKind: "task",
|
|
1727
|
-
runtimeAdapter:
|
|
1731
|
+
runtimeAdapter: CANONICAL_RUNTIME_ADAPTER,
|
|
1728
1732
|
activeRuntimeId: runtimeIdFromRunId(asRunId(runId)),
|
|
1729
1733
|
updatedAt: event.createdAt
|
|
1730
1734
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const RIG_CORE_PACKAGE = "@rig/core";
|
|
2
|
+
export { definePlugin } from "./define-plugin";
|
|
3
|
+
export { defineConfig } from "./define-config";
|
|
4
|
+
export { createPluginHost } from "./plugin-host";
|
|
5
|
+
export type { PluginHost } from "./plugin-host";
|
|
6
|
+
export { buildRigInitConfigSource, type RigInitConfigInput, } from "./rig-init-builder";
|
|
7
|
+
export type { RegisteredValidator, RigPluginRuntime, RigPluginWithRuntime, TaskSourceFactoryContext, TaskSourceFactoryEntry, ValidatorContext, ValidatorResult, } from "./plugin-runtime";
|
|
8
|
+
export { applyEngineEvent, applyEngineEvents, applyEngineEvent as applyRigEvent, pruneQueueEntries, type ApplyStatus, type EngineEventApplyResult, type EngineEventApplyResult as RigEventApplyResult, } from "./engineReadModelReducer";
|
|
9
|
+
export { pickDefaultWorkspaceId, projectRunStatusForTaskGrouping, projectTaskStatusForGrouping, projectTaskStatusWithSessions, normalizeTaskAssigneeFilter, readTaskAssigneeLogins, selectAdhocRuns, selectAdhocRunsForWorkspace, selectApprovalsForRun, selectApprovalsForWorkspace, selectGraphsForWorkspace, selectPendingApprovals, selectPrimaryWorkspace, selectQueueForWorkspace, selectRun, selectRunsByTask, selectRunsForTask, selectRunsForWorkspace, selectTask, selectTasksByStatus, selectTasksByWorkspace, selectTasksForWorkspace, selectTasksGroupedByStatus, selectTasksAssignedTo, selectTasksAssignedToMe, selectUserInputsForRun, selectUserInputsForWorkspace, selectWorkspace, selectWorkspaces, type RigTaskSessionProjection, type RigTaskStatusGroup, type RigTaskStatusGroupingInput, } from "./rigSelectors";
|
|
10
|
+
export { buildTaskReferenceIndex, computeTaskBlockingDepths, computeTaskDependencyBadges, isTaskTerminalStatus, readTaskDependencyRefs, readTaskMetadataStringList, readTaskSourceIssueId, resolveTaskReference, selectNextReadyTaskByPriority, type TaskDependencyBadge, type TaskDependencyBadgeKind, type TaskDependencyBadgeSummary, type TaskDependencyProjection, } from "./taskGraph";
|
|
11
|
+
export { extractTaskCode, extractTaskGroupKey, stripTaskCode, } from "./taskGraphCodes";
|
|
12
|
+
export { buildTaskGraphLayout, type TaskGraphEdge, type TaskGraphLane, type TaskGraphLayout, type TaskGraphNode, type TaskGraphStage, } from "./taskGraphLayout";
|