@harness-reins/linux-x64 0.0.0-stage → 0.9.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/reins/_internal/base_library.zip +0 -0
- package/dist/reins/_internal/harness_reins/_build.txt +1 -0
- package/dist/reins/_internal/harness_reins/assets/skills/claude/SKILL.md +140 -0
- package/dist/reins/_internal/harness_reins/assets/skills/codex/SKILL.md +88 -0
- package/dist/reins/_internal/harness_reins/assets/skills/pi/SKILL.md +98 -0
- package/dist/reins/_internal/harness_reins/assets/skills/reference/SKILL.md +812 -0
- package/dist/reins/_internal/harness_reins/assets/skills/reference/agents/openai.yaml +4 -0
- package/dist/reins/_internal/harness_reins/harness/codex/desktop/windows_assets/desktop-package-launch.py +263 -0
- package/dist/reins/_internal/harness_reins/harness/codex/desktop/windows_assets/invoke-desktop-package.ps1 +14 -0
- package/dist/reins/_internal/harness_reins/harness/codex/desktop/windows_assets/probe-desktop-launch.py +217 -0
- package/dist/reins/_internal/harness_reins/harness/codex/desktop/windows_assets/start-desktop-bridge.ps1 +449 -0
- package/dist/reins/_internal/harness_reins/harness/pi/extension/reins-callback.js +272 -0
- package/dist/reins/_internal/harness_reins/owners/windows_scheduler.ps1 +156 -0
- package/dist/reins/_internal/harness_reins/templates/test.md +38 -0
- package/dist/reins/_internal/harness_reins-0.9.0.dist-info/INSTALLER +1 -0
- package/dist/reins/_internal/harness_reins-0.9.0.dist-info/METADATA +13 -0
- package/dist/reins/_internal/harness_reins-0.9.0.dist-info/RECORD +199 -0
- package/dist/reins/_internal/harness_reins-0.9.0.dist-info/REQUESTED +0 -0
- package/dist/reins/_internal/harness_reins-0.9.0.dist-info/WHEEL +5 -0
- package/dist/reins/_internal/harness_reins-0.9.0.dist-info/direct_url.json +1 -0
- package/dist/reins/_internal/harness_reins-0.9.0.dist-info/entry_points.txt +3 -0
- package/dist/reins/_internal/harness_reins-0.9.0.dist-info/top_level.txt +1 -0
- package/dist/reins/_internal/lib-dynload/_bisect.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_blake2.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_bz2.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_codecs_cn.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_codecs_hk.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_codecs_iso2022.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_codecs_jp.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_codecs_kr.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_codecs_tw.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_contextvars.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_csv.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_ctypes.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_datetime.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_decimal.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_hashlib.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_heapq.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_json.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_lzma.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_md5.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_multibytecodec.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_opcode.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_pickle.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_posixsubprocess.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_random.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_sha1.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_sha2.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_sha3.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_socket.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_ssl.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_statistics.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_struct.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/_uuid.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/array.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/binascii.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/fcntl.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/grp.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/math.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/pyexpat.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/resource.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/select.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/termios.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/unicodedata.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/lib-dynload/zlib.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/_internal/libbz2.so.1.0 +0 -0
- package/dist/reins/_internal/libcrypto.so.1.1 +0 -0
- package/dist/reins/_internal/libffi.so.7 +0 -0
- package/dist/reins/_internal/liblzma.so.5 +0 -0
- package/dist/reins/_internal/libpython3.12.so.1.0 +0 -0
- package/dist/reins/_internal/libssl.so.1.1 +0 -0
- package/dist/reins/_internal/libuuid.so.1 +0 -0
- package/dist/reins/_internal/libz.so.1 +0 -0
- package/dist/reins/_internal/yaml/_yaml.cpython-312-x86_64-linux-gnu.so +0 -0
- package/dist/reins/reins +0 -0
- package/package.json +14 -4
- package/README.md +0 -3
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// Generic Pi callback integration. No user templates or model configuration.
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
import * as crypto from "node:crypto";
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
|
|
8
|
+
const SLOT = Symbol.for("harness-reins.pi-extension.v1");
|
|
9
|
+
const norm = (value) => process.platform === "win32" ? value.toLowerCase() : value;
|
|
10
|
+
const digest = (value) => crypto.createHash("sha256").update(value).digest("hex");
|
|
11
|
+
|
|
12
|
+
function canonical(value) {
|
|
13
|
+
if (typeof value !== "string" || !path.isAbsolute(value)) throw new Error("An absolute session file is required");
|
|
14
|
+
return norm(fs.existsSync(value) ? fs.realpathSync(value) : path.resolve(value));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function privateDirectory(directory) {
|
|
18
|
+
fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
19
|
+
const stat = fs.lstatSync(directory);
|
|
20
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) throw new Error("Unsafe Pi callback directory");
|
|
21
|
+
if (process.platform !== "win32" && (stat.uid !== process.getuid() || (stat.mode & 0o077))) {
|
|
22
|
+
throw new Error("Pi callback directory must be private");
|
|
23
|
+
}
|
|
24
|
+
if (process.platform === "win32") {
|
|
25
|
+
// Read-only ACL inspection; do not trust an installer marker after ACLs
|
|
26
|
+
// may have changed. Failure means no mailbox publication on this path.
|
|
27
|
+
const script = "$ErrorActionPreference='Stop'; $a=Get-Acl -LiteralPath $env:REINS_PI_ACL_PATH; " +
|
|
28
|
+
"$sid=[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value; " +
|
|
29
|
+
"$allowed=@($sid,'S-1-5-18','S-1-5-32-544'); " +
|
|
30
|
+
"$rules=$a.GetAccessRules($true,$true,[System.Security.Principal.SecurityIdentifier]); " +
|
|
31
|
+
"foreach($r in $rules){if($r.AccessControlType -eq 'Allow' -and $allowed -notcontains $r.IdentityReference.Value){exit 2}}";
|
|
32
|
+
execFileSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], {
|
|
33
|
+
env: { ...process.env, REINS_PI_ACL_PATH: directory }, timeout: 5000, windowsHide: true, stdio: "pipe" });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function readRecord(file, versions = [1]) {
|
|
38
|
+
const stat = fs.lstatSync(file);
|
|
39
|
+
if (stat.isSymbolicLink() || !stat.isFile() || stat.size > 2 * 1024 * 1024) throw new Error("Unsafe Pi callback record");
|
|
40
|
+
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
41
|
+
if (!value || !versions.includes(value.version)) throw new Error("Invalid Pi callback record");
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function writeRecord(file, value) {
|
|
46
|
+
if (fs.existsSync(file) && fs.lstatSync(file).isSymbolicLink()) throw new Error("Preserving a record symlink");
|
|
47
|
+
const temporary = `${file}.${crypto.randomUUID()}.tmp`;
|
|
48
|
+
let fd;
|
|
49
|
+
try {
|
|
50
|
+
fd = fs.openSync(temporary, "wx", 0o600);
|
|
51
|
+
fs.writeFileSync(fd, JSON.stringify(value) + "\n", "utf8");
|
|
52
|
+
fs.fsyncSync(fd);
|
|
53
|
+
fs.closeSync(fd);
|
|
54
|
+
fd = undefined;
|
|
55
|
+
fs.renameSync(temporary, file);
|
|
56
|
+
if (process.platform !== "win32") {
|
|
57
|
+
const directory = fs.openSync(path.dirname(file), "r");
|
|
58
|
+
try { fs.fsyncSync(directory); } finally { fs.closeSync(directory); }
|
|
59
|
+
}
|
|
60
|
+
} finally {
|
|
61
|
+
if (fd !== undefined) fs.closeSync(fd);
|
|
62
|
+
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function alive(pid) {
|
|
67
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
68
|
+
try { process.kill(pid, 0); return true; } catch (error) { return error.code !== "ESRCH"; }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default function ltcCallback(pi) {
|
|
72
|
+
// Both the installed copy and explicitly supplied bundled copy can load.
|
|
73
|
+
// A disposed generation clears this slot so /reload gets fresh handlers.
|
|
74
|
+
if (globalThis[SLOT]?.active) return;
|
|
75
|
+
const state = { active: true, context: undefined, owner: undefined, directory: undefined,
|
|
76
|
+
timer: undefined, polling: false, error: undefined, admitted: new Map() };
|
|
77
|
+
globalThis[SLOT] = state;
|
|
78
|
+
const managed = Boolean(process.env.REINS_PI_RESERVATION);
|
|
79
|
+
const recovering = process.env.REINS_PI_RECOVERY === "1";
|
|
80
|
+
|
|
81
|
+
function notice(message) {
|
|
82
|
+
state.context?.ui?.notify?.(`Reins: ${message}`, "warning");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function receipt(file, envelope, status) {
|
|
86
|
+
writeRecord(file, { version: 1, state: status, callback_id: envelope.callback_id,
|
|
87
|
+
pi_delivery: envelope.pi_delivery ?? "follow-up",
|
|
88
|
+
queue_dir: envelope.queue_dir, owner_nonce: envelope.owner_nonce,
|
|
89
|
+
session_file: envelope.session_file, recorded_at: Date.now() / 1000 });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function observedMessages() {
|
|
93
|
+
if (!state.context || state.admitted.size === 0) return;
|
|
94
|
+
const users = state.context.sessionManager.getBranch()
|
|
95
|
+
.filter((entry) => entry.type === "message" && entry.message?.role === "user")
|
|
96
|
+
.map((entry) => typeof entry.message.content === "string" ? entry.message.content :
|
|
97
|
+
entry.message.content.filter((part) => part.type === "text").map((part) => part.text).join("\n"));
|
|
98
|
+
for (const [file, envelope] of state.admitted) {
|
|
99
|
+
if (fs.existsSync(envelope.ack_path)) {
|
|
100
|
+
receipt(file, envelope, "acknowledged");
|
|
101
|
+
state.admitted.delete(file);
|
|
102
|
+
} else if (users.includes(envelope.prompt)) {
|
|
103
|
+
receipt(file, envelope, "session_observed");
|
|
104
|
+
state.admitted.delete(file);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function poll() {
|
|
110
|
+
if (state.polling || !state.active || !state.owner || recovering) return;
|
|
111
|
+
state.polling = true;
|
|
112
|
+
try {
|
|
113
|
+
if (canonical(state.context.sessionManager.getSessionFile()) !== state.owner.session_file) return;
|
|
114
|
+
const owner = readRecord(path.join(state.directory, "owner.json"));
|
|
115
|
+
if (owner.owner_nonce !== state.owner.owner_nonce || owner.owner_pid !== process.pid || owner.state !== "active") return;
|
|
116
|
+
if (managed && (!alive(owner.lease_pid) || (process.platform !== "win32" && process.ppid !== owner.lease_pid))) return;
|
|
117
|
+
observedMessages();
|
|
118
|
+
const inbox = path.join(state.directory, "inbox");
|
|
119
|
+
for (const filename of fs.readdirSync(inbox).filter((name) => /^[a-f0-9]{64}\.json$/.test(name)).sort()) {
|
|
120
|
+
const envelope = readRecord(path.join(inbox, filename), [1, 2]);
|
|
121
|
+
const delivery = envelope.pi_delivery ?? "follow-up";
|
|
122
|
+
if ((envelope.version === 1 && delivery !== "follow-up") ||
|
|
123
|
+
(envelope.version === 2 && delivery !== "steer")) continue;
|
|
124
|
+
if (envelope.owner_nonce !== owner.owner_nonce || envelope.session_file !== owner.session_file) continue;
|
|
125
|
+
if (typeof envelope.callback_id !== "string" || !/^[A-Za-z0-9_-]+$/.test(envelope.callback_id) ||
|
|
126
|
+
typeof envelope.prompt !== "string" || !envelope.prompt || typeof envelope.queue_dir !== "string" ||
|
|
127
|
+
!path.isAbsolute(envelope.queue_dir)) continue;
|
|
128
|
+
const queue = canonical(envelope.queue_dir);
|
|
129
|
+
if (canonical(envelope.ack_path) !== canonical(path.join(queue, "acks", `${envelope.callback_id}.json`)) ||
|
|
130
|
+
canonical(envelope.canceled_path) !== canonical(path.join(queue, "canceled", `${envelope.callback_id}.json`)) ||
|
|
131
|
+
filename !== `${digest(queue + "\0" + envelope.callback_id)}.json`) continue;
|
|
132
|
+
const received = path.join(state.directory, "receipts", filename);
|
|
133
|
+
if (fs.existsSync(received)) continue; // Never replay an ambiguous admission.
|
|
134
|
+
if (fs.existsSync(envelope.ack_path)) { receipt(received, envelope, "acknowledged"); continue; }
|
|
135
|
+
if (fs.existsSync(envelope.canceled_path)) { receipt(received, envelope, "canceled"); continue; }
|
|
136
|
+
// Older callbacks retain their follow-up intent. New callbacks enter
|
|
137
|
+
// Pi's native steer queue while busy, before the next model call, and
|
|
138
|
+
// start a normal turn while idle. Legacy envelopes must not block them.
|
|
139
|
+
if (delivery === "follow-up" && !state.context.isIdle()) continue;
|
|
140
|
+
// Native API returns void. This marker records an attempt, not success.
|
|
141
|
+
receipt(received, envelope, "admitted");
|
|
142
|
+
if (fs.existsSync(envelope.canceled_path)) { receipt(received, envelope, "canceled"); continue; }
|
|
143
|
+
if (managed && (!alive(owner.lease_pid) || (process.platform !== "win32" && process.ppid !== owner.lease_pid))) return;
|
|
144
|
+
state.admitted.set(received, envelope);
|
|
145
|
+
pi.sendUserMessage(envelope.prompt, { deliverAs: delivery === "steer" ? "steer" : "followUp" });
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
// Leave every published/admitted envelope intact for ACK or recovery.
|
|
150
|
+
// Mailbox failure must not freeze ordinary work under a valid writer.
|
|
151
|
+
state.mailboxError = String(error.message ?? error);
|
|
152
|
+
} finally { state.polling = false; }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
pi.on("session_start", async (_event, context) => {
|
|
156
|
+
state.active = true;
|
|
157
|
+
globalThis[SLOT] = state;
|
|
158
|
+
state.admitted.clear();
|
|
159
|
+
if (state.timer) clearInterval(state.timer);
|
|
160
|
+
state.context = context;
|
|
161
|
+
try {
|
|
162
|
+
const file = context.sessionManager.getSessionFile();
|
|
163
|
+
if (!file) return; // --no-session children have no callback owner.
|
|
164
|
+
const session = canonical(file);
|
|
165
|
+
const profile = canonical(path.resolve(process.env.PI_CODING_AGENT_DIR || path.join(os.homedir(), ".pi", "agent")));
|
|
166
|
+
const root = path.resolve(process.env.REINS_PI_CHANNEL_ROOT || path.join(profile, "harness-reins", "channels"));
|
|
167
|
+
if (process.platform === "win32" && !fs.existsSync(root)) {
|
|
168
|
+
throw new Error("Install the extension with Reins to initialize private Windows channel permissions");
|
|
169
|
+
}
|
|
170
|
+
privateDirectory(root);
|
|
171
|
+
const directory = path.join(root, digest(session));
|
|
172
|
+
privateDirectory(directory);
|
|
173
|
+
privateDirectory(path.join(directory, "inbox"));
|
|
174
|
+
privateDirectory(path.join(directory, "receipts"));
|
|
175
|
+
const ownerPath = path.join(directory, "owner.json");
|
|
176
|
+
const previous = fs.existsSync(ownerPath) ? readRecord(ownerPath) : undefined;
|
|
177
|
+
if (managed) {
|
|
178
|
+
const checks = { reservation: previous?.managed === true, session: previous?.session_file === session,
|
|
179
|
+
nonce: previous?.owner_nonce === process.env.REINS_PI_RESERVATION, lease: alive(previous?.lease_pid),
|
|
180
|
+
unclaimed: previous?.state === "reserved" || previous?.owner_pid === process.pid,
|
|
181
|
+
parent: previous?.state !== "reserved" || process.platform === "win32" || previous?.lease_pid === process.ppid,
|
|
182
|
+
sessionId: previous?.session_id === context.sessionManager.getSessionId() };
|
|
183
|
+
const failures = Object.entries(checks).filter(([, valid]) => !valid).map(([name]) => name);
|
|
184
|
+
if (failures.length) throw new Error(`Managed Pi ownership handshake failed: ${failures.join(", ")}`);
|
|
185
|
+
} else if (previous && previous.owner_pid !== process.pid && alive(previous.owner_pid)) {
|
|
186
|
+
throw new Error("Another Pi process owns this callback mailbox");
|
|
187
|
+
}
|
|
188
|
+
const owner = { ...(managed ? previous : {}), version: 1, session_file: session,
|
|
189
|
+
delivery_modes: ["follow-up", "steer"],
|
|
190
|
+
session_id: context.sessionManager.getSessionId(), profile_dir: profile, channel_dir: directory,
|
|
191
|
+
owner_nonce: managed ? process.env.REINS_PI_RESERVATION : crypto.randomUUID(),
|
|
192
|
+
owner_pid: process.pid, managed, state: "active", recorded_at: Date.now() / 1000 };
|
|
193
|
+
if (previous?.owner_pid !== process.pid) delete owner.owner_identity;
|
|
194
|
+
const spawnPath = path.join(directory, `spawn-${owner.owner_nonce}.json`);
|
|
195
|
+
if (managed && fs.existsSync(spawnPath)) {
|
|
196
|
+
const spawn = readRecord(spawnPath);
|
|
197
|
+
if (spawn.owner_nonce === owner.owner_nonce && spawn.owner_pid === process.pid) {
|
|
198
|
+
owner.owner_identity = spawn.owner_identity;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
writeRecord(ownerPath, owner);
|
|
202
|
+
state.owner = owner;
|
|
203
|
+
state.directory = directory;
|
|
204
|
+
state.error = undefined;
|
|
205
|
+
state.timer = setInterval(poll, 200);
|
|
206
|
+
state.timer.unref();
|
|
207
|
+
} catch (error) {
|
|
208
|
+
state.error = String(error.message ?? error);
|
|
209
|
+
notice(state.error);
|
|
210
|
+
if (managed) {
|
|
211
|
+
// Built-in commands bypass input hooks. Do not enter Pi's input loop
|
|
212
|
+
// with a failed ownership handshake, even briefly.
|
|
213
|
+
process.stderr.write(`Reins: ${state.error}; exiting\n`);
|
|
214
|
+
process.exit(2);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
pi.on("input", async (_event, context) => {
|
|
220
|
+
if (!managed || !context.sessionManager.getSessionFile()) return { action: "continue" };
|
|
221
|
+
if (recovering && [process.env.REINS_PI_CALLBACK_ACK_PATH, process.env.REINS_PI_CALLBACK_CANCEL_PATH]
|
|
222
|
+
.some((file) => file && fs.existsSync(file))) return { action: "handled" };
|
|
223
|
+
try {
|
|
224
|
+
if (state.error || !state.owner || canonical(context.sessionManager.getSessionFile()) !== state.owner.session_file ||
|
|
225
|
+
!alive(state.owner.lease_pid) || (process.platform !== "win32" && process.ppid !== state.owner.lease_pid)) {
|
|
226
|
+
throw new Error("Managed Pi session ownership is unavailable");
|
|
227
|
+
}
|
|
228
|
+
const current = readRecord(path.join(state.directory, "owner.json"));
|
|
229
|
+
if (current.owner_nonce !== state.owner.owner_nonce || current.owner_pid !== process.pid) {
|
|
230
|
+
throw new Error("Managed Pi owner changed");
|
|
231
|
+
}
|
|
232
|
+
return { action: "continue" };
|
|
233
|
+
} catch (error) {
|
|
234
|
+
notice(String(error.message ?? error));
|
|
235
|
+
return { action: "handled" }; // Pi treats a thrown input hook as continue.
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
pi.on("session_before_switch", async () => {
|
|
240
|
+
if (!managed) return;
|
|
241
|
+
// Even reopening this same file can race a settling native turn's append.
|
|
242
|
+
// Keep the in-memory branch until the managed launcher exits.
|
|
243
|
+
notice("Start reins pi with the chosen session to switch managed files");
|
|
244
|
+
return { cancel: true };
|
|
245
|
+
});
|
|
246
|
+
pi.on("session_before_fork", async () => {
|
|
247
|
+
if (!managed) return;
|
|
248
|
+
notice("Start a separate reins pi session to fork managed work");
|
|
249
|
+
return { cancel: true };
|
|
250
|
+
});
|
|
251
|
+
pi.on("agent_end", async () => { try { observedMessages(); } catch { /* Remain uncertain. */ } });
|
|
252
|
+
pi.on("session_shutdown", async (event) => {
|
|
253
|
+
state.active = false;
|
|
254
|
+
if (state.timer) clearInterval(state.timer);
|
|
255
|
+
try {
|
|
256
|
+
if (state.owner) {
|
|
257
|
+
const file = path.join(state.directory, "owner.json");
|
|
258
|
+
const current = readRecord(file);
|
|
259
|
+
if (current.owner_nonce === state.owner.owner_nonce && current.owner_pid === process.pid) {
|
|
260
|
+
writeRecord(file, { ...current, state: "closed", recorded_at: Date.now() / 1000 });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
} catch { /* A failed tombstone never authorizes offline recovery. */ }
|
|
264
|
+
if (globalThis[SLOT] === state) delete globalThis[SLOT];
|
|
265
|
+
if (managed && event.reason === "reload") {
|
|
266
|
+
// A failed extension reload would remove the session pin before native
|
|
267
|
+
// commands run. Restart the managed launcher to reload resources safely.
|
|
268
|
+
process.stderr.write("Reins: restart reins pi to reload managed session resources\n");
|
|
269
|
+
process.exit(0);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Fixed controller. Requests and replies are JSON, never localized CLI output.
|
|
2
|
+
$ErrorActionPreference = 'Stop'
|
|
3
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
4
|
+
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
5
|
+
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
6
|
+
|
|
7
|
+
function Error-Code($exception) {
|
|
8
|
+
while ($null -ne $exception.InnerException) { $exception = $exception.InnerException }
|
|
9
|
+
return [int]$exception.HResult
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function Get-Task($folder, [string]$name) {
|
|
13
|
+
try { return $folder.GetTask($name) }
|
|
14
|
+
catch {
|
|
15
|
+
$code = Error-Code $_.Exception
|
|
16
|
+
if ($code -eq -2147024894 -or $code -eq -2147024893) { return $null }
|
|
17
|
+
throw
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function Task-Status($task) {
|
|
22
|
+
if ($null -eq $task) { return @{ registered = $false } }
|
|
23
|
+
$instances = @()
|
|
24
|
+
foreach ($instance in $task.GetInstances(0)) {
|
|
25
|
+
$instances += @{ pid = [int]$instance.EnginePID; guid = [string]$instance.InstanceGuid;
|
|
26
|
+
state = [int]$instance.State }
|
|
27
|
+
}
|
|
28
|
+
# A registered-but-never-started task is ambiguous after a lost Run reply.
|
|
29
|
+
return @{ registered = $true; state = [int]$task.State; instances = $instances;
|
|
30
|
+
has_run = ($task.LastRunTime.Year -ge 2000 -and $task.LastTaskResult -ne 267011);
|
|
31
|
+
last_result = [int]$task.LastTaskResult }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function Register-Task($service, $folder, $request, [string]$sid) {
|
|
35
|
+
$configuration = $request.configuration
|
|
36
|
+
$definition = $service.NewTask(0)
|
|
37
|
+
$definition.RegistrationInfo.Description = 'Harness Reins private worker'
|
|
38
|
+
$definition.Principal.UserId = $sid
|
|
39
|
+
$definition.Principal.LogonType = 3 # TASK_LOGON_INTERACTIVE_TOKEN
|
|
40
|
+
$definition.Principal.RunLevel = 0 # TASK_RUNLEVEL_LUA
|
|
41
|
+
$settings = $definition.Settings
|
|
42
|
+
$settings.Enabled = [bool]$configuration.enabled
|
|
43
|
+
$settings.AllowDemandStart = $true
|
|
44
|
+
$settings.MultipleInstances = 2 # TASK_INSTANCES_IGNORE_NEW
|
|
45
|
+
$settings.ExecutionTimeLimit = 'PT0S'
|
|
46
|
+
$settings.RestartCount = 0
|
|
47
|
+
$settings.DisallowStartIfOnBatteries = $false
|
|
48
|
+
$settings.StopIfGoingOnBatteries = $false
|
|
49
|
+
$settings.RunOnlyIfIdle = $false
|
|
50
|
+
$settings.IdleSettings.StopOnIdleEnd = $false
|
|
51
|
+
$settings.IdleSettings.RestartOnIdle = $false
|
|
52
|
+
$settings.RunOnlyIfNetworkAvailable = $false
|
|
53
|
+
$settings.StartWhenAvailable = $false
|
|
54
|
+
$settings.WakeToRun = $false
|
|
55
|
+
$settings.AllowHardTerminate = $true
|
|
56
|
+
# Only the coordinator can opt into a login trigger. Business attempts cannot.
|
|
57
|
+
if ([bool]$configuration.login) {
|
|
58
|
+
$trigger = $definition.Triggers.Create(9) # TASK_TRIGGER_LOGON
|
|
59
|
+
$trigger.UserId = $sid
|
|
60
|
+
$trigger.Enabled = $true
|
|
61
|
+
}
|
|
62
|
+
$action = $definition.Actions.Create(0) # TASK_ACTION_EXEC
|
|
63
|
+
$action.Path = [string]$configuration.executable
|
|
64
|
+
$action.Arguments = [string]$configuration.arguments
|
|
65
|
+
$action.WorkingDirectory = [string]$configuration.cwd
|
|
66
|
+
$flags = 2 # TASK_CREATE: never replay an existing attempt after uncertainty.
|
|
67
|
+
if ($request.operation -eq 'register' -and [bool]$request.replace) { $flags = 6 }
|
|
68
|
+
$sddl = "D:P(A;;FA;;;SY)(A;;FA;;;$sid)"
|
|
69
|
+
return $folder.RegisterTaskDefinition([string]$request.owner, $definition, $flags, $sid, $null, 3, $sddl)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
$request = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
|
74
|
+
$service = New-Object -ComObject 'Schedule.Service'
|
|
75
|
+
$service.Connect()
|
|
76
|
+
$folder = $service.GetFolder('\')
|
|
77
|
+
$sid = [Security.Principal.WindowsIdentity]::GetCurrent().User.Value
|
|
78
|
+
if ($request.operation -ne 'available' -and [string]$request.owner -notmatch '^[A-Za-z0-9][A-Za-z0-9_.-]{0,199}$') {
|
|
79
|
+
throw 'invalid task owner'
|
|
80
|
+
}
|
|
81
|
+
switch ([string]$request.operation) {
|
|
82
|
+
'available' { $response = @{ available = $true } }
|
|
83
|
+
'status' { $response = Task-Status (Get-Task $folder $request.owner) }
|
|
84
|
+
'definition' {
|
|
85
|
+
$task = Get-Task $folder $request.owner
|
|
86
|
+
if ($null -eq $task) { $response = @{ registered = $false } }
|
|
87
|
+
else {
|
|
88
|
+
$definition = $task.Definition
|
|
89
|
+
$settings = $definition.Settings
|
|
90
|
+
$response = @{ registered = $true; xml = [string]$task.Xml;
|
|
91
|
+
logon_type = [int]$definition.Principal.LogonType;
|
|
92
|
+
run_level = [int]$definition.Principal.RunLevel;
|
|
93
|
+
executable = [string]$definition.Actions.Item(1).Path;
|
|
94
|
+
trigger_count = [int]$definition.Triggers.Count;
|
|
95
|
+
multiple_instances = [int]$settings.MultipleInstances;
|
|
96
|
+
execution_time_limit = [string]$settings.ExecutionTimeLimit;
|
|
97
|
+
restart_count = [int]$settings.RestartCount;
|
|
98
|
+
disallow_batteries = [bool]$settings.DisallowStartIfOnBatteries;
|
|
99
|
+
stop_batteries = [bool]$settings.StopIfGoingOnBatteries;
|
|
100
|
+
only_idle = [bool]$settings.RunOnlyIfIdle;
|
|
101
|
+
start_when_available = [bool]$settings.StartWhenAvailable }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
'register' {
|
|
105
|
+
$null = Register-Task $service $folder $request $sid
|
|
106
|
+
$response = @{ registered = $true }
|
|
107
|
+
}
|
|
108
|
+
'launch' {
|
|
109
|
+
if ([bool]$request.configuration.login) { throw 'business task cannot have a login trigger' }
|
|
110
|
+
$task = Register-Task $service $folder $request $sid
|
|
111
|
+
$instance = $task.Run($null)
|
|
112
|
+
$response = @{ submitted = $true; guid = [string]$instance.InstanceGuid }
|
|
113
|
+
}
|
|
114
|
+
'run' {
|
|
115
|
+
$task = Get-Task $folder $request.owner
|
|
116
|
+
if ($null -eq $task) { throw 'task not registered' }
|
|
117
|
+
$instance = $task.Run($null)
|
|
118
|
+
$response = @{ submitted = $true; guid = [string]$instance.InstanceGuid }
|
|
119
|
+
}
|
|
120
|
+
'stop' {
|
|
121
|
+
$task = Get-Task $folder $request.owner
|
|
122
|
+
if ($null -ne $task) { $task.Stop(0) }
|
|
123
|
+
$response = @{ stopped = $true }
|
|
124
|
+
}
|
|
125
|
+
'collect' {
|
|
126
|
+
$status = Task-Status (Get-Task $folder $request.owner)
|
|
127
|
+
$collected = -not $status.registered
|
|
128
|
+
if ($status.registered -and $status.has_run -and $status.state -in @(1, 3) -and $status.instances.Count -eq 0) {
|
|
129
|
+
$folder.DeleteTask([string]$request.owner, 0)
|
|
130
|
+
$collected = $true
|
|
131
|
+
}
|
|
132
|
+
$response = @{ collected = $collected }
|
|
133
|
+
}
|
|
134
|
+
'delete' {
|
|
135
|
+
# Removing a service definition never stops its live instance.
|
|
136
|
+
$task = Get-Task $folder $request.owner
|
|
137
|
+
if ($null -ne $task) { $folder.DeleteTask([string]$request.owner, 0) }
|
|
138
|
+
$response = @{ deleted = $true }
|
|
139
|
+
}
|
|
140
|
+
'enable' {
|
|
141
|
+
$task = Get-Task $folder $request.owner
|
|
142
|
+
if ($null -eq $task) { throw 'task not registered' }
|
|
143
|
+
$task.Enabled = [bool]$request.enabled
|
|
144
|
+
$response = @{ enabled = [bool]$request.enabled }
|
|
145
|
+
}
|
|
146
|
+
default { throw 'invalid operation' }
|
|
147
|
+
}
|
|
148
|
+
$response.ok = $true
|
|
149
|
+
[Console]::Out.WriteLine(($response | ConvertTo-Json -Compress -Depth 8))
|
|
150
|
+
exit 0
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
$response = @{ ok = $false; hresult = (Error-Code $_.Exception) }
|
|
154
|
+
[Console]::Out.WriteLine(($response | ConvertTo-Json -Compress))
|
|
155
|
+
exit 1
|
|
156
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Independent test author — template test v1
|
|
2
|
+
|
|
3
|
+
You are a fresh child agent assigned to WRITE tests. The parent agent will EXECUTE
|
|
4
|
+
them after your handoff. Do not run tests, test collection, the application under
|
|
5
|
+
test, or code that imports it. Do not delegate execution to another agent.
|
|
6
|
+
|
|
7
|
+
First read the supplied requirements and referenced specifications. Establish
|
|
8
|
+
expected observable behavior from those sources BEFORE studying implementation.
|
|
9
|
+
Record requirement sources and ambiguities. Implementation and existing tests
|
|
10
|
+
may explain interfaces and conventions, but are not an oracle for correctness.
|
|
11
|
+
If requirements are insufficient, report the precise missing contract; do not
|
|
12
|
+
invent expected behavior or silently encode the implementation's current output.
|
|
13
|
+
|
|
14
|
+
Inspect project instructions and test conventions. Write focused executable tests
|
|
15
|
+
and necessary test-only fixtures/helpers. Do not modify production code, dependency
|
|
16
|
+
manifests, project configuration, or existing assertions to make tests pass. Do not
|
|
17
|
+
overwrite another agent's edits. Work in the provided workspace; report conflicts.
|
|
18
|
+
|
|
19
|
+
Cover relevant boundary conditions, invalid inputs, failure paths, state transitions,
|
|
20
|
+
and regressions as well as representative valid behavior. For each test identify
|
|
21
|
+
a plausible faulty implementation it would reject. Avoid tautological assertions,
|
|
22
|
+
snapshots copied from current output, mocks replacing the behavior being tested,
|
|
23
|
+
and tests merely mirroring internal control flow. Prefer deterministic cases and
|
|
24
|
+
independent expected values; explain any necessary mocks at external boundaries.
|
|
25
|
+
Preserve legitimate uncertainty rather than claiming comprehensive coverage.
|
|
26
|
+
|
|
27
|
+
Finish with a handoff containing:
|
|
28
|
+
1. Status: authored / blocked / partial. State "Tests have NOT been run" only if
|
|
29
|
+
true. Disclose any accidental execution (commands/results) or production edits;
|
|
30
|
+
never conceal a deviation from this assignment.
|
|
31
|
+
2. Files added or changed, with test names.
|
|
32
|
+
3. Requirement -> test -> expected behavior -> plausible defect caught mapping.
|
|
33
|
+
4. Exact commands and working directory for the parent to execute, dependencies,
|
|
34
|
+
fixtures, and any environment requirements. Do not install dependencies yourself.
|
|
35
|
+
5. Assumptions, missing contracts, uncovered risks, and any scope conflicts.
|
|
36
|
+
|
|
37
|
+
A successful authoring process is not evidence that tests pass or that the product
|
|
38
|
+
is correct. The parent must execute the tests and report actual results separately.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pip
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: harness-reins
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Harness Reins: a harness for your harnesses. Dispatch work to Codex, Claude Code or Pi and route the result back to the session that asked.
|
|
5
|
+
Author: Local
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: agents,harness,codex,claude-code,pi,callback,long-running-tasks
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Requires-Dist: PyYAML>=6.0
|