introsio 0.3.0 → 0.5.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/CHANGELOG.md +61 -0
- package/README.md +132 -30
- package/cli.mjs +161 -9
- package/docs/managed-workspaces.md +65 -0
- package/docs/releasing.md +118 -0
- package/hook/engine.mjs +28 -4
- package/hook/features/claims.mjs +6 -0
- package/hook/features/notes.mjs +1 -0
- package/hook/features/parallel.mjs +184 -0
- package/hook/normalize.mjs +1 -0
- package/hook/state.mjs +1 -1
- package/lib/config.mjs +12 -3
- package/lib/git.mjs +31 -0
- package/lib/jsonFile.mjs +13 -5
- package/package.json +4 -2
- package/runner/activityCollector.mjs +169 -0
- package/runner/agentRegistry.mjs +68 -0
- package/runner/managedActivity.mjs +58 -0
- package/runner/processJournal.mjs +42 -0
- package/runner/projectLinks.mjs +118 -0
- package/runner/providers/index.mjs +41 -0
- package/runner/runnerController.mjs +61 -0
- package/runner/runnerLoop.mjs +62 -0
- package/runner/runnerTransport.mjs +150 -0
- package/runner/supervisedProcess.mjs +113 -0
- package/runner/workspaceArtifacts.mjs +93 -0
- package/runner/workspaceJournal.mjs +91 -0
- package/runner/workspaceManager.mjs +166 -0
- package/runner/workspaceRecovery.mjs +54 -0
- package/runner/workspaceResources.mjs +53 -0
- package/templates/execute.md +12 -4
- package/templates/pause.md +1 -1
- package/templates/resume.md +2 -2
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Releasing to GitHub and npm
|
|
2
|
+
|
|
3
|
+
The npm package is [`introsio`](https://www.npmjs.com/package/introsio), with
|
|
4
|
+
`int` and `introsio` executable aliases. Its public source repository is
|
|
5
|
+
[`introsio/Introsio-cli`](https://github.com/introsio/Introsio-cli).
|
|
6
|
+
Edit source in the Introsio monorepo's `agent-kit/` folder and mirror that folder.
|
|
7
|
+
|
|
8
|
+
## Prepare locally
|
|
9
|
+
|
|
10
|
+
1. Update `package.json` and `CHANGELOG.md`. Use a new version for changed hooks
|
|
11
|
+
so `int doctor` can detect an older installed engine. The current draft is
|
|
12
|
+
**0.5.0**; it has not been published by preparing these files.
|
|
13
|
+
2. From `agent-kit/` (or the root of a standalone clone), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm test
|
|
17
|
+
npm pack --dry-run
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
No dependency installation is needed. Tests use isolated home directories and
|
|
21
|
+
scratch Git repositories. The npm allowlist includes runtime modules,
|
|
22
|
+
templates, README, guides, changelog and license; tests and workflows stay in
|
|
23
|
+
GitHub. The monorepo also checks `test/fixtures/execute-tools.json` against the
|
|
24
|
+
server's Execute toolset. Update the snapshot when that server contract changes.
|
|
25
|
+
3. Review the diff and commit the intended CLI changes. `git subtree split`
|
|
26
|
+
exports committed history only, so uncommitted changes will not reach GitHub.
|
|
27
|
+
Test the exported standalone tree too; it must not require the backend folder.
|
|
28
|
+
|
|
29
|
+
## Update the GitHub mirror
|
|
30
|
+
|
|
31
|
+
After the reviewed monorepo changes are committed, run from the monorepo root:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git fetch cli
|
|
35
|
+
git subtree split --prefix=agent-kit -b cli-release-0.5.0
|
|
36
|
+
git push cli cli-release-0.5.0:main
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The `cli` remote must point to `https://github.com/introsio/Introsio-cli.git`.
|
|
40
|
+
Choose an unused local split branch name. If a push is rejected, inspect the
|
|
41
|
+
mirror's history and reconcile it in the monorepo before repeating the split.
|
|
42
|
+
The mirror's `.github/workflows/tests.yml` runs its dependency-free suite on
|
|
43
|
+
Linux, Windows and macOS.
|
|
44
|
+
|
|
45
|
+
## Publish from the standalone repository
|
|
46
|
+
|
|
47
|
+
Publishing runs in **Introsio-cli**, matching the case-sensitive repository URL
|
|
48
|
+
in `package.json`. npm requires this match for
|
|
49
|
+
[provenance](https://docs.npmjs.com/generating-provenance-statements/).
|
|
50
|
+
The monorepo's `agent-kit-v*` workflow only validates a draft; it does not publish.
|
|
51
|
+
|
|
52
|
+
Configure the `introsio` package's npm
|
|
53
|
+
[trusted publisher](https://docs.npmjs.com/trusted-publishers/) before the first
|
|
54
|
+
automated release:
|
|
55
|
+
|
|
56
|
+
| Setting | Value |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| Provider | GitHub Actions |
|
|
59
|
+
| Organization | `introsio` |
|
|
60
|
+
| Repository | `Introsio-cli` |
|
|
61
|
+
| Workflow filename | `release.yml` |
|
|
62
|
+
| Environment | Leave empty (the workflow does not select one) |
|
|
63
|
+
| Allowed action | Direct publish with `npm publish` |
|
|
64
|
+
|
|
65
|
+
The workflow uses GitHub-hosted runners, Node 22 and npm 11, grants OIDC permission
|
|
66
|
+
and publishes with provenance. It does not use an `NPM_TOKEN` secret. This npm
|
|
67
|
+
account configuration must be performed separately; adding the workflow does
|
|
68
|
+
not create the trust relationship.
|
|
69
|
+
|
|
70
|
+
After the mirror's tests pass, from a standalone clone at the reviewed commit:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git tag v0.5.0
|
|
74
|
+
git push origin v0.5.0
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`release.yml` requires the tag to equal `v` plus `package.json`'s version, runs
|
|
78
|
+
the tests, inspects the package and publishes. These commands publish a public
|
|
79
|
+
release; run them only when the draft is approved. Create the matching GitHub
|
|
80
|
+
Release from that tag using the version's `CHANGELOG.md` entry as release notes.
|
|
81
|
+
|
|
82
|
+
For an interactive fallback, run these from the reviewed CLI checkout and
|
|
83
|
+
complete npm's browser authentication using an account that maintains `introsio`:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm login --auth-type=web --registry=https://registry.npmjs.org
|
|
87
|
+
npm whoami --registry=https://registry.npmjs.org
|
|
88
|
+
npm publish --access public --registry=https://registry.npmjs.org
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Check that `whoami` reports the intended maintainer before publishing.
|
|
92
|
+
`prepublishOnly` runs the test suite. Provenance is generated by the CI workflow.
|
|
93
|
+
|
|
94
|
+
### Publishing returns 404
|
|
95
|
+
|
|
96
|
+
A `PUT .../introsio` 404 can indicate rejected credentials or missing publishing
|
|
97
|
+
access even when the package exists. Check authentication separately with
|
|
98
|
+
`npm whoami`, and read public ownership with `npm owner ls introsio`.
|
|
99
|
+
If `whoami` returns 401, sign in again using the commands above. If it succeeds
|
|
100
|
+
but publishing is refused, verify that the account has package write access and
|
|
101
|
+
that the package's publishing policy allows the selected method.
|
|
102
|
+
|
|
103
|
+
GitHub trusted publishing applies to the configured CI workflow; a local
|
|
104
|
+
PowerShell publish needs its own npm authentication. See
|
|
105
|
+
[npm login](https://docs.npmjs.com/cli/v11/commands/npm-login/) and
|
|
106
|
+
[trusted publishing](https://docs.npmjs.com/trusted-publishers/).
|
|
107
|
+
|
|
108
|
+
After publishing, verify `npm view introsio version`, inspect the GitHub Actions
|
|
109
|
+
result and test `npx introsio@0.5.0 version`. Tell existing users to update, run
|
|
110
|
+
`int setup` again and check `int doctor`.
|
|
111
|
+
|
|
112
|
+
## Managed execution release limits
|
|
113
|
+
|
|
114
|
+
The CLI package includes managed workspace APIs and inspection commands. Publishing
|
|
115
|
+
it does not enable unattended vendor adapters or change the backend rollout stage.
|
|
116
|
+
Live GitHub, staging and independent acceptance remain separate gates. See
|
|
117
|
+
[managed workspace guidance](managed-workspaces.md) and the
|
|
118
|
+
[service release runbook](https://github.com/RASAPALLI-MAHESH/Introsio/blob/main/docs/runbooks/managed-execution-release.md).
|
package/hook/engine.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { agentPid } from '../lib/processTree.mjs';
|
|
|
15
15
|
import { loadSession, saveSession, saveSessionUnlocked, loadOtherSessions, sessionExists, sessionFile } from './state.mjs';
|
|
16
16
|
import { applyIntrosioResult, updateClaimsFromTranscript, isCompletionCall } from './features/claims.mjs';
|
|
17
17
|
import { stopDecision } from './features/stopGuard.mjs';
|
|
18
|
+
import { sharedTreeDecision, inputsNote, trackWaiting, waitStopDecision, treeKey } from './features/parallel.mjs';
|
|
18
19
|
import { makeWorkerId, workerIdDecision } from './features/workerId.mjs';
|
|
19
20
|
import { shippedDecision, planTestGate, runTestGate, resolveMode, workTreeKey } from './features/gates.mjs';
|
|
20
21
|
import { pushDecision, secretsDecision } from './features/git.mjs';
|
|
@@ -90,7 +91,10 @@ export async function handleEvent(evt, deps = {}) {
|
|
|
90
91
|
|
|
91
92
|
let gitHandle = null;
|
|
92
93
|
const git = () => (gitHandle ??= (deps.createGit ?? createGit)(evt.cwd ?? session.cwd ?? process.cwd()));
|
|
93
|
-
|
|
94
|
+
// Inside a linked worktree, the repository's settings apply unless the worktree has its own.
|
|
95
|
+
const settingsHere = () => repoSettings(config, git().root(), git().mainRoot());
|
|
96
|
+
let othersCache = null;
|
|
97
|
+
const others = () => (othersCache ??= loadOtherSessions(session.sessionId, now, env));
|
|
94
98
|
|
|
95
99
|
switch (evt.event) {
|
|
96
100
|
case 'session-start': {
|
|
@@ -115,7 +119,8 @@ export async function handleEvent(evt, deps = {}) {
|
|
|
115
119
|
const claim = session.claims[String(tool.args?.taskId ?? '')];
|
|
116
120
|
const completing = claim && isCompletionCall(tool.name, tool.args);
|
|
117
121
|
answer = firstDeny(
|
|
118
|
-
() => (on('worker-id') ? workerIdDecision(session,
|
|
122
|
+
() => (on('worker-id') ? workerIdDecision(session, others(), tool, now, deps.isAlive) : NONE),
|
|
123
|
+
() => (on('shared-tree') ? sharedTreeDecision(session, others(), tool, { root: git().root(), now, alive: deps.isAlive }) : NONE),
|
|
119
124
|
() => (on('reread') ? rereadDecision(session, tool) : NONE),
|
|
120
125
|
() => (tool.name === 'pauseTask' && on('pause') ? pauseDecision({ git: git(), args: tool.args, session, now, budgetMs: deps.snapshotBudgetMs }) : NONE),
|
|
121
126
|
() => (completing && on('shipped-gate') ? shippedDecision({ git: git(), settings: settingsHere(), claim, args: tool.args, session }) : NONE),
|
|
@@ -126,7 +131,7 @@ export async function handleEvent(evt, deps = {}) {
|
|
|
126
131
|
}
|
|
127
132
|
} else if (tool.kind === 'shell' && GIT_WRITE.test(tool.command ?? '')) {
|
|
128
133
|
const root = git().root();
|
|
129
|
-
const settings = repoSettings(config, root);
|
|
134
|
+
const settings = repoSettings(config, root, git().mainRoot());
|
|
130
135
|
const claim = Object.values(session.claims)[0];
|
|
131
136
|
const active = session.introsio || settings.mode || settings.gate;
|
|
132
137
|
if (!root || !active) break;
|
|
@@ -153,6 +158,7 @@ export async function handleEvent(evt, deps = {}) {
|
|
|
153
158
|
const hadClaims = Object.keys(session.claims).length;
|
|
154
159
|
const pausedClaim = tool.name === 'pauseTask' ? session.claims[String(tool.args?.taskId ?? '')] : null;
|
|
155
160
|
applyIntrosioResult(session, { name: tool.name, args: tool.args, result: evt.result }, now);
|
|
161
|
+
if (tool.name === 'claimTask') notes.push(...claimNotes({ tool, result: evt.result, session, git, settingsHere, on }));
|
|
156
162
|
if (on('pause')) notes.push(...pauseNotes({ tool, result: evt.result, session, pausedClaim, git, config, env, now, deps }));
|
|
157
163
|
if (on('log')) writeLog(logRow(session, evt, { name: tool.name, args: tool.args, result: evt.result }, now), env);
|
|
158
164
|
if (tool.name === 'claimTask' && Object.keys(session.claims).length > hadClaims && !session.modeNoted && on('shipped-gate')) {
|
|
@@ -191,6 +197,7 @@ export async function handleEvent(evt, deps = {}) {
|
|
|
191
197
|
updateClaimsFromTranscript(session, evt.transcriptPath, now, fs);
|
|
192
198
|
}
|
|
193
199
|
answer = stopDecision(session, evt, now);
|
|
200
|
+
if (answer.type === 'none' && on('wait')) answer = waitStopDecision(session, now);
|
|
194
201
|
break;
|
|
195
202
|
}
|
|
196
203
|
default:
|
|
@@ -210,6 +217,23 @@ export async function handleEvent(evt, deps = {}) {
|
|
|
210
217
|
return answer;
|
|
211
218
|
}
|
|
212
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Features `shared-tree`, `inputs` and `wait`, after a claimTask answer: remember the
|
|
222
|
+
* working tree this session works in (so a second agent in the same folder is
|
|
223
|
+
* caught), name the dependency branches the task's starting point lacks, and turn a
|
|
224
|
+
* "nothing free right now" answer into a wait instead of a stop.
|
|
225
|
+
*/
|
|
226
|
+
function claimNotes({ tool, result, session, git, settingsHere, on }) {
|
|
227
|
+
const notes = [];
|
|
228
|
+
const data = result?.ok ? result.data : null;
|
|
229
|
+
if (on('wait')) notes.push(trackWaiting(session, { name: tool.name, args: tool.args, result }, session.lastSeenAt));
|
|
230
|
+
if (data?.claimed !== true) return notes;
|
|
231
|
+
const root = git().root();
|
|
232
|
+
if (root) session.root = treeKey(root);
|
|
233
|
+
if (root && on('inputs')) notes.push(inputsNote({ git: git(), data, mode: resolveMode(settingsHere(), { repository: data.repository }) }));
|
|
234
|
+
return notes;
|
|
235
|
+
}
|
|
236
|
+
|
|
213
237
|
/**
|
|
214
238
|
* Feature `pause`, after an Introsio answer: keep the snapshot of a pause that
|
|
215
239
|
* landed, drop it once the task is done, check the repository against any pause
|
|
@@ -220,7 +244,7 @@ function pauseNotes({ tool, result, session, pausedClaim, git, config, env, now,
|
|
|
220
244
|
const notes = [];
|
|
221
245
|
const root = () => git().root();
|
|
222
246
|
const gatePassed = () => {
|
|
223
|
-
const settings = repoSettings(config, root());
|
|
247
|
+
const settings = repoSettings(config, root(), git().mainRoot());
|
|
224
248
|
if (!settings.gate) return null;
|
|
225
249
|
const key = workTreeKey(git(), settings.gate);
|
|
226
250
|
return !!key && readJsonSafe(gateCachePath(env), {})[root()]?.key === key;
|
package/hook/features/claims.mjs
CHANGED
|
@@ -56,6 +56,7 @@ function lostClaim(session, { name, args = {}, result }) {
|
|
|
56
56
|
if (Number(data.status) === 404) return true;
|
|
57
57
|
// The person reset the project's execution while this session held the task (its work no longer counts).
|
|
58
58
|
if (data.code === REVOKED_BY_RESET) return true;
|
|
59
|
+
if (data.code === 'STALE_ATTEMPT' || data.code === 'STALE_LEASE') return true;
|
|
59
60
|
const holder = data.claimedBy?.workerId ?? data.details?.claimedBy?.workerId;
|
|
60
61
|
return Number(data.status) === 409 && !!holder && holder !== claim.workerId && holder !== args.workerId;
|
|
61
62
|
}
|
|
@@ -63,6 +64,7 @@ function lostClaim(session, { name, args = {}, result }) {
|
|
|
63
64
|
const lostReason = (data) => {
|
|
64
65
|
if (Number(data.status) === 404) return 'the task no longer exists';
|
|
65
66
|
if (data.code === REVOKED_BY_RESET) return "the project's execution was reset, so that work no longer counts";
|
|
67
|
+
if (data.code === 'STALE_ATTEMPT' || data.code === 'STALE_LEASE') return 'the execution attempt is stale or its lease expired';
|
|
66
68
|
return `worker ${data.claimedBy?.workerId ?? data.details?.claimedBy?.workerId} holds it now`;
|
|
67
69
|
};
|
|
68
70
|
|
|
@@ -109,6 +111,7 @@ export function applyIntrosioResult(session, { name, args = {}, result }, now) {
|
|
|
109
111
|
taskId: id,
|
|
110
112
|
title: data.task.title ?? previous?.title ?? id,
|
|
111
113
|
workerId: data.workerId ?? previous?.workerId ?? null,
|
|
114
|
+
attempt: data.attempt ?? null,
|
|
112
115
|
projectId,
|
|
113
116
|
claimedAt: previous?.claimedAt ?? now,
|
|
114
117
|
lastWriteAt: now,
|
|
@@ -116,6 +119,8 @@ export function applyIntrosioResult(session, { name, args = {}, result }, now) {
|
|
|
116
119
|
leaseMs: expiresAt ? Math.max(60_000, expiresAt - now) : 30 * 60_000,
|
|
117
120
|
nudgedAt: null,
|
|
118
121
|
repository: data.repository ?? null,
|
|
122
|
+
integration: data.task.integration ?? null,
|
|
123
|
+
dependencySnapshot: data.dependencySnapshot ?? null,
|
|
119
124
|
branch: data.task.outcome?.branch ?? previous?.branch ?? null,
|
|
120
125
|
files: extractPaths(data.task.description),
|
|
121
126
|
subtasks: countSubtasks(data.task),
|
|
@@ -147,6 +152,7 @@ export function applyIntrosioResult(session, { name, args = {}, result }, now) {
|
|
|
147
152
|
const expiresAt = time(data.task.claim?.expiresAt);
|
|
148
153
|
session.claims[id] = {
|
|
149
154
|
taskId: id, title: data.task.title ?? id, workerId: data.task.claim?.workerId ?? args.workerId ?? null,
|
|
155
|
+
attempt: data.attempt ?? null,
|
|
150
156
|
projectId, claimedAt: now, lastWriteAt: now, expiresAt,
|
|
151
157
|
leaseMs: expiresAt ? Math.max(60_000, expiresAt - now) : 30 * 60_000,
|
|
152
158
|
nudgedAt: null, repository: null, branch: args.outcome?.branch ?? null, files: [], subtasks: { total: 0, done: 0 },
|
package/hook/features/notes.mjs
CHANGED
|
@@ -54,6 +54,7 @@ export function recoveryNote(session) {
|
|
|
54
54
|
for (const claim of claims) {
|
|
55
55
|
const revision = claim.projectId != null ? session.contextRevision?.[claim.projectId] : undefined;
|
|
56
56
|
const parts = [
|
|
57
|
+
claim.attempt ? `attempt ${JSON.stringify(claim.attempt)} (send unchanged on execution writes)` : null,
|
|
57
58
|
claim.subtasks?.total ? `subtasks ${claim.subtasks.done}/${claim.subtasks.total} done` : null,
|
|
58
59
|
revision !== undefined ? `context revision ${revision}` : null,
|
|
59
60
|
claim.expiresAt ? `lease until ${clock(claim.expiresAt)}` : null,
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Features `shared-tree`, `inputs` and `wait`: several agents on one project.
|
|
2
|
+
//
|
|
3
|
+
// The server makes sure two workers never hold one task (an atomic claim). What it
|
|
4
|
+
// cannot see is the computer: two agents in ONE folder share one branch and one set
|
|
5
|
+
// of files, a task's dependencies may sit on branches its worker has not merged, and
|
|
6
|
+
// a worker that finds every ready task taken would simply stop. These three close that.
|
|
7
|
+
import { repoKey } from '../../lib/paths.mjs';
|
|
8
|
+
import { isAlive } from '../../lib/processTree.mjs';
|
|
9
|
+
import { sessionIsLive } from './workerId.mjs';
|
|
10
|
+
|
|
11
|
+
const NONE = Object.freeze({ type: 'none' });
|
|
12
|
+
|
|
13
|
+
/** How long `int wait` waits at most per call: under the shell-tool time limits agents use. */
|
|
14
|
+
export const WAIT_STEP_SEC = 240;
|
|
15
|
+
/** After this long waiting on other workers, the agent is told to report to the user instead. */
|
|
16
|
+
export const MAX_WAIT_MS = 60 * 60_000;
|
|
17
|
+
/** A no-work answer older than this no longer makes a stop worth questioning. */
|
|
18
|
+
const WAIT_FRESH_MS = 15 * 60_000;
|
|
19
|
+
/** The claimTask answers that mean "work exists, but other workers hold what can start now". */
|
|
20
|
+
const WAIT_REASONS = new Set(['all_claimed', 'awaiting_completion']);
|
|
21
|
+
|
|
22
|
+
const STARTS_WORK = (name, args) => name === 'claimTask' || (name === 'updateTask' && args?.statusState === 'in_progress');
|
|
23
|
+
|
|
24
|
+
const liveClaims = (session, now) => Object.values(session.claims ?? {}).filter((claim) => !claim.expiresAt || claim.expiresAt > now);
|
|
25
|
+
|
|
26
|
+
/** The working tree a session works in, as one comparable key (null outside a repository). */
|
|
27
|
+
export const treeKey = (root) => (root ? repoKey(root) : null);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* `shared-tree`, before a claim: another live session holds a task in this same
|
|
31
|
+
* working tree. Two agents in one folder share one HEAD, index and set of files —
|
|
32
|
+
* a `git switch` by one moves the other's next commit, `git add -A` takes the
|
|
33
|
+
* other's half-done files, and each test run sees the other's unfinished code. Refused
|
|
34
|
+
* once, naming the fix (a worktree per agent); a second claim goes through, so a
|
|
35
|
+
* person who chose to share the folder is never stuck.
|
|
36
|
+
*/
|
|
37
|
+
export function sharedTreeDecision(session, others, { name, args = {} }, { root, now, alive = isAlive }) {
|
|
38
|
+
if (!STARTS_WORK(name, args)) return NONE;
|
|
39
|
+
const here = treeKey(root);
|
|
40
|
+
if (!here) return NONE;
|
|
41
|
+
// Taking back a task this session already holds is not a second worker in the folder.
|
|
42
|
+
if (args.taskId && session.claims?.[String(args.taskId)]) return NONE;
|
|
43
|
+
const other = others.find((candidate) => candidate.root === here
|
|
44
|
+
&& candidate.workerId !== session.workerId
|
|
45
|
+
&& liveClaims(candidate, now).length > 0
|
|
46
|
+
&& sessionIsLive(candidate, now, alive));
|
|
47
|
+
if (!other) return NONE;
|
|
48
|
+
session.sharedTreeAllowed = session.sharedTreeAllowed ?? {};
|
|
49
|
+
const key = `${other.sessionId}:${here}`;
|
|
50
|
+
if (session.sharedTreeAllowed[key]) return NONE;
|
|
51
|
+
session.sharedTreeAllowed[key] = now;
|
|
52
|
+
const held = liveClaims(other, now)[0];
|
|
53
|
+
return {
|
|
54
|
+
type: 'deny',
|
|
55
|
+
message:
|
|
56
|
+
`Introsio: another live ${other.agent ?? 'agent'} session (workerId ${other.workerId ?? held.workerId ?? '?'}) is working on "${held.title}" in this same folder (${root}). ` +
|
|
57
|
+
'Two agents in one working tree share one branch and one set of files: commits land on each other\'s branches, `git add` takes the other\'s half-done files, and each test run sees the other\'s unfinished code.\n' +
|
|
58
|
+
'Stop and ask the user to give this agent its own worktree — in a terminal: `int worktree add <name>` — and to start it in the folder that prints. ' +
|
|
59
|
+
'If the user already chose to share this folder, call claimTask again and it goes through.',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* `inputs`, after a claim: the branches of the tasks this one builds on
|
|
65
|
+
* (`inputs[].outcome.branch`) that are not in the branch the work starts from yet,
|
|
66
|
+
* with the command that brings each in. Without it a dependent task starts from the
|
|
67
|
+
* default branch and simply does not have the code it builds on. github mode compares
|
|
68
|
+
* with the default branch (each task branches off it); local mode with HEAD.
|
|
69
|
+
*/
|
|
70
|
+
export function inputsNote({ git, data, mode }) {
|
|
71
|
+
if (data?.task?.integration?.required) {
|
|
72
|
+
const managed = (data.inputs ?? []).filter(input => input.integration?.state === 'integrated');
|
|
73
|
+
const missing = managed.filter(input => !git.isAncestor(input.integration.headSha, 'HEAD'));
|
|
74
|
+
if (!missing.length) return null;
|
|
75
|
+
return 'Introsio: provision this task with the managed runner before editing. Its workspace pin includes the shared integration head. Required inputs are ' +
|
|
76
|
+
missing.map(input => `${input.taskId} at ${input.integration.headSha} (artifact ${input.integration.artifactId})`).join(', ') + '.';
|
|
77
|
+
}
|
|
78
|
+
const inputs = (Array.isArray(data?.inputs) ? data.inputs : [])
|
|
79
|
+
.filter((input) => typeof input?.outcome?.branch === 'string' && input.outcome.branch.trim());
|
|
80
|
+
if (inputs.length === 0 || !git.root()) return null;
|
|
81
|
+
const github = mode === 'github';
|
|
82
|
+
const defaultBranch = data.repository?.defaultBranch ?? git.defaultBranch();
|
|
83
|
+
// A task being taken up again already has its branch checked out (or recorded): compare with HEAD.
|
|
84
|
+
const continuing = data.alreadyHeld === true || !!data.resumedFrom || !!data.resumedPause || !!data.task?.outcome?.branch;
|
|
85
|
+
let base = null;
|
|
86
|
+
let label = null;
|
|
87
|
+
if (github && defaultBranch && !continuing) {
|
|
88
|
+
base = git.resolve(`refs/remotes/origin/${defaultBranch}`) ?? git.resolve(`refs/heads/${defaultBranch}`);
|
|
89
|
+
label = `the default branch "${defaultBranch}"`;
|
|
90
|
+
}
|
|
91
|
+
if (!base) {
|
|
92
|
+
base = git.head();
|
|
93
|
+
const branch = git.branch();
|
|
94
|
+
label = branch && branch !== 'HEAD' ? `your branch "${branch}"` : 'your HEAD';
|
|
95
|
+
}
|
|
96
|
+
if (!base) return null;
|
|
97
|
+
const lines = [];
|
|
98
|
+
const seen = new Set();
|
|
99
|
+
for (const input of inputs) {
|
|
100
|
+
const branch = input.outcome.branch.trim();
|
|
101
|
+
if (seen.has(branch)) continue;
|
|
102
|
+
seen.add(branch);
|
|
103
|
+
const title = input.title ?? input.taskId ?? branch;
|
|
104
|
+
const local = git.resolve(`refs/heads/${branch}`);
|
|
105
|
+
const remote = git.resolve(`refs/remotes/origin/${branch}`);
|
|
106
|
+
// github mode trusts what was pushed; local mode the branch in this repository (every worktree shares it).
|
|
107
|
+
const [sha, ref] = github ? (remote ? [remote, `origin/${branch}`] : [local, branch]) : (local ? [local, branch] : [remote, `origin/${branch}`]);
|
|
108
|
+
if (!sha) {
|
|
109
|
+
lines.push(github
|
|
110
|
+
? ` - "${title}": branch ${branch} is not on this computer yet — git fetch origin ${branch}, then git merge --no-edit origin/${branch}`
|
|
111
|
+
: ` - "${title}": branch ${branch} is not in this repository (another clone?) — ask the user, or build from its outcome`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (git.isAncestor(sha, base)) continue;
|
|
115
|
+
lines.push(` - "${title}": git merge --no-edit ${ref}`);
|
|
116
|
+
}
|
|
117
|
+
if (lines.length === 0) return null;
|
|
118
|
+
const start = github && !continuing ? `Run git fetch origin, branch off ${defaultBranch ?? 'the default branch'} for this task, then merge these into it before you start` : 'Merge these before you start';
|
|
119
|
+
return `Introsio: "${data.task?.title ?? 'this task'}" builds on work that is not in ${label} yet:\n${lines.join('\n')}\n` +
|
|
120
|
+
`${start}. Resolve any conflict; if you cannot, mark the task blocked and say why.`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const clock = (ms) => new Date(ms).toISOString().slice(11, 16) + ' UTC';
|
|
124
|
+
const waitCommand = (waiting) => `int wait ${waiting.retryAfter ? new Date(waiting.retryAfter).toISOString() : '120'}`;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* `wait`, after claimTask: remember that this worker found no task only because
|
|
128
|
+
* other workers hold the ready work (`all_claimed`), or because tasks report their
|
|
129
|
+
* phase done without being completed (`awaiting_completion`). The first such answer
|
|
130
|
+
* of a wait says what to do; a claim, or any other answer, ends the wait.
|
|
131
|
+
*/
|
|
132
|
+
export function trackWaiting(session, { name, args = {}, result }, now) {
|
|
133
|
+
if (name !== 'claimTask' || !result?.ok || !result.data) return null;
|
|
134
|
+
const data = result.data;
|
|
135
|
+
if (data.claimed === true || !WAIT_REASONS.has(data.reason) || args.taskId) {
|
|
136
|
+
session.waiting = null;
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const projectId = data.project?.id ?? args.projectId ?? null;
|
|
140
|
+
const previous = session.waiting?.projectId === projectId ? session.waiting : null;
|
|
141
|
+
const retryAfter = Date.parse(data.retryAfter ?? '');
|
|
142
|
+
session.waiting = {
|
|
143
|
+
projectId,
|
|
144
|
+
since: previous?.since ?? now,
|
|
145
|
+
at: now,
|
|
146
|
+
retryAfter: Number.isFinite(retryAfter) ? retryAfter : null,
|
|
147
|
+
reason: data.reason,
|
|
148
|
+
reminded: previous?.reminded ?? false,
|
|
149
|
+
overdueNoted: previous?.overdueNoted ?? false,
|
|
150
|
+
};
|
|
151
|
+
const waiting = session.waiting;
|
|
152
|
+
if (now - waiting.since > MAX_WAIT_MS) {
|
|
153
|
+
if (waiting.overdueNoted) return null;
|
|
154
|
+
waiting.overdueNoted = true;
|
|
155
|
+
return `Introsio: you have waited ${Math.round((now - waiting.since) / 60_000)} min for other workers. Tell the user which tasks are still held (claimedTasks) and stop — you may claim again later.`;
|
|
156
|
+
}
|
|
157
|
+
if (previous) return null;
|
|
158
|
+
const done = data.reason === 'awaiting_completion'
|
|
159
|
+
? 'Some tasks report their phase completed but are not completed — if you hold one, completeTask it now. Otherwise their workers will. '
|
|
160
|
+
: '';
|
|
161
|
+
return `Introsio: other workers hold the ready work of this project${waiting.retryAfter ? ` (the first lease ends ${clock(waiting.retryAfter)})` : ''}; each task they finish unlocks more. ${done}` +
|
|
162
|
+
`Don't stop: run \`${waitCommand(waiting)}\` (it returns after at most ${WAIT_STEP_SEC / 60} minutes), then claimTask { projectId, workerId } again, and repeat. ` +
|
|
163
|
+
'Stop only when claimTask answers "complete", "blocked" or "paused", or the user asked you to.';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* `wait`, at stop: no task held, but the last claim found work that other workers
|
|
168
|
+
* are finishing. Sent back once per wait — the user's instruction comes first, and
|
|
169
|
+
* stopping again is taken as a decision.
|
|
170
|
+
*/
|
|
171
|
+
export function waitStopDecision(session, now) {
|
|
172
|
+
const waiting = session.waiting;
|
|
173
|
+
if (!waiting || waiting.reminded) return NONE;
|
|
174
|
+
if (Object.keys(session.claims ?? {}).length > 0) return NONE;
|
|
175
|
+
if (now - waiting.at > WAIT_FRESH_MS || now - waiting.since > MAX_WAIT_MS) return NONE;
|
|
176
|
+
waiting.reminded = true;
|
|
177
|
+
return {
|
|
178
|
+
type: 'block',
|
|
179
|
+
message:
|
|
180
|
+
'Introsio: other workers are still running tasks of this project, and what they finish unlocks the rest. ' +
|
|
181
|
+
`Unless the user asked you to stop (or to do only part of the project): run \`${waitCommand(waiting)}\`, then claimTask { projectId, workerId } again — ` +
|
|
182
|
+
'stop when it answers "complete", "blocked" or "paused". To stop anyway, just stop again; you will not be asked twice.',
|
|
183
|
+
};
|
|
184
|
+
}
|
package/hook/normalize.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/** Every Introsio MCP tool whose name alone identifies it, even under another server name. */
|
|
7
7
|
export const DISTINCTIVE_TOOLS = new Set([
|
|
8
8
|
'claimTask', 'pauseTask', 'completeTask', 'undoTaskCompletion', 'updateSubtask', 'getReadySubtasks', 'getReadyTasks',
|
|
9
|
+
'waitForWork',
|
|
9
10
|
'getExecutionWaves', 'getProjectPlan', 'createProjectPlan', 'getProjectState', 'updateProjectState',
|
|
10
11
|
'getProjectContext', 'updateProjectContext', 'editProjectContextItems', 'recordProjectDecision',
|
|
11
12
|
'exportProjectBlueprint', 'importProjectBlueprint', 'getTaskDependencies', 'addTaskDependency', 'removeTaskDependency',
|
package/hook/state.mjs
CHANGED
|
@@ -50,7 +50,7 @@ export function saveSession(session, env) {
|
|
|
50
50
|
writeJson(path.join(sessionsDir(env), `${safeName(session.sessionId)}.json`), session);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const KEYED = ['claims', 'paused', 'pending', 'pendingPause', 'contextRevision', 'contextRead', 'rereadDenied', 'resumeChecked'];
|
|
53
|
+
const KEYED = ['claims', 'paused', 'pending', 'pendingPause', 'contextRevision', 'contextRead', 'rereadDenied', 'resumeChecked', 'sharedTreeAllowed'];
|
|
54
54
|
const LISTS = ['editedFiles', 'warnedFiles'];
|
|
55
55
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
56
56
|
const isMap = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
package/lib/config.mjs
CHANGED
|
@@ -16,6 +16,9 @@ export const FEATURES = {
|
|
|
16
16
|
reread: 'Skip re-reading context / schedule the agent already has',
|
|
17
17
|
log: 'Record every Introsio call in ~/.introsio/log.jsonl (see `int stats`)',
|
|
18
18
|
pause: 'Snapshot the working tree when a task is paused, and check the repository against the pause before it is resumed',
|
|
19
|
+
'shared-tree': 'Refuse once a claim in a folder another live agent session is working in (give each agent its own: int worktree add)',
|
|
20
|
+
inputs: "After a claim, name the dependencies' branches that are not in the agent's branch yet, with the merge command",
|
|
21
|
+
wait: 'When other workers hold all the ready work, send the agent back once to wait (int wait) and claim again instead of quitting',
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export const MODES = ['github', 'local', 'off'];
|
|
@@ -43,9 +46,15 @@ export function featureOn(config, name) {
|
|
|
43
46
|
return config.features?.[name] !== false;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
/**
|
|
50
|
+
* The settings of the repository at `root` (any spelling of its path), defaults filled in.
|
|
51
|
+
* Inside a linked worktree, `mainRoot` is the repository's main checkout: a worktree
|
|
52
|
+
* with no settings of its own uses the repository's, so `int mode` / `int gate` set once
|
|
53
|
+
* apply to every parallel agent's worktree.
|
|
54
|
+
*/
|
|
55
|
+
export function repoSettings(config, root, mainRoot = null) {
|
|
56
|
+
const lookup = (dir) => (dir ? (config.repos?.[repoKey(dir)] ?? config.repos?.[dir]) : null);
|
|
57
|
+
const stored = lookup(root) || lookup(mainRoot) || {};
|
|
49
58
|
return {
|
|
50
59
|
mode: MODES.includes(stored.mode) ? stored.mode : null,
|
|
51
60
|
gate: typeof stored.gate === 'string' && stored.gate.trim() ? stored.gate.trim() : null,
|
package/lib/git.mjs
CHANGED
|
@@ -25,6 +25,37 @@ export function createGit(cwd) {
|
|
|
25
25
|
cwd,
|
|
26
26
|
run,
|
|
27
27
|
root: () => value(['rev-parse', '--show-toplevel']),
|
|
28
|
+
/**
|
|
29
|
+
* The main working tree of this repository: the same as root() in an ordinary
|
|
30
|
+
* checkout, the original checkout inside a linked worktree (`git worktree add`),
|
|
31
|
+
* so every worktree of one repository shares its settings. Null for a bare repository.
|
|
32
|
+
*/
|
|
33
|
+
mainRoot: () => {
|
|
34
|
+
const common = value(['rev-parse', '--path-format=absolute', '--git-common-dir'])
|
|
35
|
+
?? (() => {
|
|
36
|
+
const relative = value(['rev-parse', '--git-common-dir']);
|
|
37
|
+
return relative === null ? null : path.resolve(cwd, relative);
|
|
38
|
+
})();
|
|
39
|
+
if (!common) return null;
|
|
40
|
+
return path.basename(common) === '.git' ? path.dirname(common) : value(['rev-parse', '--show-toplevel']);
|
|
41
|
+
},
|
|
42
|
+
/** Linked and main worktrees as { path, branch, head }, main first (`git worktree list --porcelain`). */
|
|
43
|
+
worktrees: () => {
|
|
44
|
+
const text = value(['worktree', 'list', '--porcelain']);
|
|
45
|
+
if (text === null) return [];
|
|
46
|
+
return text.split(/\n\n+/).map((block) => {
|
|
47
|
+
const entry = {};
|
|
48
|
+
for (const line of block.split('\n')) {
|
|
49
|
+
const [key, ...rest] = line.split(' ');
|
|
50
|
+
if (key === 'worktree') entry.path = rest.join(' ');
|
|
51
|
+
else if (key === 'HEAD') entry.head = rest[0];
|
|
52
|
+
else if (key === 'branch') entry.branch = rest.join(' ').replace(/^refs\/heads\//, '');
|
|
53
|
+
else if (key === 'detached') entry.branch = null;
|
|
54
|
+
else if (key === 'bare') entry.bare = true;
|
|
55
|
+
}
|
|
56
|
+
return entry;
|
|
57
|
+
}).filter((entry) => entry.path);
|
|
58
|
+
},
|
|
28
59
|
gitDir: () => value(['rev-parse', '--absolute-git-dir']),
|
|
29
60
|
head: () => value(['rev-parse', '--verify', '--quiet', 'HEAD']),
|
|
30
61
|
shortHead: () => value(['rev-parse', '--short', 'HEAD']),
|
package/lib/jsonFile.mjs
CHANGED
|
@@ -66,7 +66,7 @@ const RENAME_RETRY_MS = 2_000;
|
|
|
66
66
|
const TRANSIENT = new Set(['EPERM', 'EACCES', 'EBUSY']);
|
|
67
67
|
const pause = (ms) => { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); };
|
|
68
68
|
|
|
69
|
-
function renameWithRetry(from, to) {
|
|
69
|
+
export function renameWithRetry(from, to) {
|
|
70
70
|
const deadline = Date.now() + RENAME_RETRY_MS;
|
|
71
71
|
let delay = 5;
|
|
72
72
|
for (;;) {
|
|
@@ -81,20 +81,28 @@ function renameWithRetry(from, to) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
export function writeAtomic(file, text) {
|
|
84
|
+
export function writeAtomic(file, text, options) {
|
|
85
85
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
86
86
|
const tmp = `${file}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
87
|
-
fs.writeFileSync(tmp, text);
|
|
88
87
|
try {
|
|
88
|
+
const fd = fs.openSync(tmp, 'wx', options?.mode);
|
|
89
|
+
try {
|
|
90
|
+
fs.writeFileSync(fd, text);
|
|
91
|
+
if (options?.durable) fs.fsyncSync(fd);
|
|
92
|
+
} finally { fs.closeSync(fd); }
|
|
89
93
|
renameWithRetry(tmp, file);
|
|
94
|
+
if (options?.durable && process.platform !== 'win32') {
|
|
95
|
+
const dirFd = fs.openSync(path.dirname(file), 'r');
|
|
96
|
+
try { fs.fsyncSync(dirFd); } finally { fs.closeSync(dirFd); }
|
|
97
|
+
}
|
|
90
98
|
} catch (error) {
|
|
91
99
|
try { fs.rmSync(tmp, { force: true }); } catch { /* best effort */ }
|
|
92
100
|
throw error;
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
export function writeJson(file, value) {
|
|
97
|
-
writeAtomic(file, `${JSON.stringify(value, null, 2)}\n
|
|
104
|
+
export function writeJson(file, value, options) {
|
|
105
|
+
writeAtomic(file, `${JSON.stringify(value, null, 2)}\n`, options);
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
export function appendLine(file, line) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "introsio",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Connect
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Connect coding agents to Introsio with MCP, execution hooks, pause/resume, parallel worktrees and managed attempt workspace tooling.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"int": "cli.mjs",
|
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"cli.mjs",
|
|
15
15
|
"lib",
|
|
16
|
+
"runner",
|
|
16
17
|
"hook",
|
|
17
18
|
"agents",
|
|
18
19
|
"opencode",
|
|
19
20
|
"templates",
|
|
20
21
|
"README.md",
|
|
22
|
+
"docs",
|
|
21
23
|
"LICENSE",
|
|
22
24
|
"CHANGELOG.md"
|
|
23
25
|
],
|