@kitsy/coop-ai 0.0.1 → 1.0.0

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/index.d.cts CHANGED
@@ -1,7 +1,205 @@
1
- type CoopAiRuntimePlaceholder = {
2
- readonly package: "@kitsy/coop-ai";
3
- readonly status: "planned";
4
- };
5
- declare const coopAiRuntime: CoopAiRuntimePlaceholder;
1
+ import { Task, TaskGraph, Run, RunStatus, RunStepResult } from '@kitsy/coop-core';
6
2
 
7
- export { type CoopAiRuntimePlaceholder, coopAiRuntime };
3
+ interface AgentContractPermissions {
4
+ read_paths: string[];
5
+ write_paths: string[];
6
+ allowed_commands: string[];
7
+ forbidden_commands: string[];
8
+ }
9
+ interface AgentContractConstraints {
10
+ max_tokens: number;
11
+ max_duration_minutes: number;
12
+ max_file_changes: number;
13
+ require_tests: boolean;
14
+ }
15
+ interface AgentContractRelatedArtifacts {
16
+ task_id: string;
17
+ artifacts: Array<{
18
+ type: string;
19
+ target?: string;
20
+ path?: string;
21
+ }>;
22
+ }
23
+ interface AgentContractContext {
24
+ paths: string[];
25
+ files: string[];
26
+ tasks: string[];
27
+ acceptance_criteria: string[];
28
+ related_task_artifacts: AgentContractRelatedArtifacts[];
29
+ }
30
+ interface AgentContract {
31
+ task_id: string;
32
+ goal: string;
33
+ executor: string;
34
+ permissions: AgentContractPermissions;
35
+ constraints: AgentContractConstraints;
36
+ context: AgentContractContext;
37
+ output_requirements: string[];
38
+ }
39
+
40
+ /**
41
+ * Builds a sandboxed AI agent contract from a task and repo graph context.
42
+ * [SPEC: Architecture v2.0 §13.1, Task Schema v2.0 §8]
43
+ */
44
+ declare function build_contract(task: Task, graph: TaskGraph, config: unknown): AgentContract;
45
+
46
+ /**
47
+ * Selects the AI executor for a task based on complexity/type/review signals.
48
+ * [SPEC: Architecture v2.0 §13.3]
49
+ */
50
+ declare function select_agent(task: Task, config: unknown): string;
51
+
52
+ type FileAccessMode = "read" | "write";
53
+ interface SandboxRunState {
54
+ tokens_used: number;
55
+ duration_minutes: number;
56
+ file_changes: number;
57
+ }
58
+ /**
59
+ * Validates whether a shell command is permitted by the contract sandbox.
60
+ * [SPEC: Architecture v2.0 §13.2]
61
+ */
62
+ declare function validate_command(command: string, contract: AgentContract): boolean;
63
+ /**
64
+ * Validates whether the requested file access is within sandboxed paths.
65
+ * [SPEC: Architecture v2.0 §13.2]
66
+ */
67
+ declare function validate_file_access(pathValue: string, mode: FileAccessMode, contract: AgentContract): boolean;
68
+ declare function constraint_violation_reasons(runState: SandboxRunState, contract: AgentContract): string[];
69
+ /**
70
+ * Enforces token/time/file-change constraints for an active run.
71
+ * [SPEC: Architecture v2.0 §13.2]
72
+ */
73
+ declare function enforce_constraints(runState: SandboxRunState, contract: AgentContract): boolean;
74
+
75
+ /**
76
+ * Creates an execution run envelope for a task and executor.
77
+ * [SPEC: Architecture v2.0 §12]
78
+ */
79
+ declare function create_run(task: Task, executor: string, now?: Date): Run;
80
+ /**
81
+ * Appends a step result to an existing run.
82
+ * [SPEC: Architecture v2.0 §12]
83
+ */
84
+ declare function log_step(run: Run, step: RunStepResult): Run;
85
+ /**
86
+ * Finalizes a run status and completion timestamp.
87
+ * [SPEC: Architecture v2.0 §12]
88
+ */
89
+ declare function finalize_run(run: Run, status: RunStatus, now?: Date): Run;
90
+ /**
91
+ * Persists a run log under .coop/runs/.
92
+ * [SPEC: Architecture v2.0 §12]
93
+ */
94
+ declare function write_run(run: Run, coopDir: string): string;
95
+
96
+ interface AgentResponse {
97
+ summary: string;
98
+ tokens_used?: number;
99
+ file_changes?: number;
100
+ }
101
+ interface AgentClient {
102
+ generate(input: {
103
+ task: Task;
104
+ step: NonNullable<NonNullable<Task["execution"]>["runbook"]>[number];
105
+ contract: AgentContract;
106
+ prompt: string;
107
+ }): Promise<AgentResponse>;
108
+ review(input: {
109
+ task: Task;
110
+ step: NonNullable<NonNullable<Task["execution"]>["runbook"]>[number];
111
+ contract: AgentContract;
112
+ prompt: string;
113
+ }): Promise<AgentResponse>;
114
+ }
115
+ interface ExecuteTaskOptions {
116
+ repo_root?: string;
117
+ coop_dir?: string;
118
+ step?: string;
119
+ on_progress?: (message: string) => void;
120
+ agent_client?: AgentClient;
121
+ }
122
+ interface RunResult {
123
+ status: RunStatus;
124
+ run: Run;
125
+ log_path: string;
126
+ }
127
+ /**
128
+ * Executes a task runbook in a sandbox and writes an immutable run log.
129
+ * [SPEC: Architecture v2.0 §12, §13.2]
130
+ */
131
+ declare function execute_task(task: Task, contract: AgentContract, _graph: TaskGraph, options?: ExecuteTaskOptions): Promise<RunResult>;
132
+
133
+ interface IdeaDecompositionInput {
134
+ idea_id: string;
135
+ title: string;
136
+ body: string;
137
+ }
138
+ interface DecomposedTaskDraft {
139
+ title: string;
140
+ body?: string;
141
+ type?: "feature" | "bug" | "chore" | "spike";
142
+ priority?: "p0" | "p1" | "p2" | "p3";
143
+ track?: string;
144
+ }
145
+ interface IdeaDecomposerClient {
146
+ decompose(prompt: string, input: IdeaDecompositionInput): Promise<DecomposedTaskDraft[]>;
147
+ }
148
+ /**
149
+ * Builds a decomposition prompt used for idea-to-task expansion.
150
+ * [SPEC: Architecture v2.0 §Phase 4]
151
+ */
152
+ declare function build_decomposition_prompt(input: IdeaDecompositionInput): string;
153
+ /**
154
+ * Decomposes an idea into task drafts using a provided AI client or a deterministic fallback.
155
+ * [SPEC: Architecture v2.0 §Phase 4]
156
+ */
157
+ declare function decompose_idea_to_tasks(input: IdeaDecompositionInput, client?: IdeaDecomposerClient): Promise<DecomposedTaskDraft[]>;
158
+
159
+ type AiProviderName = "mock" | "openai" | "anthropic" | "gemini" | "ollama";
160
+ interface ProviderConfig {
161
+ provider: AiProviderName;
162
+ model: string;
163
+ base_url?: string;
164
+ api_key?: string;
165
+ temperature: number;
166
+ max_output_tokens: number;
167
+ timeout_ms: number;
168
+ }
169
+ interface CompletionInput {
170
+ system: string;
171
+ prompt: string;
172
+ }
173
+ interface CompletionResult {
174
+ text: string;
175
+ total_tokens?: number;
176
+ }
177
+ interface LlmProvider {
178
+ readonly name: AiProviderName;
179
+ complete(input: CompletionInput): Promise<CompletionResult>;
180
+ }
181
+
182
+ /**
183
+ * Resolves provider runtime settings from config and environment variables.
184
+ * [SPEC: Architecture v2.0 §13]
185
+ */
186
+ declare function resolve_provider_config(config: unknown): ProviderConfig;
187
+
188
+ /**
189
+ * Creates an LLM provider instance from COOP config.
190
+ * [SPEC: Architecture v2.0 §13]
191
+ */
192
+ declare function create_provider(config: unknown): LlmProvider;
193
+
194
+ /**
195
+ * Creates an executor client backed by configured LLM provider(s).
196
+ * [SPEC: Architecture v2.0 §13]
197
+ */
198
+ declare function create_provider_agent_client(config: unknown): AgentClient;
199
+ /**
200
+ * Creates an idea decomposition client backed by configured LLM provider(s).
201
+ * [SPEC: Architecture v2.0 §Phase 4]
202
+ */
203
+ declare function create_provider_idea_decomposer(config: unknown): IdeaDecomposerClient;
204
+
205
+ export { type AgentClient, type AgentContract, type AgentContractConstraints, type AgentContractContext, type AgentContractPermissions, type AgentContractRelatedArtifacts, type AgentResponse, type AiProviderName, type CompletionInput, type CompletionResult, type DecomposedTaskDraft, type ExecuteTaskOptions, type FileAccessMode, type IdeaDecomposerClient, type IdeaDecompositionInput, type LlmProvider, type ProviderConfig, type RunResult, type SandboxRunState, build_contract, build_decomposition_prompt, constraint_violation_reasons, create_provider, create_provider_agent_client, create_provider_idea_decomposer, create_run, decompose_idea_to_tasks, enforce_constraints, execute_task, finalize_run, log_step, resolve_provider_config, select_agent, validate_command, validate_file_access, write_run };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,205 @@
1
- type CoopAiRuntimePlaceholder = {
2
- readonly package: "@kitsy/coop-ai";
3
- readonly status: "planned";
4
- };
5
- declare const coopAiRuntime: CoopAiRuntimePlaceholder;
1
+ import { Task, TaskGraph, Run, RunStatus, RunStepResult } from '@kitsy/coop-core';
6
2
 
7
- export { type CoopAiRuntimePlaceholder, coopAiRuntime };
3
+ interface AgentContractPermissions {
4
+ read_paths: string[];
5
+ write_paths: string[];
6
+ allowed_commands: string[];
7
+ forbidden_commands: string[];
8
+ }
9
+ interface AgentContractConstraints {
10
+ max_tokens: number;
11
+ max_duration_minutes: number;
12
+ max_file_changes: number;
13
+ require_tests: boolean;
14
+ }
15
+ interface AgentContractRelatedArtifacts {
16
+ task_id: string;
17
+ artifacts: Array<{
18
+ type: string;
19
+ target?: string;
20
+ path?: string;
21
+ }>;
22
+ }
23
+ interface AgentContractContext {
24
+ paths: string[];
25
+ files: string[];
26
+ tasks: string[];
27
+ acceptance_criteria: string[];
28
+ related_task_artifacts: AgentContractRelatedArtifacts[];
29
+ }
30
+ interface AgentContract {
31
+ task_id: string;
32
+ goal: string;
33
+ executor: string;
34
+ permissions: AgentContractPermissions;
35
+ constraints: AgentContractConstraints;
36
+ context: AgentContractContext;
37
+ output_requirements: string[];
38
+ }
39
+
40
+ /**
41
+ * Builds a sandboxed AI agent contract from a task and repo graph context.
42
+ * [SPEC: Architecture v2.0 §13.1, Task Schema v2.0 §8]
43
+ */
44
+ declare function build_contract(task: Task, graph: TaskGraph, config: unknown): AgentContract;
45
+
46
+ /**
47
+ * Selects the AI executor for a task based on complexity/type/review signals.
48
+ * [SPEC: Architecture v2.0 §13.3]
49
+ */
50
+ declare function select_agent(task: Task, config: unknown): string;
51
+
52
+ type FileAccessMode = "read" | "write";
53
+ interface SandboxRunState {
54
+ tokens_used: number;
55
+ duration_minutes: number;
56
+ file_changes: number;
57
+ }
58
+ /**
59
+ * Validates whether a shell command is permitted by the contract sandbox.
60
+ * [SPEC: Architecture v2.0 §13.2]
61
+ */
62
+ declare function validate_command(command: string, contract: AgentContract): boolean;
63
+ /**
64
+ * Validates whether the requested file access is within sandboxed paths.
65
+ * [SPEC: Architecture v2.0 §13.2]
66
+ */
67
+ declare function validate_file_access(pathValue: string, mode: FileAccessMode, contract: AgentContract): boolean;
68
+ declare function constraint_violation_reasons(runState: SandboxRunState, contract: AgentContract): string[];
69
+ /**
70
+ * Enforces token/time/file-change constraints for an active run.
71
+ * [SPEC: Architecture v2.0 §13.2]
72
+ */
73
+ declare function enforce_constraints(runState: SandboxRunState, contract: AgentContract): boolean;
74
+
75
+ /**
76
+ * Creates an execution run envelope for a task and executor.
77
+ * [SPEC: Architecture v2.0 §12]
78
+ */
79
+ declare function create_run(task: Task, executor: string, now?: Date): Run;
80
+ /**
81
+ * Appends a step result to an existing run.
82
+ * [SPEC: Architecture v2.0 §12]
83
+ */
84
+ declare function log_step(run: Run, step: RunStepResult): Run;
85
+ /**
86
+ * Finalizes a run status and completion timestamp.
87
+ * [SPEC: Architecture v2.0 §12]
88
+ */
89
+ declare function finalize_run(run: Run, status: RunStatus, now?: Date): Run;
90
+ /**
91
+ * Persists a run log under .coop/runs/.
92
+ * [SPEC: Architecture v2.0 §12]
93
+ */
94
+ declare function write_run(run: Run, coopDir: string): string;
95
+
96
+ interface AgentResponse {
97
+ summary: string;
98
+ tokens_used?: number;
99
+ file_changes?: number;
100
+ }
101
+ interface AgentClient {
102
+ generate(input: {
103
+ task: Task;
104
+ step: NonNullable<NonNullable<Task["execution"]>["runbook"]>[number];
105
+ contract: AgentContract;
106
+ prompt: string;
107
+ }): Promise<AgentResponse>;
108
+ review(input: {
109
+ task: Task;
110
+ step: NonNullable<NonNullable<Task["execution"]>["runbook"]>[number];
111
+ contract: AgentContract;
112
+ prompt: string;
113
+ }): Promise<AgentResponse>;
114
+ }
115
+ interface ExecuteTaskOptions {
116
+ repo_root?: string;
117
+ coop_dir?: string;
118
+ step?: string;
119
+ on_progress?: (message: string) => void;
120
+ agent_client?: AgentClient;
121
+ }
122
+ interface RunResult {
123
+ status: RunStatus;
124
+ run: Run;
125
+ log_path: string;
126
+ }
127
+ /**
128
+ * Executes a task runbook in a sandbox and writes an immutable run log.
129
+ * [SPEC: Architecture v2.0 §12, §13.2]
130
+ */
131
+ declare function execute_task(task: Task, contract: AgentContract, _graph: TaskGraph, options?: ExecuteTaskOptions): Promise<RunResult>;
132
+
133
+ interface IdeaDecompositionInput {
134
+ idea_id: string;
135
+ title: string;
136
+ body: string;
137
+ }
138
+ interface DecomposedTaskDraft {
139
+ title: string;
140
+ body?: string;
141
+ type?: "feature" | "bug" | "chore" | "spike";
142
+ priority?: "p0" | "p1" | "p2" | "p3";
143
+ track?: string;
144
+ }
145
+ interface IdeaDecomposerClient {
146
+ decompose(prompt: string, input: IdeaDecompositionInput): Promise<DecomposedTaskDraft[]>;
147
+ }
148
+ /**
149
+ * Builds a decomposition prompt used for idea-to-task expansion.
150
+ * [SPEC: Architecture v2.0 §Phase 4]
151
+ */
152
+ declare function build_decomposition_prompt(input: IdeaDecompositionInput): string;
153
+ /**
154
+ * Decomposes an idea into task drafts using a provided AI client or a deterministic fallback.
155
+ * [SPEC: Architecture v2.0 §Phase 4]
156
+ */
157
+ declare function decompose_idea_to_tasks(input: IdeaDecompositionInput, client?: IdeaDecomposerClient): Promise<DecomposedTaskDraft[]>;
158
+
159
+ type AiProviderName = "mock" | "openai" | "anthropic" | "gemini" | "ollama";
160
+ interface ProviderConfig {
161
+ provider: AiProviderName;
162
+ model: string;
163
+ base_url?: string;
164
+ api_key?: string;
165
+ temperature: number;
166
+ max_output_tokens: number;
167
+ timeout_ms: number;
168
+ }
169
+ interface CompletionInput {
170
+ system: string;
171
+ prompt: string;
172
+ }
173
+ interface CompletionResult {
174
+ text: string;
175
+ total_tokens?: number;
176
+ }
177
+ interface LlmProvider {
178
+ readonly name: AiProviderName;
179
+ complete(input: CompletionInput): Promise<CompletionResult>;
180
+ }
181
+
182
+ /**
183
+ * Resolves provider runtime settings from config and environment variables.
184
+ * [SPEC: Architecture v2.0 §13]
185
+ */
186
+ declare function resolve_provider_config(config: unknown): ProviderConfig;
187
+
188
+ /**
189
+ * Creates an LLM provider instance from COOP config.
190
+ * [SPEC: Architecture v2.0 §13]
191
+ */
192
+ declare function create_provider(config: unknown): LlmProvider;
193
+
194
+ /**
195
+ * Creates an executor client backed by configured LLM provider(s).
196
+ * [SPEC: Architecture v2.0 §13]
197
+ */
198
+ declare function create_provider_agent_client(config: unknown): AgentClient;
199
+ /**
200
+ * Creates an idea decomposition client backed by configured LLM provider(s).
201
+ * [SPEC: Architecture v2.0 §Phase 4]
202
+ */
203
+ declare function create_provider_idea_decomposer(config: unknown): IdeaDecomposerClient;
204
+
205
+ export { type AgentClient, type AgentContract, type AgentContractConstraints, type AgentContractContext, type AgentContractPermissions, type AgentContractRelatedArtifacts, type AgentResponse, type AiProviderName, type CompletionInput, type CompletionResult, type DecomposedTaskDraft, type ExecuteTaskOptions, type FileAccessMode, type IdeaDecomposerClient, type IdeaDecompositionInput, type LlmProvider, type ProviderConfig, type RunResult, type SandboxRunState, build_contract, build_decomposition_prompt, constraint_violation_reasons, create_provider, create_provider_agent_client, create_provider_idea_decomposer, create_run, decompose_idea_to_tasks, enforce_constraints, execute_task, finalize_run, log_step, resolve_provider_config, select_agent, validate_command, validate_file_access, write_run };