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,54 @@
|
|
|
1
|
+
// Read-only recovery: server unavailability is never interpreted as permission
|
|
2
|
+
// to release an attempt, kill a PID, adopt a checkout or discard local work.
|
|
3
|
+
import { listWorkspaces } from './workspaceManager.mjs';
|
|
4
|
+
import { attemptIdentity } from './workspaceJournal.mjs';
|
|
5
|
+
import { readProcessRecord,unresolvedProcess } from './processJournal.mjs';
|
|
6
|
+
|
|
7
|
+
export function classifyAuthority(record, packet, now = Date.now()) {
|
|
8
|
+
if (!packet || typeof packet !== 'object') return 'unknown';
|
|
9
|
+
let expected, actual;
|
|
10
|
+
try { expected = attemptIdentity(record); actual = attemptIdentity(packet); } catch { return 'unknown'; }
|
|
11
|
+
if (expected.projectId !== actual.projectId || expected.taskId !== actual.taskId) return 'unknown';
|
|
12
|
+
if (expected.attemptId !== actual.attemptId || expected.fence !== actual.fence ||
|
|
13
|
+
expected.generation !== actual.generation || expected.baseSha !== actual.baseSha) return 'superseded';
|
|
14
|
+
if (typeof packet.repository !== 'string' || packet.repository.toLowerCase() !== record.repository) return 'unknown';
|
|
15
|
+
if (packet.active === false) return 'inactive';
|
|
16
|
+
const expires = Date.parse(packet.expiresAt);
|
|
17
|
+
if (packet.active !== true || !Number.isFinite(expires)) return 'unknown';
|
|
18
|
+
return expires <= now ? 'expired' : 'active';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function recoveryDecision(workspace, authority) {
|
|
22
|
+
if (workspace.state === 'orphaned' || workspace.state === 'quarantined' ||
|
|
23
|
+
workspace.state === 'missing' || workspace.exists === false) return 'inspect-manually';
|
|
24
|
+
if (workspace.state !== 'ready') return 'inspect-interrupted';
|
|
25
|
+
if (authority === 'active') return 'retain-active';
|
|
26
|
+
if (authority === 'unknown') return 'retain-unverified';
|
|
27
|
+
// Even a clean status does not include ignored files, and an upstream
|
|
28
|
+
// branch is not proof that all local commits have reached the server.
|
|
29
|
+
return 'retain-for-review';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function reconcileWorkspaces({ env = process.env, lookupAttempt, now = Date.now(), workspaces = listWorkspaces } = {}) {
|
|
33
|
+
const result = [];
|
|
34
|
+
for (const workspace of workspaces(env)) {
|
|
35
|
+
let authority = 'unknown';
|
|
36
|
+
if (workspace.state === 'ready' && typeof lookupAttempt === 'function') {
|
|
37
|
+
try { authority = classifyAuthority(workspace, await lookupAttempt(attemptIdentity(workspace)), now); }
|
|
38
|
+
catch { /* offline, denied, invalid response: retain everything */ }
|
|
39
|
+
}
|
|
40
|
+
let processState=null;
|
|
41
|
+
let processUnresolved=false;
|
|
42
|
+
if(workspace.state==='ready') {
|
|
43
|
+
try { const record=readProcessRecord(workspace,env);processState=record?.state??null;processUnresolved=unresolvedProcess(record); }
|
|
44
|
+
catch { processState='unverified';processUnresolved=true; }
|
|
45
|
+
}
|
|
46
|
+
result.push({
|
|
47
|
+
projectId: workspace.projectId, taskId: workspace.taskId, attemptId: workspace.attemptId,
|
|
48
|
+
state: workspace.state, authority, processState, decision: processUnresolved?'inspect-process-manually':recoveryDecision(workspace, authority),
|
|
49
|
+
dirty: workspace.dirty ?? null, unpushed: workspace.unpushed ?? null,
|
|
50
|
+
cwd: workspace.cwd ?? null,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Per-attempt resources for trusted provider adapters. Not an OS sandbox.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import net from 'node:net';
|
|
5
|
+
import { privateDir, workspacePaths } from './workspaceJournal.mjs';
|
|
6
|
+
import { inspectWorkspace } from './workspaceManager.mjs';
|
|
7
|
+
|
|
8
|
+
const SAFE = new Set(['PATH','PATHEXT','SYSTEMROOT','WINDIR','COMSPEC','LANG','LC_ALL','LC_CTYPE','TERM','TZ','NUMBER_OF_PROCESSORS','PROCESSOR_ARCHITECTURE']);
|
|
9
|
+
export function isolatedEnvironment(source, resources) {
|
|
10
|
+
const result = Object.create(null);
|
|
11
|
+
for (const [key,value] of Object.entries(source ?? {})) {
|
|
12
|
+
if (SAFE.has(key.toUpperCase()) && typeof value === 'string' && !value.includes('\0')) result[key] = value;
|
|
13
|
+
}
|
|
14
|
+
// Never inherit the user's HOME, token variables, Git overrides, NODE_OPTIONS,
|
|
15
|
+
// proxy credentials or dotenv settings. Provider auth is a separate capability.
|
|
16
|
+
return Object.assign(result, {
|
|
17
|
+
HOME: resources.home, USERPROFILE: resources.home, TMP: resources.tmp, TEMP: resources.tmp, TMPDIR: resources.tmp,
|
|
18
|
+
XDG_CONFIG_HOME: resources.config, XDG_CACHE_HOME: resources.cache,
|
|
19
|
+
XDG_DATA_HOME: resources.data, INTROSIO_BUILD_DIR: resources.build,
|
|
20
|
+
GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'Never',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function prepareResources(identity, env = process.env) {
|
|
25
|
+
const workspace = inspectWorkspace(identity, env);
|
|
26
|
+
if (workspace.state !== 'ready' || !workspace.exists) throw new Error('A verified ready workspace is required.');
|
|
27
|
+
const paths = workspacePaths(identity, env);
|
|
28
|
+
const dir = path.join(paths.dir, 'resources');
|
|
29
|
+
privateDir(dir, true);
|
|
30
|
+
const resources = { cwd: workspace.cwd };
|
|
31
|
+
for (const name of ['home','tmp','config','cache','data','build']) {
|
|
32
|
+
const target = path.join(dir, name);
|
|
33
|
+
privateDir(target, true);
|
|
34
|
+
resources[name] = target;
|
|
35
|
+
}
|
|
36
|
+
return resources;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Hold the actual socket while allocating; release is idempotent. Once released,
|
|
40
|
+
// the provider must bind immediately or handle EADDRINUSE (no false guarantee).
|
|
41
|
+
export async function reserveLoopbackPort() {
|
|
42
|
+
const server = net.createServer(socket => socket.destroy());
|
|
43
|
+
await new Promise((resolve,reject) => {
|
|
44
|
+
server.once('error',reject);
|
|
45
|
+
server.listen({ host:'127.0.0.1',port:0,exclusive:true },resolve);
|
|
46
|
+
});
|
|
47
|
+
const {port} = server.address();
|
|
48
|
+
let pending;
|
|
49
|
+
return { port, release() {
|
|
50
|
+
if (!pending) pending = new Promise((resolve,reject) => server.close(error => error ? reject(error) : resolve()));
|
|
51
|
+
return pending;
|
|
52
|
+
}};
|
|
53
|
+
}
|
package/templates/execute.md
CHANGED
|
@@ -3,18 +3,26 @@ Execute an Introsio Developer Mode project with the Introsio MCP tools, task by
|
|
|
3
3
|
Project: $ARGUMENTS (a name or id — if empty, call getProjects and ask which Developer Mode project to run).
|
|
4
4
|
|
|
5
5
|
1. Start or resume: getProjectState { projectId } for the overview and the context revision, then getProjectContext { projectId } once. Work inside the context: use its tech stack, never cross a "must" constraint, follow its conventions, do not reopen accepted decisions (record a new one with recordProjectDecision).
|
|
6
|
-
2. Loop:
|
|
6
|
+
2. RegisterWorker: call registerWorkerSession { projectId, protocolVersion: 2 }. Use the returned server-issued workerId and private workerSession on every claimTask, updateTask, updateSubtask, completeTask and pauseTask. Keep the credential in the agent session only; never put it in a repository, outcome, handoff, or chat. Call renewWorkerSession before expiry; revoke it only after all held work is finished or paused. If resuming after revocation or expiry, register a new session and wait for any old lease to expire. Loop:
|
|
7
|
+
Keep the `attempt` object returned by claimTask and send it unchanged on updateTask, updateSubtask, completeTask and pauseTask, including when re-claiming an active task. Before a new claim, generate a private UUID (node -e "console.log(require('crypto').randomUUID())") as claimKey; reuse it only for a retry of that claim after a lost response. A STALE_ATTEMPT or STALE_LEASE refusal ends that attempt. Claim again before reporting more work.
|
|
7
8
|
a. claimTask { projectId, workerId } — use the SAME workerId on every call (the one claimTask returns, or the one the Introsio hook gave you). It hands you the spec, subtask waves, inputs (what earlier tasks produced) and, when the project has one, the GitHub repository.
|
|
9
|
+
Start from the code you build on: each inputs[].outcome.branch must be in your branch before you write anything. If the claim named a repository: git fetch origin, branch off its defaultBranch, then git merge --no-edit origin/<branch> for each input branch. Otherwise merge each input branch that is not already in your current branch (git merge-base --is-ancestor <branch> HEAD tells you). Resolve conflicts; if you cannot, mark the task blocked (step 3).
|
|
8
10
|
b. Do the work, one subtask at a time in the order of subtaskWaves, and report the steps you FINISH — never one you did not do:
|
|
9
11
|
- A task you will finish well inside the lease (leaseExpiresAt in the claim, 30 minutes by default): make no call per step. Name every finished subtask in step e: completeTask { …, completedSubtasks: [ids] }.
|
|
10
12
|
- A longer task: updateSubtask { taskId, subtaskId, workerId, completed: true } as each step finishes — one call, no in_progress first. It saves your progress if the session ends and renews the lease.
|
|
11
13
|
- Only when several workers share one task: mark a subtask in_progress before you start it, so they see it is taken.
|
|
12
14
|
c. Check it: run the tests or commands that prove it works.
|
|
13
|
-
d. Commit it. If the claim named a repository: work on your own branch
|
|
14
|
-
e. completeTask { taskId, workerId, completedSubtasks: [the subtasks you finished and have not reported], outcome: { summary: what you produced (names, shapes, commit id), verification: what you ran and its result, files: paths you changed } }. If it is refused, fix exactly what the error names and call it again.
|
|
15
|
+
d. Commit it. If the claim named a repository: work on your own branch (step a), push it, and record outcome.branch. Otherwise keep it local — commit only, no push — and still record outcome.branch (your current branch), so the tasks that build on yours can merge it.
|
|
16
|
+
e. Generate a fresh random UUIDv4 as requestId for this completion and retain it with the exact request until acknowledged. Retry a lost response with the same requestId and unchanged payload; use a new key if correcting a validation refusal. completeTask { taskId, workerId, attempt, requestId, completedSubtasks: [the subtasks you finished and have not reported], outcome: { summary: what you produced (names, shapes, commit id), verification: what you ran and its result, files: paths you changed } }. If it is refused, fix exactly what the error names and call it again.
|
|
15
17
|
Size the outcome to the task, not to a template: a small change is one line ("Renamed X to Y — abc1234"); a task that later tasks build on adds only the names and shapes they need (endpoints, exports, schema fields, decisions). Never narrate the steps you took, repeat the spec, or list what files already shows. verification is the command and its result in one line.
|
|
16
18
|
The outcome is the record — do not also write a recap in chat. Between tasks say at most one short line ("Done: <title>") and claim the next one; save the wrap-up for when the project is done or you stop.
|
|
17
19
|
f. The answer lists nowReady and openTasks — claim the next task. Do not re-read the schedule after every task.
|
|
20
|
+
g. An integration task (its inputs name several branches) merges ALL of them into one branch, runs the whole test suite, and fixes what breaks between the pieces — its outcome names the merged branch and the full test result.
|
|
18
21
|
3. If you cannot finish a task: updateTask { taskId, workerId, statusState: "blocked" } and tell the user why. Never leave a claimed task silently open.
|
|
19
|
-
4. When claimTask
|
|
22
|
+
4. When claimTask has nothing for you, its reason says why:
|
|
23
|
+
- "all_claimed" (other workers hold the ready work) or "awaiting_completion" (tasks report their phase done but are not completed — completeTask any you hold): do NOT stop. Wait, then claimTask again: run `int wait <retryAfter>` in a shell (it returns after at most 4 minutes; without the int command, wait the same way your tools allow), and repeat. What the other workers finish unlocks your next task. After an hour of waiting with no task, tell the user what is still held and stop.
|
|
24
|
+
- "complete": updateProjectState { projectId, handoff: true, execution: { description: where things stand, status: "done" } }.
|
|
25
|
+
- "paused": the rest of the ready work is paused — tell the user (/introsio-resume takes a paused task back after checking the repository); never claim a paused task without resume: true.
|
|
26
|
+
- "blocked": tell the user which tasks are blocked and why nothing else can start.
|
|
20
27
|
5. If you have to stop before the project is done — out of usage, context or time, or the user asks — follow the /introsio-pause procedure: pauseTask each task you hold with a note, nextSteps, the subtask you were on and the git position, so the work resumes exactly.
|
|
28
|
+
6. Parallel workers: give each agent its OWN folder (`int worktree add <name>` makes one) — two agents in one working tree share one branch and one set of files and break each other's work. Each uses its own workerId; the server never hands one task to two workers.
|
package/templates/pause.md
CHANGED
|
@@ -12,7 +12,7 @@ Be fast and do only this — no new work, no refactoring. If you are cut off par
|
|
|
12
12
|
- git status --porcelain → dirtyFiles (the paths only)
|
|
13
13
|
Never commit, stash, reset or clean anything for a plain pause: the unfinished files stay exactly where they are.
|
|
14
14
|
4. Only with --release: commit the task's work on its own branch (create introsio/<taskId> first if you are on the default branch), push it if the project has a GitHub repository, and record it with updateTask { taskId, workerId, outcome: { branch } }. If you cannot commit cleanly, pause without release instead and say why.
|
|
15
|
-
5. For each task: pauseTask { taskId, workerId, agentName, release (only with --release), completedSubtasks: [the ids from step 2], handoff: {
|
|
15
|
+
5. For each task: pauseTask { taskId, workerId, workerSession (the private protocol v2 credential), attempt (the object returned by its claim), agentName, release (only with --release), completedSubtasks: [the ids from step 2], handoff: {
|
|
16
16
|
reason: "usage_limit" | "context" | "user" | "other",
|
|
17
17
|
subtaskId: the subtask you were on,
|
|
18
18
|
note: written for someone who has NONE of your conversation — what is finished, what is half done and exactly how far (function, file:line, the failing test), what you were about to do, anything you tried that did not work, and the user's note if they gave one,
|
package/templates/resume.md
CHANGED
|
@@ -17,6 +17,6 @@ What to resume: $ARGUMENTS (a task id, a project name or id, or empty).
|
|
|
17
17
|
- EXACT → step 4.
|
|
18
18
|
- DRIFT → show the user each difference in plain words and ask how to go on: restore the snapshot (run the exact restore command the check gave, only after they agree), continue from the repository as it is, or leave it paused. Leaving it paused changes nothing.
|
|
19
19
|
- BLOCKED → do not resume. Explain what is wrong (e.g. the unfinished code is on another computer, another session is working it, a rebase is half done) and stop.
|
|
20
|
-
4. Take it back: claimTask { taskId, workerId, resume: true } — use your own workerId. For
|
|
20
|
+
4. Register a new private worker session using registerWorkerSession { projectId, protocolVersion: 2 }; retain the returned workerSession and workerId. If the previous session is still live, reuse its exact credentials; otherwise wait for any old claim to expire. Take it back: claimTask { taskId, workerId, workerSession, resume: true } — use your own workerId. For interrupted work, retain the original authenticated session when available. A fresh session waits for the old claim to expire before taking a new attempt. If the claim is refused because someone else resumed it first, stop and tell the user.
|
|
21
21
|
The answer carries resumedPause and taskChangedSincePause: if the task changed, read its spec again before coding. If the context revision moved since the pause (pause.contextRevision), getProjectContext once.
|
|
22
|
-
5. Continue from the note and nextSteps, starting at the paused subtask (one updateSubtask { completed: true } when it is done). From here it is the normal loop: work → check → commit → completeTask { taskId, workerId, outcome } → claimTask { projectId, workerId } for the next task, as /introsio-execute does. If you must stop again, use /introsio-pause.
|
|
22
|
+
5. Continue from the note and nextSteps, starting at the paused subtask (one updateSubtask { completed: true } when it is done). From here it is the normal loop: work → check → commit → completeTask { taskId, workerId, workerSession, attempt, outcome } → claimTask { projectId, workerId, workerSession } for the next task, as /introsio-execute does. If you must stop again, use /introsio-pause.
|