@mingchuno/agent-workflows 0.1.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/LICENCE +21 -0
- package/README.md +74 -0
- package/dist/drizzle/0000_initial.sql +45 -0
- package/dist/drizzle/meta/0000_snapshot.json +264 -0
- package/dist/drizzle/meta/_journal.json +13 -0
- package/dist/src/adapters/agent-worker.d.ts +1 -0
- package/dist/src/adapters/agent-worker.js +16 -0
- package/dist/src/adapters/agents.d.ts +24 -0
- package/dist/src/adapters/agents.js +142 -0
- package/dist/src/adapters/hosting.d.ts +33 -0
- package/dist/src/adapters/hosting.js +275 -0
- package/dist/src/adapters/sdk-protocol.d.ts +43 -0
- package/dist/src/adapters/sdk-protocol.js +64 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +175 -0
- package/dist/src/config.d.ts +224 -0
- package/dist/src/config.js +82 -0
- package/dist/src/db/locks.d.ts +4 -0
- package/dist/src/db/locks.js +14 -0
- package/dist/src/db/migrate.d.ts +1 -0
- package/dist/src/db/migrate.js +12 -0
- package/dist/src/db/migrations.d.ts +2 -0
- package/dist/src/db/migrations.js +22 -0
- package/dist/src/db/schema.d.ts +486 -0
- package/dist/src/db/schema.js +46 -0
- package/dist/src/domain.d.ts +133 -0
- package/dist/src/domain.js +24 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +8 -0
- package/dist/src/operations.d.ts +35 -0
- package/dist/src/operations.js +378 -0
- package/dist/src/run-record.d.ts +7 -0
- package/dist/src/run-record.js +19 -0
- package/dist/src/runner.d.ts +47 -0
- package/dist/src/runner.js +370 -0
- package/dist/src/runtime/ownership.d.ts +8 -0
- package/dist/src/runtime/ownership.js +84 -0
- package/dist/src/runtime/process.d.ts +18 -0
- package/dist/src/runtime/process.js +98 -0
- package/dist/src/runtime/redaction.d.ts +8 -0
- package/dist/src/runtime/redaction.js +33 -0
- package/dist/src/store.d.ts +87 -0
- package/dist/src/store.js +355 -0
- package/dist/src/tui-data.d.ts +25 -0
- package/dist/src/tui-data.js +89 -0
- package/dist/src/tui.d.ts +5 -0
- package/dist/src/tui.js +69 -0
- package/dist/src/workspace.d.ts +16 -0
- package/dist/src/workspace.js +186 -0
- package/docs/acceptance.md +35 -0
- package/docs/api.md +64 -0
- package/docs/architecture.md +24 -0
- package/docs/configuration.md +41 -0
- package/docs/database.md +28 -0
- package/docs/operations.md +46 -0
- package/docs/providers.md +49 -0
- package/docs/releases.md +89 -0
- package/examples/config.ts +57 -0
- package/examples/custom-workflow.ts +32 -0
- package/examples/observe.ts +18 -0
- package/examples/run.ts +31 -0
- package/package.json +78 -0
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mingchuno
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Agent Workflows
|
|
2
|
+
|
|
3
|
+
A local TypeScript SDK and CLI/TUI that turns labelled GitHub or GitLab issues into draft change requests with independent agent reviews. DBOS persists execution; each project uses its existing checkout, with one task at a time. Separate projects progress concurrently.
|
|
4
|
+
|
|
5
|
+
Phase 1 includes Codex and Copilot SDK adapters, GitHub and GitLab.com/self-hosted GitLab adapters, durable publication reconciliation, session observability and explicit operator controls. Human review and merging remain separate.
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
Prerequisites: Node.js 22.12+, Git, PostgreSQL 17+, and an authenticated Codex or Copilot runtime. macOS and Linux are supported; Windows process-group ownership is not supported.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install -g @mingchuno/agent-workflows
|
|
13
|
+
createdb agent_workflows
|
|
14
|
+
export AGENT_WORKFLOWS_DATABASE_URL="postgresql://$(id -un)@localhost/agent_workflows"
|
|
15
|
+
agent-workflows init
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
For SDK use, install locally with `npm install @mingchuno/agent-workflows`. Both interfaces ship in the same package.
|
|
19
|
+
|
|
20
|
+
Edit `agent-workflows.json`: set the checkout, hosting origin/repository, Git identity, agent stages and validation commands. Set the named hosting-token environment variable through your usual secret manager. Commit or ignore the configuration before running. Keep the state directory outside managed checkouts, or explicitly Git-ignore it.
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
agent-workflows run
|
|
24
|
+
# In a second terminal:
|
|
25
|
+
agent-workflows monitor
|
|
26
|
+
agent-workflows status --json
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The runner fetches the configured base, creates a branch, implements an eligible issue, validates it, generates publication text, commits and pushes, creates a draft PR/MR, and publishes an independent review of its exact head. It never merges. Initial use should target a repository and issue you explicitly intend to automate; running the CLI authorizes these effects and agent usage.
|
|
30
|
+
|
|
31
|
+
## SDK
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { Runner, createAgents, createHosting } from "@mingchuno/agent-workflows";
|
|
35
|
+
|
|
36
|
+
const runner = new Runner({
|
|
37
|
+
config,
|
|
38
|
+
databaseUrl,
|
|
39
|
+
agents: createAgents(),
|
|
40
|
+
hosting: createHosting,
|
|
41
|
+
});
|
|
42
|
+
await runner.start();
|
|
43
|
+
// Later, stop intake and terminate in-flight local work safely:
|
|
44
|
+
await runner.shutdown();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
[Custom workflow](examples/custom-workflow.ts), [complete runner](examples/run.ts), [configuration](examples/config.ts), and [inspection](examples/observe.ts) examples are type-checked with the library. The custom workflow is also exercised using controlled providers.
|
|
48
|
+
|
|
49
|
+
## Development and review
|
|
50
|
+
|
|
51
|
+
[mise](https://mise.jdx.dev/getting-started.html) pins the development Node and pnpm versions. Activate it in your shell or prefix commands with `mise exec --`.
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
mise trust
|
|
55
|
+
mise install
|
|
56
|
+
pnpm install --frozen-lockfile
|
|
57
|
+
pnpm verify
|
|
58
|
+
pnpm pack:smoke
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Use `pnpm start --help` to run the CLI from source. `pnpm build` emits the runtime and declarations into `dist/src` and copies migrations to `dist/drizzle`.
|
|
62
|
+
|
|
63
|
+
`pnpm test` builds the application, then starts and removes a disposable real PostgreSQL database using `initdb`, `pg_ctl`, and `createdb` on PATH. Alternatively, set `TEST_DATABASE_URL` to a disposable database whose role can create test databases. Tests use real temporary Git repositories and controlled adapters/HTTP servers; they make no paid agent calls or writes to real hosting providers.
|
|
64
|
+
|
|
65
|
+
Schema changes and database upgrades: [database maintenance](docs/database.md). Biome formats and lints supported source/configuration files; Markdown and YAML are maintained manually.
|
|
66
|
+
|
|
67
|
+
- [Configuration and profiles](docs/configuration.md)
|
|
68
|
+
- [Public SDK API and composition](docs/api.md)
|
|
69
|
+
- [Authentication and provider capabilities](docs/providers.md)
|
|
70
|
+
- [CLI, TUI, observability and recovery](docs/operations.md)
|
|
71
|
+
- [Architecture and review evidence](docs/architecture.md)
|
|
72
|
+
- [Phase 1 acceptance](docs/acceptance.md)
|
|
73
|
+
- [Release setup, first publication and recovery](docs/releases.md)
|
|
74
|
+
- [Specification](https://github.com/mingchuno/agent-workflows/issues/1)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- Bootstrap also adopts the identical pre-Drizzle schema without replacing data.
|
|
2
|
+
CREATE SCHEMA IF NOT EXISTS "agent_workflows";
|
|
3
|
+
--> statement-breakpoint
|
|
4
|
+
CREATE TABLE IF NOT EXISTS "agent_workflows"."commands" (
|
|
5
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
6
|
+
"scope" text NOT NULL,
|
|
7
|
+
"kind" text NOT NULL,
|
|
8
|
+
"target" text NOT NULL,
|
|
9
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
10
|
+
"error" text,
|
|
11
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
12
|
+
);
|
|
13
|
+
--> statement-breakpoint
|
|
14
|
+
CREATE TABLE IF NOT EXISTS "agent_workflows"."events" (
|
|
15
|
+
"sequence" bigserial PRIMARY KEY NOT NULL,
|
|
16
|
+
"scope" text NOT NULL,
|
|
17
|
+
"run_id" text,
|
|
18
|
+
"kind" text NOT NULL,
|
|
19
|
+
"payload" jsonb NOT NULL,
|
|
20
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
21
|
+
);
|
|
22
|
+
--> statement-breakpoint
|
|
23
|
+
CREATE TABLE IF NOT EXISTS "agent_workflows"."invocations" (
|
|
24
|
+
"scope" text NOT NULL,
|
|
25
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
26
|
+
"run_id" text NOT NULL,
|
|
27
|
+
"record" jsonb NOT NULL
|
|
28
|
+
);
|
|
29
|
+
--> statement-breakpoint
|
|
30
|
+
CREATE TABLE IF NOT EXISTS "agent_workflows"."projects" (
|
|
31
|
+
"scope" text NOT NULL,
|
|
32
|
+
"id" text NOT NULL,
|
|
33
|
+
"paused" boolean DEFAULT false NOT NULL,
|
|
34
|
+
"blocked" text,
|
|
35
|
+
CONSTRAINT "projects_pkey" PRIMARY KEY("scope","id")
|
|
36
|
+
);
|
|
37
|
+
--> statement-breakpoint
|
|
38
|
+
CREATE TABLE IF NOT EXISTS "agent_workflows"."runs" (
|
|
39
|
+
"scope" text NOT NULL,
|
|
40
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
41
|
+
"task_key" text NOT NULL,
|
|
42
|
+
"attempt" integer NOT NULL,
|
|
43
|
+
"record" jsonb NOT NULL,
|
|
44
|
+
CONSTRAINT "runs_scope_task_key_attempt_key" UNIQUE("scope","task_key","attempt")
|
|
45
|
+
);
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "01de7257-12b0-4332-97f8-28f6221d632d",
|
|
3
|
+
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
4
|
+
"version": "7",
|
|
5
|
+
"dialect": "postgresql",
|
|
6
|
+
"tables": {
|
|
7
|
+
"agent_workflows.commands": {
|
|
8
|
+
"name": "commands",
|
|
9
|
+
"schema": "agent_workflows",
|
|
10
|
+
"columns": {
|
|
11
|
+
"id": {
|
|
12
|
+
"name": "id",
|
|
13
|
+
"type": "text",
|
|
14
|
+
"primaryKey": true,
|
|
15
|
+
"notNull": true
|
|
16
|
+
},
|
|
17
|
+
"scope": {
|
|
18
|
+
"name": "scope",
|
|
19
|
+
"type": "text",
|
|
20
|
+
"primaryKey": false,
|
|
21
|
+
"notNull": true
|
|
22
|
+
},
|
|
23
|
+
"kind": {
|
|
24
|
+
"name": "kind",
|
|
25
|
+
"type": "text",
|
|
26
|
+
"primaryKey": false,
|
|
27
|
+
"notNull": true
|
|
28
|
+
},
|
|
29
|
+
"target": {
|
|
30
|
+
"name": "target",
|
|
31
|
+
"type": "text",
|
|
32
|
+
"primaryKey": false,
|
|
33
|
+
"notNull": true
|
|
34
|
+
},
|
|
35
|
+
"status": {
|
|
36
|
+
"name": "status",
|
|
37
|
+
"type": "text",
|
|
38
|
+
"primaryKey": false,
|
|
39
|
+
"notNull": true,
|
|
40
|
+
"default": "'pending'"
|
|
41
|
+
},
|
|
42
|
+
"error": {
|
|
43
|
+
"name": "error",
|
|
44
|
+
"type": "text",
|
|
45
|
+
"primaryKey": false,
|
|
46
|
+
"notNull": false
|
|
47
|
+
},
|
|
48
|
+
"created_at": {
|
|
49
|
+
"name": "created_at",
|
|
50
|
+
"type": "timestamp with time zone",
|
|
51
|
+
"primaryKey": false,
|
|
52
|
+
"notNull": true,
|
|
53
|
+
"default": "now()"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"indexes": {},
|
|
57
|
+
"foreignKeys": {},
|
|
58
|
+
"compositePrimaryKeys": {},
|
|
59
|
+
"uniqueConstraints": {},
|
|
60
|
+
"policies": {},
|
|
61
|
+
"checkConstraints": {},
|
|
62
|
+
"isRLSEnabled": false
|
|
63
|
+
},
|
|
64
|
+
"agent_workflows.events": {
|
|
65
|
+
"name": "events",
|
|
66
|
+
"schema": "agent_workflows",
|
|
67
|
+
"columns": {
|
|
68
|
+
"sequence": {
|
|
69
|
+
"name": "sequence",
|
|
70
|
+
"type": "bigserial",
|
|
71
|
+
"primaryKey": true,
|
|
72
|
+
"notNull": true
|
|
73
|
+
},
|
|
74
|
+
"scope": {
|
|
75
|
+
"name": "scope",
|
|
76
|
+
"type": "text",
|
|
77
|
+
"primaryKey": false,
|
|
78
|
+
"notNull": true
|
|
79
|
+
},
|
|
80
|
+
"run_id": {
|
|
81
|
+
"name": "run_id",
|
|
82
|
+
"type": "text",
|
|
83
|
+
"primaryKey": false,
|
|
84
|
+
"notNull": false
|
|
85
|
+
},
|
|
86
|
+
"kind": {
|
|
87
|
+
"name": "kind",
|
|
88
|
+
"type": "text",
|
|
89
|
+
"primaryKey": false,
|
|
90
|
+
"notNull": true
|
|
91
|
+
},
|
|
92
|
+
"payload": {
|
|
93
|
+
"name": "payload",
|
|
94
|
+
"type": "jsonb",
|
|
95
|
+
"primaryKey": false,
|
|
96
|
+
"notNull": true
|
|
97
|
+
},
|
|
98
|
+
"created_at": {
|
|
99
|
+
"name": "created_at",
|
|
100
|
+
"type": "timestamp with time zone",
|
|
101
|
+
"primaryKey": false,
|
|
102
|
+
"notNull": true,
|
|
103
|
+
"default": "now()"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"indexes": {},
|
|
107
|
+
"foreignKeys": {},
|
|
108
|
+
"compositePrimaryKeys": {},
|
|
109
|
+
"uniqueConstraints": {},
|
|
110
|
+
"policies": {},
|
|
111
|
+
"checkConstraints": {},
|
|
112
|
+
"isRLSEnabled": false
|
|
113
|
+
},
|
|
114
|
+
"agent_workflows.invocations": {
|
|
115
|
+
"name": "invocations",
|
|
116
|
+
"schema": "agent_workflows",
|
|
117
|
+
"columns": {
|
|
118
|
+
"scope": {
|
|
119
|
+
"name": "scope",
|
|
120
|
+
"type": "text",
|
|
121
|
+
"primaryKey": false,
|
|
122
|
+
"notNull": true
|
|
123
|
+
},
|
|
124
|
+
"id": {
|
|
125
|
+
"name": "id",
|
|
126
|
+
"type": "text",
|
|
127
|
+
"primaryKey": true,
|
|
128
|
+
"notNull": true
|
|
129
|
+
},
|
|
130
|
+
"run_id": {
|
|
131
|
+
"name": "run_id",
|
|
132
|
+
"type": "text",
|
|
133
|
+
"primaryKey": false,
|
|
134
|
+
"notNull": true
|
|
135
|
+
},
|
|
136
|
+
"record": {
|
|
137
|
+
"name": "record",
|
|
138
|
+
"type": "jsonb",
|
|
139
|
+
"primaryKey": false,
|
|
140
|
+
"notNull": true
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"indexes": {},
|
|
144
|
+
"foreignKeys": {},
|
|
145
|
+
"compositePrimaryKeys": {},
|
|
146
|
+
"uniqueConstraints": {},
|
|
147
|
+
"policies": {},
|
|
148
|
+
"checkConstraints": {},
|
|
149
|
+
"isRLSEnabled": false
|
|
150
|
+
},
|
|
151
|
+
"agent_workflows.projects": {
|
|
152
|
+
"name": "projects",
|
|
153
|
+
"schema": "agent_workflows",
|
|
154
|
+
"columns": {
|
|
155
|
+
"scope": {
|
|
156
|
+
"name": "scope",
|
|
157
|
+
"type": "text",
|
|
158
|
+
"primaryKey": false,
|
|
159
|
+
"notNull": true
|
|
160
|
+
},
|
|
161
|
+
"id": {
|
|
162
|
+
"name": "id",
|
|
163
|
+
"type": "text",
|
|
164
|
+
"primaryKey": false,
|
|
165
|
+
"notNull": true
|
|
166
|
+
},
|
|
167
|
+
"paused": {
|
|
168
|
+
"name": "paused",
|
|
169
|
+
"type": "boolean",
|
|
170
|
+
"primaryKey": false,
|
|
171
|
+
"notNull": true,
|
|
172
|
+
"default": false
|
|
173
|
+
},
|
|
174
|
+
"blocked": {
|
|
175
|
+
"name": "blocked",
|
|
176
|
+
"type": "text",
|
|
177
|
+
"primaryKey": false,
|
|
178
|
+
"notNull": false
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"indexes": {},
|
|
182
|
+
"foreignKeys": {},
|
|
183
|
+
"compositePrimaryKeys": {
|
|
184
|
+
"projects_pkey": {
|
|
185
|
+
"name": "projects_pkey",
|
|
186
|
+
"columns": [
|
|
187
|
+
"scope",
|
|
188
|
+
"id"
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
"uniqueConstraints": {},
|
|
193
|
+
"policies": {},
|
|
194
|
+
"checkConstraints": {},
|
|
195
|
+
"isRLSEnabled": false
|
|
196
|
+
},
|
|
197
|
+
"agent_workflows.runs": {
|
|
198
|
+
"name": "runs",
|
|
199
|
+
"schema": "agent_workflows",
|
|
200
|
+
"columns": {
|
|
201
|
+
"scope": {
|
|
202
|
+
"name": "scope",
|
|
203
|
+
"type": "text",
|
|
204
|
+
"primaryKey": false,
|
|
205
|
+
"notNull": true
|
|
206
|
+
},
|
|
207
|
+
"id": {
|
|
208
|
+
"name": "id",
|
|
209
|
+
"type": "text",
|
|
210
|
+
"primaryKey": true,
|
|
211
|
+
"notNull": true
|
|
212
|
+
},
|
|
213
|
+
"task_key": {
|
|
214
|
+
"name": "task_key",
|
|
215
|
+
"type": "text",
|
|
216
|
+
"primaryKey": false,
|
|
217
|
+
"notNull": true
|
|
218
|
+
},
|
|
219
|
+
"attempt": {
|
|
220
|
+
"name": "attempt",
|
|
221
|
+
"type": "integer",
|
|
222
|
+
"primaryKey": false,
|
|
223
|
+
"notNull": true
|
|
224
|
+
},
|
|
225
|
+
"record": {
|
|
226
|
+
"name": "record",
|
|
227
|
+
"type": "jsonb",
|
|
228
|
+
"primaryKey": false,
|
|
229
|
+
"notNull": true
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
"indexes": {},
|
|
233
|
+
"foreignKeys": {},
|
|
234
|
+
"compositePrimaryKeys": {},
|
|
235
|
+
"uniqueConstraints": {
|
|
236
|
+
"runs_scope_task_key_attempt_key": {
|
|
237
|
+
"name": "runs_scope_task_key_attempt_key",
|
|
238
|
+
"nullsNotDistinct": false,
|
|
239
|
+
"columns": [
|
|
240
|
+
"scope",
|
|
241
|
+
"task_key",
|
|
242
|
+
"attempt"
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"policies": {},
|
|
247
|
+
"checkConstraints": {},
|
|
248
|
+
"isRLSEnabled": false
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
"enums": {},
|
|
252
|
+
"schemas": {
|
|
253
|
+
"agent_workflows": "agent_workflows"
|
|
254
|
+
},
|
|
255
|
+
"sequences": {},
|
|
256
|
+
"roles": {},
|
|
257
|
+
"policies": {},
|
|
258
|
+
"views": {},
|
|
259
|
+
"_meta": {
|
|
260
|
+
"columns": {},
|
|
261
|
+
"schemas": {},
|
|
262
|
+
"tables": {}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { CopilotClient } from "@github/copilot-sdk";
|
|
3
|
+
import { Codex } from "@openai/codex-sdk";
|
|
4
|
+
import { runCodex, runCopilot } from "./sdk-protocol.js";
|
|
5
|
+
const input = JSON.parse(await readFile(process.argv[2], "utf8"));
|
|
6
|
+
if (input.processFile)
|
|
7
|
+
await writeFile(input.processFile, JSON.stringify({ pid: process.pid }), {
|
|
8
|
+
mode: 0o600,
|
|
9
|
+
});
|
|
10
|
+
const emit = (type, value) => {
|
|
11
|
+
process.stdout.write(`AW:${JSON.stringify({ type, value })}\n`);
|
|
12
|
+
};
|
|
13
|
+
if (input.provider === "codex")
|
|
14
|
+
await runCodex(new Codex(), input, emit);
|
|
15
|
+
else
|
|
16
|
+
await runCopilot(new CopilotClient(), input, emit);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AgentProfile } from "../config.js";
|
|
2
|
+
import type { AgentAdapter, AgentInvocation, EffectiveProfile } from "../domain.js";
|
|
3
|
+
interface ModelCapability {
|
|
4
|
+
id: string;
|
|
5
|
+
reasoningEfforts: string[];
|
|
6
|
+
contextWindowTokens?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SDKAgentOptions {
|
|
9
|
+
models?: ModelCapability[];
|
|
10
|
+
}
|
|
11
|
+
/** Runs each SDK invocation in an owned process group; no cross-stage session reuse. */
|
|
12
|
+
export declare class SDKAgent implements AgentAdapter {
|
|
13
|
+
readonly provider: "codex" | "copilot";
|
|
14
|
+
readonly options: SDKAgentOptions;
|
|
15
|
+
constructor(provider: "codex" | "copilot", options?: SDKAgentOptions);
|
|
16
|
+
validate(profile: AgentProfile, signal?: AbortSignal): Promise<EffectiveProfile>;
|
|
17
|
+
invoke(invocation: AgentInvocation): Promise<string>;
|
|
18
|
+
private worker;
|
|
19
|
+
}
|
|
20
|
+
export declare function createAgents(): {
|
|
21
|
+
codex: SDKAgent;
|
|
22
|
+
copilot: SDKAgent;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir, tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { command } from "../runtime/process.js";
|
|
6
|
+
/** Runs each SDK invocation in an owned process group; no cross-stage session reuse. */
|
|
7
|
+
export class SDKAgent {
|
|
8
|
+
provider;
|
|
9
|
+
options;
|
|
10
|
+
constructor(provider, options = {}) {
|
|
11
|
+
this.provider = provider;
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
async validate(profile, signal) {
|
|
15
|
+
if (profile.provider !== this.provider)
|
|
16
|
+
throw new Error("Profile provider does not match adapter");
|
|
17
|
+
if (this.provider === "codex" && profile.context)
|
|
18
|
+
throw new Error("Codex SDK does not expose runtime context controls");
|
|
19
|
+
const context = profile.context;
|
|
20
|
+
if (context &&
|
|
21
|
+
(context.backgroundCompactionThreshold ?? 0.8) >=
|
|
22
|
+
(context.bufferExhaustionThreshold ?? 0.95))
|
|
23
|
+
throw new Error("Background compaction threshold must precede buffer exhaustion");
|
|
24
|
+
let models = this.options.models;
|
|
25
|
+
if (!models &&
|
|
26
|
+
this.provider === "codex" &&
|
|
27
|
+
(profile.model || profile.reasoningEffort)) {
|
|
28
|
+
try {
|
|
29
|
+
const cache = JSON.parse(await readFile(join(process.env.CODEX_HOME ?? join(homedir(), ".codex"), "models_cache.json"), "utf8"));
|
|
30
|
+
models = cache.models.map((model) => ({
|
|
31
|
+
id: model.slug,
|
|
32
|
+
reasoningEfforts: model.supported_reasoning_levels?.map((level) => level.effort) ??
|
|
33
|
+
[],
|
|
34
|
+
contextWindowTokens: model.context_window,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error("Cannot validate explicit Codex settings: refresh the local Codex model catalog or supply SDKAgent models");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!models &&
|
|
42
|
+
this.provider === "copilot" &&
|
|
43
|
+
(profile.model || profile.reasoningEffort)) {
|
|
44
|
+
const result = await this.worker({ operation: "models" }, undefined, signal);
|
|
45
|
+
models = JSON.parse(result);
|
|
46
|
+
}
|
|
47
|
+
const model = models?.find((candidate) => candidate.id === profile.model);
|
|
48
|
+
if (profile.model && !model)
|
|
49
|
+
throw new Error(`Model capability information unavailable: ${profile.model}`);
|
|
50
|
+
if (profile.reasoningEffort &&
|
|
51
|
+
!model?.reasoningEfforts.includes(profile.reasoningEffort))
|
|
52
|
+
throw new Error(`Unsupported reasoning effort ${profile.reasoningEffort} for ${profile.model ?? "unspecified model"}`);
|
|
53
|
+
return {
|
|
54
|
+
provider: this.provider,
|
|
55
|
+
model: profile.model ?? "unknown",
|
|
56
|
+
reasoningEffort: profile.reasoningEffort ?? "unknown",
|
|
57
|
+
context: context ?? "unknown",
|
|
58
|
+
contextWindowTokens: model?.contextWindowTokens ?? "unknown",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async invoke(invocation) {
|
|
62
|
+
return this.worker({
|
|
63
|
+
operation: "invoke",
|
|
64
|
+
id: invocation.id,
|
|
65
|
+
cwd: invocation.cwd,
|
|
66
|
+
prompt: invocation.prompt,
|
|
67
|
+
profile: invocation.profile,
|
|
68
|
+
skills: invocation.skills,
|
|
69
|
+
readOnly: invocation.readOnly,
|
|
70
|
+
timeoutMs: invocation.timeoutMs ?? 1_800_000,
|
|
71
|
+
}, invocation);
|
|
72
|
+
}
|
|
73
|
+
async worker(input, invocation, signal = invocation?.signal) {
|
|
74
|
+
const directory = await mkdtemp(join(tmpdir(), "agent-workflows-sdk-"));
|
|
75
|
+
const path = join(directory, "input.json");
|
|
76
|
+
await writeFile(path, JSON.stringify({
|
|
77
|
+
...input,
|
|
78
|
+
provider: this.provider,
|
|
79
|
+
processFile: invocation?.processFile,
|
|
80
|
+
}), { mode: 0o600 });
|
|
81
|
+
const ownPath = fileURLToPath(import.meta.url);
|
|
82
|
+
const source = ownPath.endsWith(".ts");
|
|
83
|
+
const worker = join(dirname(ownPath), `agent-worker.${source ? "ts" : "js"}`);
|
|
84
|
+
let buffer = "", output = "", events = Promise.resolve();
|
|
85
|
+
let eventError;
|
|
86
|
+
const persistenceFailure = new AbortController();
|
|
87
|
+
try {
|
|
88
|
+
await command(process.execPath, [
|
|
89
|
+
...(source ? ["--import", import.meta.resolve("tsx")] : []),
|
|
90
|
+
worker,
|
|
91
|
+
path,
|
|
92
|
+
], {
|
|
93
|
+
cwd: invocation?.cwd ?? process.cwd(),
|
|
94
|
+
signal: AbortSignal.any([
|
|
95
|
+
persistenceFailure.signal,
|
|
96
|
+
...(signal ? [signal] : []),
|
|
97
|
+
]),
|
|
98
|
+
captureOutput: false,
|
|
99
|
+
processFile: invocation?.processFile,
|
|
100
|
+
timeoutMs: invocation ? (invocation.timeoutMs ?? 1_800_000) : 30_000,
|
|
101
|
+
onOutput: (chunk) => {
|
|
102
|
+
buffer += chunk;
|
|
103
|
+
for (;;) {
|
|
104
|
+
const newline = buffer.indexOf("\n");
|
|
105
|
+
if (newline < 0)
|
|
106
|
+
break;
|
|
107
|
+
const line = buffer.slice(0, newline);
|
|
108
|
+
buffer = buffer.slice(newline + 1);
|
|
109
|
+
if (!line.startsWith("AW:"))
|
|
110
|
+
continue;
|
|
111
|
+
const message = JSON.parse(line.slice(3));
|
|
112
|
+
if (message.type === "result")
|
|
113
|
+
output = message.value;
|
|
114
|
+
else
|
|
115
|
+
events = events
|
|
116
|
+
.then(async () => {
|
|
117
|
+
if (message.type === "session")
|
|
118
|
+
await invocation?.session(message.value);
|
|
119
|
+
else
|
|
120
|
+
await invocation?.event(message.value);
|
|
121
|
+
})
|
|
122
|
+
.catch((error) => {
|
|
123
|
+
eventError = error;
|
|
124
|
+
persistenceFailure.abort();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
await events;
|
|
130
|
+
if (eventError)
|
|
131
|
+
throw eventError;
|
|
132
|
+
return output;
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
await events;
|
|
136
|
+
await rm(directory, { recursive: true, force: true });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function createAgents() {
|
|
141
|
+
return { codex: new SDKAgent("codex"), copilot: new SDKAgent("copilot") };
|
|
142
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Project } from "../config.js";
|
|
2
|
+
import { type ChangeRequest, type HostingAdapter, type Issue, type Review } from "../domain.js";
|
|
3
|
+
export declare function inlineFindings(review: Review, diff: string): {
|
|
4
|
+
body: string;
|
|
5
|
+
path: string;
|
|
6
|
+
line: number;
|
|
7
|
+
}[];
|
|
8
|
+
export declare class GitHubHosting implements HostingAdapter {
|
|
9
|
+
readonly identity: string;
|
|
10
|
+
private readonly client;
|
|
11
|
+
private readonly repo;
|
|
12
|
+
constructor(project: Project);
|
|
13
|
+
listIssues(labels: string[]): Promise<Issue[]>;
|
|
14
|
+
getIssue(number: number): Promise<Issue>;
|
|
15
|
+
findChange(branch: string): Promise<ChangeRequest | undefined>;
|
|
16
|
+
createChange(input: Parameters<HostingAdapter["createChange"]>[0]): Promise<ChangeRequest>;
|
|
17
|
+
head(change: ChangeRequest): Promise<string>;
|
|
18
|
+
publishReview(input: Parameters<HostingAdapter["publishReview"]>[0]): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare class GitLabHosting implements HostingAdapter {
|
|
21
|
+
readonly identity: string;
|
|
22
|
+
private readonly client;
|
|
23
|
+
private readonly repository;
|
|
24
|
+
constructor(project: Project);
|
|
25
|
+
preflight(): Promise<void>;
|
|
26
|
+
listIssues(labels: string[]): Promise<Issue[]>;
|
|
27
|
+
getIssue(number: number): Promise<Issue>;
|
|
28
|
+
findChange(branch: string): Promise<ChangeRequest | undefined>;
|
|
29
|
+
createChange(input: Parameters<HostingAdapter["createChange"]>[0]): Promise<ChangeRequest>;
|
|
30
|
+
head(change: ChangeRequest): Promise<string>;
|
|
31
|
+
publishReview(input: Parameters<HostingAdapter["publishReview"]>[0]): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export declare function createHosting(project: Project): HostingAdapter;
|