@h-rig/contracts 0.0.6-alpha.16 → 0.0.6-alpha.160

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.
Files changed (162) hide show
  1. package/dist/index.cjs +3280 -0
  2. package/dist/index.mjs +3239 -0
  3. package/dist/src/agent-roles.d.ts +8 -0
  4. package/dist/src/artifact.d.ts +13 -0
  5. package/dist/src/artifact.js +3 -0
  6. package/dist/src/baseSchemas.d.ts +63 -0
  7. package/dist/src/baseSchemas.js +6 -0
  8. package/dist/src/browser.d.ts +80 -0
  9. package/dist/src/browser.js +13 -0
  10. package/dist/src/capability-id.d.ts +22 -0
  11. package/dist/src/capability-id.js +8 -0
  12. package/dist/src/cli-output.d.ts +348 -0
  13. package/dist/src/cli-output.js +190 -0
  14. package/dist/src/cli-runner.d.ts +43 -0
  15. package/dist/src/cli-runner.js +13 -0
  16. package/dist/src/collab-session-viewer.d.ts +36 -0
  17. package/dist/src/collab-session-viewer.js +13 -0
  18. package/dist/src/config.d.ts +551 -0
  19. package/dist/src/config.js +765 -162
  20. package/dist/src/control-plane-types.d.ts +323 -0
  21. package/dist/src/control-plane-types.js +13 -0
  22. package/dist/src/conversation.d.ts +50 -0
  23. package/dist/src/conversation.js +3 -0
  24. package/dist/src/dependency-preflight.d.ts +43 -0
  25. package/dist/src/dependency-preflight.js +13 -0
  26. package/dist/src/doctor.d.ts +90 -0
  27. package/dist/src/doctor.js +13 -0
  28. package/dist/src/drift.d.ts +28 -0
  29. package/dist/src/drift.js +69 -0
  30. package/dist/src/editor.d.ts +25 -0
  31. package/dist/src/editor.js +3 -0
  32. package/dist/src/errors.d.ts +13 -0
  33. package/dist/src/errors.js +17 -0
  34. package/dist/src/git.d.ts +144 -0
  35. package/dist/src/git.js +3 -0
  36. package/dist/src/github.d.ts +146 -0
  37. package/dist/src/github.js +17 -0
  38. package/dist/src/graph.d.ts +360 -0
  39. package/dist/src/graph.js +137 -1
  40. package/dist/src/guard.d.ts +111 -0
  41. package/dist/src/guard.js +6 -0
  42. package/dist/src/harness-events.d.ts +8 -0
  43. package/dist/src/harness-events.js +1 -0
  44. package/dist/src/help-catalog.d.ts +41 -0
  45. package/dist/src/help-catalog.js +13 -0
  46. package/dist/src/host.d.ts +41 -0
  47. package/dist/src/host.js +13 -0
  48. package/dist/src/identity.d.ts +44 -0
  49. package/dist/src/identity.js +1 -0
  50. package/dist/src/index.d.ts +77 -0
  51. package/dist/src/index.js +2661 -3970
  52. package/dist/src/isolation.d.ts +213 -0
  53. package/dist/src/isolation.js +13 -0
  54. package/dist/src/kernel.d.ts +200 -0
  55. package/dist/src/kernel.js +261 -0
  56. package/dist/src/keybindings.d.ts +71 -0
  57. package/dist/src/keybindings.js +3 -0
  58. package/dist/src/layout.d.ts +49 -0
  59. package/dist/src/layout.js +10 -0
  60. package/dist/src/lifecycle-capabilities.d.ts +128 -0
  61. package/dist/src/lifecycle-capabilities.js +25 -0
  62. package/dist/src/managed-repos.d.ts +136 -0
  63. package/dist/src/managed-repos.js +17 -0
  64. package/dist/src/memory.d.ts +199 -0
  65. package/dist/src/memory.js +15 -0
  66. package/dist/src/model.d.ts +77 -0
  67. package/dist/src/notify.d.ts +46 -0
  68. package/dist/src/notify.js +13 -0
  69. package/dist/src/orchestration.d.ts +43 -0
  70. package/dist/src/orchestration.js +28 -961
  71. package/dist/src/panel-protocol.d.ts +17 -0
  72. package/dist/src/panel-protocol.js +10 -0
  73. package/dist/src/pi-session.d.ts +113 -0
  74. package/dist/src/pi-session.js +1 -0
  75. package/dist/src/planning.d.ts +64 -0
  76. package/dist/src/planning.js +90 -0
  77. package/dist/src/plugin-hooks.d.ts +51 -0
  78. package/dist/src/plugin-hooks.js +386 -0
  79. package/dist/src/plugin.d.ts +476 -0
  80. package/dist/src/plugin.js +346 -64
  81. package/dist/src/policy.d.ts +16 -0
  82. package/dist/src/policy.js +3 -0
  83. package/dist/src/project.d.ts +71 -0
  84. package/dist/src/project.js +3 -0
  85. package/dist/src/prompt.d.ts +29 -0
  86. package/dist/src/prompt.js +13 -0
  87. package/dist/src/protocol-version.d.ts +21 -0
  88. package/dist/src/protocol-version.js +6 -0
  89. package/dist/src/provider-instructions.d.ts +41 -0
  90. package/dist/src/provider-instructions.js +13 -0
  91. package/dist/src/provider.d.ts +105 -0
  92. package/dist/src/provider.js +4 -824
  93. package/dist/src/remote.d.ts +318 -0
  94. package/dist/src/remote.js +238 -1078
  95. package/dist/src/review.d.ts +18 -0
  96. package/dist/src/review.js +3 -0
  97. package/dist/src/rollups.d.ts +41 -0
  98. package/dist/src/rollups.js +70 -0
  99. package/dist/src/run-discovery.d.ts +79 -0
  100. package/dist/src/run-discovery.js +13 -0
  101. package/dist/src/run-dispatch.d.ts +34 -0
  102. package/dist/src/run-dispatch.js +13 -0
  103. package/dist/src/run-identity.d.ts +47 -0
  104. package/dist/src/run-identity.js +13 -0
  105. package/dist/src/run-journal.d.ts +694 -0
  106. package/dist/src/run-journal.js +569 -0
  107. package/dist/src/run-read-model.d.ts +234 -0
  108. package/dist/src/run-read-model.js +13 -0
  109. package/dist/src/run-record.d.ts +45 -0
  110. package/dist/src/run-record.js +1 -0
  111. package/dist/src/run-registry-backbone.d.ts +56 -0
  112. package/dist/src/run-registry-backbone.js +13 -0
  113. package/dist/src/run-session-journal.d.ts +69 -0
  114. package/dist/src/run-session-journal.js +78 -0
  115. package/dist/src/run-status.d.ts +10 -0
  116. package/dist/src/run-status.js +27 -0
  117. package/dist/src/run-timeline.d.ts +7 -0
  118. package/dist/src/run-timeline.js +1 -0
  119. package/dist/src/runtime-task-context.d.ts +82 -0
  120. package/dist/src/runtime-task-context.js +1 -0
  121. package/dist/src/runtime.d.ts +103 -0
  122. package/dist/src/runtime.js +73 -906
  123. package/dist/src/session-asset-materializer.d.ts +35 -0
  124. package/dist/src/session-asset-materializer.js +13 -0
  125. package/dist/src/setup.d.ts +47 -0
  126. package/dist/src/setup.js +13 -0
  127. package/dist/src/stage.d.ts +245 -0
  128. package/dist/src/stage.js +169 -0
  129. package/dist/src/supervisor-journal.d.ts +204 -0
  130. package/dist/src/supervisor-journal.js +334 -0
  131. package/dist/src/task-data.d.ts +239 -0
  132. package/dist/src/task-data.js +13 -0
  133. package/dist/src/task-graph-primitives.d.ts +47 -0
  134. package/dist/src/task-graph-primitives.js +1 -0
  135. package/dist/src/task-source.d.ts +102 -0
  136. package/dist/src/task-source.js +12 -0
  137. package/dist/src/task-state-metadata.d.ts +21 -0
  138. package/dist/src/task-state-metadata.js +1 -0
  139. package/dist/src/terminal.d.ts +130 -0
  140. package/dist/src/terminal.js +3 -0
  141. package/dist/src/tool-materializer.d.ts +36 -0
  142. package/dist/src/tool-materializer.js +13 -0
  143. package/dist/src/tool-registry.d.ts +3 -0
  144. package/dist/src/tool-registry.js +58 -0
  145. package/dist/src/toolchain-sources.d.ts +54 -0
  146. package/dist/src/toolchain-sources.js +17 -0
  147. package/dist/src/validation.d.ts +14 -0
  148. package/dist/src/validation.js +3 -0
  149. package/dist/src/workflow-journal.d.ts +92 -0
  150. package/dist/src/workflow-journal.js +18 -0
  151. package/dist/src/workspace-config.d.ts +18 -0
  152. package/dist/src/workspace-config.js +13 -0
  153. package/dist/src/workspace.d.ts +204 -0
  154. package/dist/src/workspace.js +76 -911
  155. package/package.json +51 -4
  156. package/dist/src/engine.js +0 -2278
  157. package/dist/src/providerRuntime.js +0 -1630
  158. package/dist/src/rig.js +0 -2374
  159. package/dist/src/server.js +0 -1053
  160. package/dist/src/serviceFabric.js +0 -1066
  161. package/dist/src/ws.js +0 -2968
  162. /package/dist/src/{ipc.js → agent-roles.js} +0 -0
@@ -0,0 +1,71 @@
1
+ import { Schema } from "effect";
2
+ export declare const MAX_KEYBINDING_VALUE_LENGTH = 64;
3
+ export declare const MAX_WHEN_EXPRESSION_DEPTH = 64;
4
+ export declare const MAX_SCRIPT_ID_LENGTH = 24;
5
+ export declare const MAX_KEYBINDINGS_COUNT = 256;
6
+ export declare const SCRIPT_RUN_COMMAND_PATTERN: Schema.TemplateLiteral<readonly [Schema.Literal<"script.">, Schema.String, Schema.Literal<".run">]>;
7
+ export declare const KeybindingCommand: Schema.Union<readonly [Schema.Literals<readonly ["terminal.toggle", "terminal.split", "terminal.new", "terminal.close", "diff.toggle", "chat.new", "chat.newLocal", "editor.openFavorite"]>, Schema.TemplateLiteral<readonly [Schema.Literal<"script.">, Schema.String, Schema.Literal<".run">]>]>;
8
+ export type KeybindingCommand = typeof KeybindingCommand.Type;
9
+ export declare const KeybindingRule: Schema.Struct<{
10
+ readonly key: Schema.Trim;
11
+ readonly command: Schema.Union<readonly [Schema.Literals<readonly ["terminal.toggle", "terminal.split", "terminal.new", "terminal.close", "diff.toggle", "chat.new", "chat.newLocal", "editor.openFavorite"]>, Schema.TemplateLiteral<readonly [Schema.Literal<"script.">, Schema.String, Schema.Literal<".run">]>]>;
12
+ readonly when: Schema.optional<Schema.Trim>;
13
+ }>;
14
+ export type KeybindingRule = typeof KeybindingRule.Type;
15
+ export declare const KeybindingsConfig: Schema.$Array<Schema.Struct<{
16
+ readonly key: Schema.Trim;
17
+ readonly command: Schema.Union<readonly [Schema.Literals<readonly ["terminal.toggle", "terminal.split", "terminal.new", "terminal.close", "diff.toggle", "chat.new", "chat.newLocal", "editor.openFavorite"]>, Schema.TemplateLiteral<readonly [Schema.Literal<"script.">, Schema.String, Schema.Literal<".run">]>]>;
18
+ readonly when: Schema.optional<Schema.Trim>;
19
+ }>>;
20
+ export type KeybindingsConfig = typeof KeybindingsConfig.Type;
21
+ export declare const KeybindingShortcut: Schema.Struct<{
22
+ readonly key: Schema.Trim;
23
+ readonly metaKey: Schema.Boolean;
24
+ readonly ctrlKey: Schema.Boolean;
25
+ readonly shiftKey: Schema.Boolean;
26
+ readonly altKey: Schema.Boolean;
27
+ readonly modKey: Schema.Boolean;
28
+ }>;
29
+ export type KeybindingShortcut = typeof KeybindingShortcut.Type;
30
+ export declare const KeybindingWhenNode: Schema.Schema<KeybindingWhenNode>;
31
+ export type KeybindingWhenNode = {
32
+ type: "identifier";
33
+ name: string;
34
+ } | {
35
+ type: "not";
36
+ node: KeybindingWhenNode;
37
+ } | {
38
+ type: "and";
39
+ left: KeybindingWhenNode;
40
+ right: KeybindingWhenNode;
41
+ } | {
42
+ type: "or";
43
+ left: KeybindingWhenNode;
44
+ right: KeybindingWhenNode;
45
+ };
46
+ export declare const ResolvedKeybindingRule: Schema.Struct<{
47
+ readonly command: Schema.Union<readonly [Schema.Literals<readonly ["terminal.toggle", "terminal.split", "terminal.new", "terminal.close", "diff.toggle", "chat.new", "chat.newLocal", "editor.openFavorite"]>, Schema.TemplateLiteral<readonly [Schema.Literal<"script.">, Schema.String, Schema.Literal<".run">]>]>;
48
+ readonly shortcut: Schema.Struct<{
49
+ readonly key: Schema.Trim;
50
+ readonly metaKey: Schema.Boolean;
51
+ readonly ctrlKey: Schema.Boolean;
52
+ readonly shiftKey: Schema.Boolean;
53
+ readonly altKey: Schema.Boolean;
54
+ readonly modKey: Schema.Boolean;
55
+ }>;
56
+ readonly whenAst: Schema.optional<Schema.Schema<KeybindingWhenNode>>;
57
+ }>;
58
+ export type ResolvedKeybindingRule = typeof ResolvedKeybindingRule.Type;
59
+ export declare const ResolvedKeybindingsConfig: Schema.$Array<Schema.Struct<{
60
+ readonly command: Schema.Union<readonly [Schema.Literals<readonly ["terminal.toggle", "terminal.split", "terminal.new", "terminal.close", "diff.toggle", "chat.new", "chat.newLocal", "editor.openFavorite"]>, Schema.TemplateLiteral<readonly [Schema.Literal<"script.">, Schema.String, Schema.Literal<".run">]>]>;
61
+ readonly shortcut: Schema.Struct<{
62
+ readonly key: Schema.Trim;
63
+ readonly metaKey: Schema.Boolean;
64
+ readonly ctrlKey: Schema.Boolean;
65
+ readonly shiftKey: Schema.Boolean;
66
+ readonly altKey: Schema.Boolean;
67
+ readonly modKey: Schema.Boolean;
68
+ }>;
69
+ readonly whenAst: Schema.optional<Schema.Schema<KeybindingWhenNode>>;
70
+ }>>;
71
+ export type ResolvedKeybindingsConfig = typeof ResolvedKeybindingsConfig.Type;
@@ -16,6 +16,9 @@ var WorkspaceId = makeEntityId("WorkspaceId");
16
16
  var GraphId = makeEntityId("GraphId");
17
17
  var TaskId = makeEntityId("TaskId");
18
18
  var RunId = makeEntityId("RunId");
19
+ var SafePathSegment = TrimmedNonEmptyString.check(Schema.isPattern(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/)).pipe(Schema.brand("SafePathSegment"));
20
+ var SafeRunId = TrimmedNonEmptyString.check(Schema.isPattern(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/)).pipe(Schema.brand("SafeRunId"));
21
+ var SafeGitRefComponent = TrimmedNonEmptyString.check(Schema.isPattern(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/)).pipe(Schema.brand("SafeGitRefComponent"));
19
22
  var EngineRuntimeId = makeEntityId("EngineRuntimeId");
20
23
  var ConversationId = makeEntityId("ConversationId");
21
24
  var ActionId = makeEntityId("ActionId");
@@ -0,0 +1,49 @@
1
+ /** Directory name for a project's checked-in rig definition (`<root>/rig`). */
2
+ export declare const RIG_DEFINITION_DIRNAME = "rig";
3
+ /** Directory name for rig's per-project state (`<root>/.rig`). */
4
+ export declare const RIG_STATE_DIRNAME = ".rig";
5
+ /** Directory name for run artifacts (`<workspace>/artifacts`). */
6
+ export declare const RIG_ARTIFACTS_DIRNAME = "artifacts";
7
+ export type RigLayout = {
8
+ projectRoot: string;
9
+ monorepoRoot: string;
10
+ definitionRoot: string;
11
+ runtimeWorkspaceRoot: string;
12
+ stateRoot: string;
13
+ artifactsRoot: string;
14
+ configPath: string;
15
+ taskConfigPath: string;
16
+ policyDir: string;
17
+ policyFile: string;
18
+ pluginsDir: string;
19
+ hooksDir: string;
20
+ toolsDir: string;
21
+ templatesDir: string;
22
+ validationDir: string;
23
+ stateDir: string;
24
+ logsDir: string;
25
+ notificationsDir: string;
26
+ runtimeDir: string;
27
+ distDir: string;
28
+ binDir: string;
29
+ pluginBinDir: string;
30
+ keybindingsPath: string;
31
+ controlPlaneEventsFile: string;
32
+ };
33
+ export type RuntimeWorkspaceLayout = {
34
+ workspaceDir: string;
35
+ rigRoot: string;
36
+ stateDir: string;
37
+ logsDir: string;
38
+ artifactsRoot: string;
39
+ runtimeDir: string;
40
+ homeDir: string;
41
+ tmpDir: string;
42
+ cacheDir: string;
43
+ sessionDir: string;
44
+ binDir: string;
45
+ distDir: string;
46
+ pluginBinDir: string;
47
+ contextPath: string;
48
+ controlPlaneEventsFile: string;
49
+ };
@@ -0,0 +1,10 @@
1
+ // @bun
2
+ // packages/contracts/src/layout.ts
3
+ var RIG_DEFINITION_DIRNAME = "rig";
4
+ var RIG_STATE_DIRNAME = ".rig";
5
+ var RIG_ARTIFACTS_DIRNAME = "artifacts";
6
+ export {
7
+ RIG_STATE_DIRNAME,
8
+ RIG_DEFINITION_DIRNAME,
9
+ RIG_ARTIFACTS_DIRNAME
10
+ };
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Typed ports for the default-lifecycle bundle's verification services.
3
+ *
4
+ * The dumb runtime substrate (rig-agent, harness-cli) must NOT import the
5
+ * lifecycle bundle (substrate->plugin cycle). Instead the bundle plugin
6
+ * registers executable impls under these ids on its
7
+ * `contributes.capabilities[].run`, and the runtime resolves them by id from
8
+ * `pluginHost.listExecutableCapabilities()`. These pure types are the shared
9
+ * contract for that seam — they carry no behaviour and import nothing.
10
+ */
11
+ import type { CapabilityId } from "./capability-id";
12
+ import type { JournalCapability } from "./kernel";
13
+ import type { RigAutomationConfig, StrictPrGreptileApiOptions } from "./control-plane-types";
14
+ import type { RunCloseoutPhase, RunCloseoutPhaseOutcome } from "./run-journal";
15
+ /** Capability id the bundle registers its `taskVerify` orchestration under. */
16
+ export declare const TASK_VERIFY_CAPABILITY_ID = "default-lifecycle.task-verify";
17
+ /** Capability id the bundle registers the completion-verification gate under. */
18
+ export declare const COMPLETION_VERIFICATION_CAPABILITY_ID = "default-lifecycle.completion-verification";
19
+ /** Capability id the bundle registers its run-worker closeout driver under. */
20
+ export declare const RUN_CLOSEOUT_CAPABILITY_ID = "default-lifecycle.run-closeout";
21
+ /** Capability id the bundle registers its agent-facing git helper surface under. */
22
+ export declare const LIFECYCLE_GIT_AGENT_CAPABILITY_ID = "default-lifecycle.git-agent";
23
+ export interface TaskVerifyCapabilityInput {
24
+ readonly projectRoot: string;
25
+ readonly taskId?: string;
26
+ }
27
+ /** Resolves true when the task is approved, false when verification rejects. */
28
+ export type TaskVerifyCapabilityRun = (input: TaskVerifyCapabilityInput) => Promise<boolean>;
29
+ /**
30
+ * The typed capability id the bundle provides its task-verify run under, phantom-
31
+ * typed with {@link TaskVerifyCapabilityRun} so `defineCapability(TASK_VERIFY_CAPABILITY)`
32
+ * resolves to the run function with no cast leaking to callers. Its string value
33
+ * is {@link TASK_VERIFY_CAPABILITY_ID}, so it indexes the same host entry.
34
+ */
35
+ export declare const TASK_VERIFY_CAPABILITY: CapabilityId<TaskVerifyCapabilityRun>;
36
+ export interface CompletionVerificationCapabilityInput {
37
+ readonly projectRoot: string;
38
+ readonly taskId?: string;
39
+ }
40
+ export interface CompletionVerificationCapabilityResult {
41
+ /** True when every completion gate passed; false when the gate blocks. */
42
+ readonly ok: boolean;
43
+ }
44
+ export type CompletionVerificationCapabilityRun = (input: CompletionVerificationCapabilityInput) => Promise<CompletionVerificationCapabilityResult>;
45
+ /**
46
+ * The typed capability id the bundle provides its completion-verification gate
47
+ * under, phantom-typed with {@link CompletionVerificationCapabilityRun}. Its
48
+ * string value is {@link COMPLETION_VERIFICATION_CAPABILITY_ID}, so it indexes
49
+ * the same host entry.
50
+ */
51
+ export declare const COMPLETION_VERIFICATION_CAPABILITY: CapabilityId<CompletionVerificationCapabilityRun>;
52
+ export type LifecycleGitCommitOptions = {
53
+ projectRoot: string;
54
+ taskId?: string;
55
+ target: "monorepo" | "project" | "both";
56
+ message?: string;
57
+ allowEmpty: boolean;
58
+ scoped?: boolean;
59
+ };
60
+ export type LifecycleGitOpenPrOptions = {
61
+ projectRoot: string;
62
+ taskId?: string;
63
+ target?: "monorepo" | "project";
64
+ reviewer?: string;
65
+ base?: string;
66
+ title?: string;
67
+ body?: string;
68
+ draft?: boolean;
69
+ };
70
+ export type LifecycleGitOpenPrResult = {
71
+ url: string;
72
+ reviewer?: string;
73
+ reviewerSource?: "flag" | "task-config" | "changed-files" | "env";
74
+ target: "monorepo" | "project";
75
+ repoLabel: string;
76
+ branch: string;
77
+ base: string;
78
+ };
79
+ export type LifecycleGitAgentService = {
80
+ shouldScopeGitCommit(args: string[], hasTaskContext: boolean): boolean;
81
+ gitStatus(projectRoot: string, taskId?: string): void;
82
+ gitChanged(projectRoot: string, taskId: string | undefined, scoped: boolean): string[];
83
+ gitPreflight(projectRoot: string, taskId: string | undefined, strict: boolean): boolean;
84
+ gitSyncBranch(projectRoot: string, taskId?: string, targetRepo?: "monorepo" | "project"): void;
85
+ gitCommit(options: LifecycleGitCommitOptions): void;
86
+ gitSnapshot(projectRoot: string, taskId?: string, outputPath?: string): string;
87
+ gitOpenPr(options: LifecycleGitOpenPrOptions): LifecycleGitOpenPrResult;
88
+ };
89
+ export declare const LIFECYCLE_GIT_AGENT: CapabilityId<LifecycleGitAgentService>;
90
+ export type RunTaskSourceReflectStatus = "under_review" | "ci_fixing" | "merging" | "closed" | "needs_attention";
91
+ export type RunCloseoutResultStatus = "merged" | "opened" | "skipped" | "needs-attention";
92
+ export type RunCloseoutResult = {
93
+ status: RunCloseoutResultStatus;
94
+ prUrl?: string;
95
+ iterations: number;
96
+ feedback: readonly string[];
97
+ };
98
+ export type RunCloseoutValidationInput = {
99
+ projectRoot: string;
100
+ taskId: string;
101
+ };
102
+ export type RunCloseoutValidationRunner = (input: RunCloseoutValidationInput) => Promise<boolean> | boolean;
103
+ export type RunCloseoutInput = {
104
+ projectRoot: string;
105
+ runId: string;
106
+ taskId: string;
107
+ branch: string;
108
+ workspace: string;
109
+ artifactRoot?: string | null;
110
+ config?: RigAutomationConfig | null;
111
+ sourceTask?: Record<string, unknown> | null;
112
+ steerPi: (message: string) => Promise<void>;
113
+ greptileApi?: StrictPrGreptileApiOptions;
114
+ runValidation?: RunCloseoutValidationRunner;
115
+ onValidationStart?: () => Promise<void> | void;
116
+ kernelJournal?: JournalCapability | null;
117
+ journalPhase: (phase: RunCloseoutPhase, outcome: RunCloseoutPhaseOutcome, detail?: string | null) => Promise<void> | void;
118
+ reflect: (status: RunTaskSourceReflectStatus, summary: string, options?: {
119
+ errorText?: string | null;
120
+ }) => Promise<void> | void;
121
+ };
122
+ export type RunCloseoutCapabilityRun = (input: RunCloseoutInput) => Promise<RunCloseoutResult>;
123
+ /**
124
+ * The typed capability id the bundle provides its run-worker closeout driver
125
+ * under, so @rig/run-worker can close out by resolving the lifecycle capability
126
+ * instead of importing the lifecycle plugin implementation.
127
+ */
128
+ export declare const RUN_CLOSEOUT_CAPABILITY: CapabilityId<RunCloseoutCapabilityRun>;
@@ -0,0 +1,25 @@
1
+ // @bun
2
+ // packages/contracts/src/capability-id.ts
3
+ function makeCapabilityId(id) {
4
+ return id;
5
+ }
6
+
7
+ // packages/contracts/src/lifecycle-capabilities.ts
8
+ var TASK_VERIFY_CAPABILITY_ID = "default-lifecycle.task-verify";
9
+ var COMPLETION_VERIFICATION_CAPABILITY_ID = "default-lifecycle.completion-verification";
10
+ var RUN_CLOSEOUT_CAPABILITY_ID = "default-lifecycle.run-closeout";
11
+ var LIFECYCLE_GIT_AGENT_CAPABILITY_ID = "default-lifecycle.git-agent";
12
+ var TASK_VERIFY_CAPABILITY = makeCapabilityId(TASK_VERIFY_CAPABILITY_ID);
13
+ var COMPLETION_VERIFICATION_CAPABILITY = makeCapabilityId(COMPLETION_VERIFICATION_CAPABILITY_ID);
14
+ var LIFECYCLE_GIT_AGENT = makeCapabilityId(LIFECYCLE_GIT_AGENT_CAPABILITY_ID);
15
+ var RUN_CLOSEOUT_CAPABILITY = makeCapabilityId(RUN_CLOSEOUT_CAPABILITY_ID);
16
+ export {
17
+ TASK_VERIFY_CAPABILITY_ID,
18
+ TASK_VERIFY_CAPABILITY,
19
+ RUN_CLOSEOUT_CAPABILITY_ID,
20
+ RUN_CLOSEOUT_CAPABILITY,
21
+ LIFECYCLE_GIT_AGENT_CAPABILITY_ID,
22
+ LIFECYCLE_GIT_AGENT,
23
+ COMPLETION_VERIFICATION_CAPABILITY_ID,
24
+ COMPLETION_VERIFICATION_CAPABILITY
25
+ };
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Pure managed-repo and repo-operation contract types + capability ids.
3
+ *
4
+ * `@rig/repos-plugin` owns the concrete implementations. It contributes:
5
+ * - `ManagedRepoService` under {@link MANAGED_REPO_SERVICE_CAPABILITY_ID} for
6
+ * registry/layout/mirror state, and
7
+ * - `RepoOperationsService` under {@link REPO_OPERATIONS_CAPABILITY_ID} for
8
+ * task repo pinning, baseline reset, and project-main pre-run sync.
9
+ *
10
+ * This module carries no behaviour and imports only pure sibling types, so
11
+ * consumers resolve typed ids through `@rig/core` without importing the provider
12
+ * plugin or the old kernel repo-ops facades.
13
+ */
14
+ import type { CapabilityId } from "./capability-id";
15
+ import type { RepoSourceRegistration } from "./plugin";
16
+ export type ManagedRepoId = string;
17
+ export type ManagedRepoAlias = string;
18
+ export type ManagedRepoHealth = "missing" | "ready" | "stale" | "misconfigured";
19
+ export type ManagedRepoRegistryEntry = {
20
+ id: ManagedRepoId;
21
+ alias: ManagedRepoAlias;
22
+ defaultBranch: string;
23
+ defaultRemoteUrl: string;
24
+ remoteEnvVar?: string;
25
+ checkoutEnvVar?: string;
26
+ };
27
+ export type ManagedRepoLayout = {
28
+ projectRoot: string;
29
+ repoId: ManagedRepoId;
30
+ alias: ManagedRepoAlias;
31
+ defaultBranch: string;
32
+ remoteUrl: string;
33
+ checkoutRoot: string;
34
+ worktreesRoot: string;
35
+ stateDir: string;
36
+ metadataRoot: string;
37
+ metadataRelativePath: string;
38
+ mirrorRoot: string;
39
+ mirrorStatePath: string;
40
+ mirrorStateRelativePath: string;
41
+ };
42
+ export type ManagedRepoMirrorState = {
43
+ version: 1;
44
+ repoId: ManagedRepoId;
45
+ remoteUrl: string;
46
+ defaultBranch: string;
47
+ initializedAt?: string;
48
+ lastSyncedAt?: string;
49
+ headRef?: string;
50
+ headCommit?: string;
51
+ };
52
+ export type ManagedRepoSyncResult = {
53
+ layout: ManagedRepoLayout;
54
+ headCommit: string;
55
+ };
56
+ /** A repo registration plus an optional computed local checkout path. */
57
+ export interface RepoEntry extends RepoSourceRegistration {
58
+ /** Optional computed local checkout path (runtime-specific, may be set by caller). */
59
+ localPath?: string;
60
+ }
61
+ /** An immutable, id-indexed view over plugin-contributed repo sources. */
62
+ export interface RepoRegistry {
63
+ getById(id: string): RepoEntry | undefined;
64
+ list(): readonly RepoEntry[];
65
+ }
66
+ /**
67
+ * The cohesive set of managed-repo operations the runtime substrate depends on.
68
+ * The plugin provides a concrete impl (statically checked against this interface
69
+ * via `defineCapability(MANAGED_REPO_SERVICE_CAPABILITY).provide`); the substrate
70
+ * only ever sees this port, resolved by id off a plugin host with no cast.
71
+ */
72
+ export interface ManagedRepoService {
73
+ /** Replace the managed-repo singleton with the given entries (boot wiring). */
74
+ setManagedRepos(entries: readonly ManagedRepoRegistryEntry[]): void;
75
+ /** List the currently registered managed-repo entries. */
76
+ listManagedRepoEntries(): ManagedRepoRegistryEntry[];
77
+ /** Resolve a managed-repo id from its alias, or null when unknown. */
78
+ resolveManagedRepoIdByAlias(alias: string): ManagedRepoId | null;
79
+ /**
80
+ * Convert a plugin-contributed RepoSourceRegistration into the managed-repo
81
+ * entry shape; null for pure-listing registrations (no defaultBranch).
82
+ */
83
+ repoRegistrationToManagedEntry(reg: RepoSourceRegistration): ManagedRepoRegistryEntry | null;
84
+ /** Build an immutable id-indexed registry from repo source registrations. */
85
+ createRepoRegistry(entries: readonly RepoSourceRegistration[]): RepoRegistry;
86
+ /** Resolve a managed repo's on-disk layout by alias, or null when unknown. */
87
+ resolveManagedRepoLayoutByAlias(projectRoot: string, alias: string): ManagedRepoLayout | null;
88
+ /** Resolve the primary monorepo layout; throws when no managed repos exist. */
89
+ resolveMonorepoRepoLayout(projectRoot: string): ManagedRepoLayout;
90
+ /** Refresh + sync a managed repo's mirror, returning the resulting head. */
91
+ syncManagedRepo(projectRoot: string, repoId: ManagedRepoId): ManagedRepoSyncResult;
92
+ }
93
+ export type RepoPins = Record<string, string>;
94
+ export type ProjectMainPreRunSyncResult = {
95
+ status: "disabled";
96
+ } | {
97
+ status: "skipped_not_main";
98
+ branch: string;
99
+ } | {
100
+ status: "up_to_date";
101
+ } | {
102
+ status: "local_ahead";
103
+ localAhead: number;
104
+ } | {
105
+ status: "updated";
106
+ remoteAhead: number;
107
+ };
108
+ export type ProjectMainPreRunSyncOptions = {
109
+ projectRoot: string;
110
+ disabled?: boolean;
111
+ runBootstrap: () => Promise<void>;
112
+ syncMonorepo?: (projectRoot: string) => void | Promise<void>;
113
+ };
114
+ export interface RepoOperationsService {
115
+ repoEnsure(projectRoot: string, taskId?: string): void;
116
+ repoPins(projectRoot: string, taskId?: string): RepoPins;
117
+ repoVerify(projectRoot: string, taskId?: string): boolean;
118
+ repoDiscover(projectRoot: string, taskId?: string): RepoPins;
119
+ repoBaseline(projectRoot: string, refresh?: boolean): RepoPins;
120
+ resetBaseline(projectRoot: string, keepTaskStatus: boolean): void;
121
+ ensureProjectMainFreshBeforeRun(options: ProjectMainPreRunSyncOptions): Promise<ProjectMainPreRunSyncResult>;
122
+ }
123
+ export declare const REPO_OPERATIONS_CAPABILITY_ID = "repos.operations";
124
+ export declare const REPO_OPERATIONS_CAPABILITY: CapabilityId<RepoOperationsService>;
125
+ /** The capability `run` shape the plugin registers: a (lazy) service factory. */
126
+ export type ManagedRepoServiceCapabilityRun = () => ManagedRepoService | Promise<ManagedRepoService>;
127
+ /** Capability id the managed-repo service plugin registers its factory under. */
128
+ export declare const MANAGED_REPO_SERVICE_CAPABILITY_ID = "managed-repos.service";
129
+ /**
130
+ * The typed capability id the repos plugin provides and consumers require.
131
+ * Phantom-typed with {@link ManagedRepoService} so
132
+ * `defineCapability(MANAGED_REPO_SERVICE_CAPABILITY).resolve(host)` returns a
133
+ * `ManagedRepoService` with no cast leaking to callers. Its string value is
134
+ * {@link MANAGED_REPO_SERVICE_CAPABILITY_ID}, so it indexes the same host entry.
135
+ */
136
+ export declare const MANAGED_REPO_SERVICE_CAPABILITY: CapabilityId<ManagedRepoService>;
@@ -0,0 +1,17 @@
1
+ // @bun
2
+ // packages/contracts/src/capability-id.ts
3
+ function makeCapabilityId(id) {
4
+ return id;
5
+ }
6
+
7
+ // packages/contracts/src/managed-repos.ts
8
+ var REPO_OPERATIONS_CAPABILITY_ID = "repos.operations";
9
+ var REPO_OPERATIONS_CAPABILITY = makeCapabilityId(REPO_OPERATIONS_CAPABILITY_ID);
10
+ var MANAGED_REPO_SERVICE_CAPABILITY_ID = "managed-repos.service";
11
+ var MANAGED_REPO_SERVICE_CAPABILITY = makeCapabilityId(MANAGED_REPO_SERVICE_CAPABILITY_ID);
12
+ export {
13
+ REPO_OPERATIONS_CAPABILITY_ID,
14
+ REPO_OPERATIONS_CAPABILITY,
15
+ MANAGED_REPO_SERVICE_CAPABILITY_ID,
16
+ MANAGED_REPO_SERVICE_CAPABILITY
17
+ };
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Pure memory-service contract types.
3
+ *
4
+ * These types are the neutral home for the shared-memory data model so that the
5
+ * dumb runtime substrate (hooks, harness-cli, isolation, rig-agent) and the
6
+ * @rig/memory-plugin that owns the implementation can both reference them
7
+ * without a substrate->plugin import cycle. They carry no behaviour and import
8
+ * nothing — exactly like `lifecycle-capabilities.ts`.
9
+ *
10
+ * The plugin registers its executable `MemoryService` impl under the typed
11
+ * capability id {@link MEMORY} (whose string value is
12
+ * {@link MEMORY_SERVICE_CAPABILITY_ID}); the runtime resolves it by id from
13
+ * `pluginHost.listExecutableCapabilities()` via the `defineCapability` seam
14
+ * (`@rig/core/capability`), re-exported from the thin
15
+ * `@rig/runtime/control-plane/memory-service-port`.
16
+ */
17
+ import type { CapabilityId } from "./capability-id";
18
+ import type { RuntimeMemoryRetrievalConfig, RuntimeTaskContext } from "./runtime-task-context";
19
+ /** Capability id the memory plugin registers its `MemoryService` factory under. */
20
+ export declare const MEMORY_SERVICE_CAPABILITY_ID = "memory.service";
21
+ export declare const NO_MATCH_RETRIEVAL_CANONICAL_KEY = "__memory_recall__:none";
22
+ export type MemoryDbStatement = {
23
+ sql: string;
24
+ args?: unknown[];
25
+ };
26
+ export type MemoryDbExecuteResult = {
27
+ rows: Array<Record<string, unknown>>;
28
+ rowsAffected?: number;
29
+ };
30
+ export type MemoryDbTransaction = {
31
+ execute(statement: MemoryDbStatement | string, args?: unknown[]): Promise<MemoryDbExecuteResult>;
32
+ commit(): Promise<void>;
33
+ rollback(): Promise<void>;
34
+ close(): void;
35
+ };
36
+ export type MemoryDbClient = {
37
+ execute(statement: MemoryDbStatement | string, args?: unknown[]): Promise<MemoryDbExecuteResult>;
38
+ transaction(mode: "write"): Promise<MemoryDbTransaction>;
39
+ close(): void;
40
+ };
41
+ export type MemoryEventType = "observed" | "promoted" | "corrected" | "superseded" | "retracted" | "reinforced" | "retrieved" | "feedback_recorded";
42
+ export type MemoryStatus = "active" | "superseded" | "retracted";
43
+ export type RetrievalFeedbackOutcome = "helpful" | "ignored" | "incorrect";
44
+ type MemoryEventBase = {
45
+ eventId: string;
46
+ canonicalKey: string;
47
+ sourceRunId?: string | null;
48
+ sourceTaskId?: string | null;
49
+ branch?: string | null;
50
+ createdAt: string;
51
+ };
52
+ type MemoryProjectionSeed = {
53
+ summary: string;
54
+ kind: string;
55
+ category?: string | null;
56
+ confidence: number;
57
+ details?: Record<string, unknown> | null;
58
+ };
59
+ export type MemoryEventInput = (MemoryEventBase & MemoryProjectionSeed & {
60
+ eventType: "observed";
61
+ }) | (MemoryEventBase & MemoryProjectionSeed & {
62
+ eventType: "promoted";
63
+ sourceCanonicalKey: string;
64
+ }) | (MemoryEventBase & MemoryProjectionSeed & {
65
+ eventType: "corrected";
66
+ sourceCanonicalKey: string;
67
+ }) | (MemoryEventBase & {
68
+ eventType: "superseded";
69
+ replacementCanonicalKey: string;
70
+ }) | (MemoryEventBase & {
71
+ eventType: "retracted";
72
+ }) | (MemoryEventBase & {
73
+ eventType: "reinforced";
74
+ confidence: number;
75
+ }) | (MemoryEventBase & {
76
+ eventType: "retrieved";
77
+ retrievalQuery: string;
78
+ retrievalRank: number;
79
+ }) | (MemoryEventBase & {
80
+ eventType: "feedback_recorded";
81
+ feedbackOutcome: RetrievalFeedbackOutcome;
82
+ retrievalRank: number;
83
+ retrievalQuery?: string | null;
84
+ });
85
+ export type MemoryEventMetadata = {
86
+ sourceCanonicalKey?: string | null;
87
+ replacementCanonicalKey?: string | null;
88
+ retrievalQuery?: string | null;
89
+ retrievalRank?: number | null;
90
+ feedbackOutcome?: RetrievalFeedbackOutcome | null;
91
+ summary?: string | null;
92
+ kind?: string | null;
93
+ category?: string | null;
94
+ confidence?: number | null;
95
+ details?: Record<string, unknown> | null;
96
+ };
97
+ export type MemoryEventRow = {
98
+ eventId: string;
99
+ eventType: MemoryEventType;
100
+ canonicalKey: string;
101
+ summary: string;
102
+ createdAt: string;
103
+ };
104
+ export type MemoryItemRow = {
105
+ canonicalKey: string;
106
+ summary: string;
107
+ kind: string | null;
108
+ category: string | null;
109
+ status: MemoryStatus;
110
+ confidence: number;
111
+ sourceRunId: string | null;
112
+ sourceTaskId: string | null;
113
+ branch: string | null;
114
+ details: Record<string, unknown> | null;
115
+ createdAt: string;
116
+ updatedAt: string;
117
+ lastEventId: string;
118
+ supersededBy: string | null;
119
+ embedding: number[] | null;
120
+ };
121
+ export type MemoryQueryOptions = {
122
+ canonicalKey?: string;
123
+ includeInactive?: boolean;
124
+ };
125
+ export type MemoryDb = {
126
+ path: string;
127
+ client: MemoryDbClient;
128
+ close(): Promise<void>;
129
+ };
130
+ /** A scored, ranked shared-memory item returned by the retrieval query. */
131
+ export type MemoryQueryResult = {
132
+ canonicalKey: string;
133
+ summary: string;
134
+ kind: string | null;
135
+ category: string | null;
136
+ confidence: number;
137
+ updatedAt: string;
138
+ score: number;
139
+ lexicalScore: number;
140
+ vectorScore: number;
141
+ recencyScore: number;
142
+ };
143
+ /** Embeds text into vectors for memory retrieval; provider-agnostic. */
144
+ export type MemoryEmbedder = {
145
+ embed(texts: string[]): Promise<number[][]>;
146
+ };
147
+ /** A materialized read-only snapshot of the canonical project-memory database. */
148
+ export type CanonicalMemorySnapshot = {
149
+ repoPath: string;
150
+ baseOid: string;
151
+ dbPath: string;
152
+ createdFresh: boolean;
153
+ cleanup(): Promise<void>;
154
+ };
155
+ /**
156
+ * Minimal telemetry sink the memory command emits run events through. The
157
+ * substrate's concrete event bus (`@rig/runtime` `EventBusLike`) is a superset
158
+ * and is structurally assignable to this; the memory contract only depends on
159
+ * `emit`, so the pure contract stays free of any runtime/behaviour import.
160
+ */
161
+ export interface MemoryCommandEventSink {
162
+ emit<TPayload extends Record<string, unknown>>(type: string, payload: TPayload): Promise<unknown>;
163
+ }
164
+ /** Options for the agent-facing `rig-agent memory <verb>` command dispatch. */
165
+ export type ExecuteMemoryCommandOptions = {
166
+ projectRoot: string;
167
+ taskId: string;
168
+ runtimeContext: RuntimeTaskContext | null;
169
+ args: string[];
170
+ eventBus?: MemoryCommandEventSink;
171
+ };
172
+ /** The retrieval-query shape the substrate passes through to the impl. */
173
+ export type MemoryQueryPortInput = {
174
+ query: string;
175
+ limit?: number;
176
+ retrieval?: RuntimeMemoryRetrievalConfig;
177
+ };
178
+ /**
179
+ * The cohesive set of shared-memory operations the runtime consumers depend on.
180
+ * This is pure capability VOCAB: the `@rig/memory-plugin` provides a concrete
181
+ * impl (statically checked against this interface via `MemoryCap.provide`), and
182
+ * the substrate only ever sees this contract — resolved by id off a plugin host
183
+ * with no `as unknown as` at any call site.
184
+ */
185
+ export interface MemoryService {
186
+ executeMemoryCommand(options: ExecuteMemoryCommandOptions): Promise<string>;
187
+ readCanonicalMemoryDb(projectRoot: string): Promise<CanonicalMemorySnapshot>;
188
+ openMemoryDb(dbPath: string): Promise<MemoryDb>;
189
+ queryRelevantMemory(db: MemoryDb, input: MemoryQueryPortInput): Promise<MemoryQueryResult[]>;
190
+ formatMemoryQueryResults(results: MemoryQueryResult[]): string;
191
+ }
192
+ /**
193
+ * The typed capability id the memory plugin provides and consumers require.
194
+ * Phantom-typed with `MemoryService` so `MemoryCap.require(host)` returns a
195
+ * `MemoryService` with no cast leaking to callers. Its string value is
196
+ * {@link MEMORY_SERVICE_CAPABILITY_ID}, so it indexes the same host entry.
197
+ */
198
+ export declare const MEMORY: CapabilityId<MemoryService>;
199
+ export {};
@@ -0,0 +1,15 @@
1
+ // @bun
2
+ // packages/contracts/src/capability-id.ts
3
+ function makeCapabilityId(id) {
4
+ return id;
5
+ }
6
+
7
+ // packages/contracts/src/memory.ts
8
+ var MEMORY_SERVICE_CAPABILITY_ID = "memory.service";
9
+ var NO_MATCH_RETRIEVAL_CANONICAL_KEY = "__memory_recall__:none";
10
+ var MEMORY = makeCapabilityId(MEMORY_SERVICE_CAPABILITY_ID);
11
+ export {
12
+ NO_MATCH_RETRIEVAL_CANONICAL_KEY,
13
+ MEMORY_SERVICE_CAPABILITY_ID,
14
+ MEMORY
15
+ };