@awebai/oats-pi 0.69.6 → 0.69.8
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/README.md +4 -0
- package/extension/core-loader.mjs +7 -5
- package/extension/failed-turn.mjs +66 -0
- package/extension/index.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@ from the same release tag). This bridge registers no operational tools. It only:
|
|
|
23
23
|
streamingBehavior. @awebai/pi has no such handler. A session that shuts
|
|
24
24
|
down (a reload, say) releases the hold, and pi then runs or refuses the
|
|
25
25
|
task by its own rules;
|
|
26
|
+
- reports a turn that ended in a provider error, once pi has stopped retrying
|
|
27
|
+
and recovering (`agent_settled`, pi 0.80.4 and later): a waiting claim
|
|
28
|
+
through `oats instance waiting`, producer `oats.pi`, cleared by the next run,
|
|
29
|
+
so the instance shows as needing input instead of idling unseen;
|
|
26
30
|
- journals compaction summaries and sends resume nudges when the active
|
|
27
31
|
knowledge capability created `STATE.md`/`log.md`. A startup gets the nudge
|
|
28
32
|
only when pi kept an earlier session of the home (pi files a session once
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* a link to the kernel that launched it) → realpath → its package root, whatever
|
|
11
11
|
* PATH pi has
|
|
12
12
|
* 3. the `oats` binary on PATH → realpath → its package root
|
|
13
|
-
* 4. `npm root -g
|
|
13
|
+
* 4. `npm root -g`/<either npm name of the kernel> (binary not linked but package present)
|
|
14
14
|
* Steps 2 and 3 find the package from the binary's real path: an `oats` that is
|
|
15
15
|
* a script running the kernel from elsewhere names no package, and is passed
|
|
16
16
|
* over. Step 2 takes only a link, and falls through silently without one.
|
|
@@ -20,12 +20,12 @@ import { existsSync, lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
|
20
20
|
import { dirname, join } from "node:path";
|
|
21
21
|
import { pathToFileURL } from "node:url";
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const PKG_NAMES = ["@awebai/oats", "@oats-project/oats"];
|
|
24
24
|
|
|
25
25
|
function isKernelRoot(dir) {
|
|
26
26
|
const pj = join(dir, "package.json");
|
|
27
27
|
if (!existsSync(pj) || !existsSync(join(dir, "lib", "core.mjs"))) return false;
|
|
28
|
-
try { return JSON.parse(readFileSync(pj, "utf8")).name
|
|
28
|
+
try { return PKG_NAMES.includes(JSON.parse(readFileSync(pj, "utf8")).name); } catch { return false; }
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** The kernel package a binary's real path lies in (<pkg>/bin/oats.mjs → <pkg>), or undefined. */
|
|
@@ -54,8 +54,10 @@ function findKernelRoot() {
|
|
|
54
54
|
} catch { /* not on PATH */ }
|
|
55
55
|
try {
|
|
56
56
|
const g = execSync("npm root -g", { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
57
|
-
const
|
|
58
|
-
|
|
57
|
+
for (const name of PKG_NAMES) {
|
|
58
|
+
const cand = join(g, name);
|
|
59
|
+
if (isKernelRoot(cand)) return cand;
|
|
60
|
+
}
|
|
59
61
|
} catch { /* no npm */ }
|
|
60
62
|
return undefined;
|
|
61
63
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* failed-turn.mjs — a turn that ends in a provider error stops the instance with
|
|
3
|
+
* nothing left to run an instruction, so the bridge says so itself
|
|
4
|
+
* (awebai/oats#1667): a waiting claim through the kernel's verb, as oats.core
|
|
5
|
+
* does for Claude Code.
|
|
6
|
+
*
|
|
7
|
+
* agent_end is too early: pi retries a transient error and recovers an overflow
|
|
8
|
+
* after it, and each attempt has its own agent_end. Only agent_settled (pi 0.80.4
|
|
9
|
+
* and later) says pi will not go on, and a pi without it reports nothing. The last
|
|
10
|
+
* run decides: a retry that worked leaves nothing to report, and an abort is not an
|
|
11
|
+
* error, even one that cancels a retry's backoff, where no agent_end follows the
|
|
12
|
+
* error it was retrying. The next run clears the claim. This process cannot know what an earlier pi
|
|
13
|
+
* in the session claimed (a /reload, a pi started again in the pane), so its first run
|
|
14
|
+
* clears too; after that, a run with no claim to clear starts no process.
|
|
15
|
+
*/
|
|
16
|
+
import { execFile } from "node:child_process";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
|
|
19
|
+
/** The characters the kernel refuses in a claim's message: a copy of its set
|
|
20
|
+
* (lib/refused-text.mjs REFUSED_TEXT), which this package cannot import before it
|
|
21
|
+
* has found the kernel. A claim the kernel refuses is a stuck instance nobody
|
|
22
|
+
* sees. A test pins the two equal. */
|
|
23
|
+
export const MESSAGE_REFUSED = /[\p{Cc}\u2028\u2029\u202A-\u202E\u2066-\u2069\u200B\u2060\uFEFF\u{E0000}-\u{E007F}]/gu;
|
|
24
|
+
/** The kernel's longest message, in code points (lib/instance-events.mjs WAITING_MESSAGE_MAX). */
|
|
25
|
+
const MESSAGE_MAX = 200;
|
|
26
|
+
|
|
27
|
+
/** The claim's message for a run's error: one the kernel accepts, whatever the provider said. */
|
|
28
|
+
export function failedTurnMessage(error) {
|
|
29
|
+
const said = typeof error === "string" ? error.replace(/\s+/gu, " ").trim().replace(MESSAGE_REFUSED, "\ufffd") : "";
|
|
30
|
+
const points = [...(said ? `Turn failed: ${said}` : "Turn failed")];
|
|
31
|
+
return points.length > MESSAGE_MAX ? `${points.slice(0, MESSAGE_MAX - 1).join("")}…` : points.join("");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Writes run one at a time, so a clear cannot pass the set it answers, and a session
|
|
35
|
+
* that ends waits for them: a /reload's next reporter starts its own queue, and a set
|
|
36
|
+
* still under way would land after its clear. A write is bounded by its timeout, and
|
|
37
|
+
* a failed one is dropped: reporting must never break a session. */
|
|
38
|
+
export function reportFailedTurn(pi, home) {
|
|
39
|
+
let failure;
|
|
40
|
+
let claimed = true;
|
|
41
|
+
let writes = Promise.resolve();
|
|
42
|
+
const waiting = (...args) => {
|
|
43
|
+
const argv = ["instance", "waiting", ...args, "--producer", "oats.pi", "--home", home, "--json"];
|
|
44
|
+
writes = writes.then(() => new Promise((done) => {
|
|
45
|
+
execFile(join(home, ".oats", "bin", "oats"), argv, { cwd: home, timeout: 5000 }, () => done());
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
48
|
+
pi.on("agent_start", () => {
|
|
49
|
+
failure = undefined;
|
|
50
|
+
if (!claimed) return;
|
|
51
|
+
claimed = false;
|
|
52
|
+
waiting("clear");
|
|
53
|
+
});
|
|
54
|
+
pi.on("agent_end", (event) => {
|
|
55
|
+
const last = event.messages?.findLast((message) => message.role === "assistant");
|
|
56
|
+
failure = last?.stopReason === "error" ? failedTurnMessage(last.errorMessage) : undefined;
|
|
57
|
+
});
|
|
58
|
+
pi.on("agent_settled", (event) => {
|
|
59
|
+
const reported = event.aborted ? undefined : failure;
|
|
60
|
+
failure = undefined;
|
|
61
|
+
if (reported === undefined) return;
|
|
62
|
+
claimed = true;
|
|
63
|
+
waiting("set", "--reason", "attention", `--message=${reported}`);
|
|
64
|
+
});
|
|
65
|
+
pi.on("session_shutdown", () => writes);
|
|
66
|
+
}
|
package/extension/index.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
10
10
|
import { appendLogEntry, PACKAGED_SKILLS_DIR } from "./core-loader.mjs";
|
|
11
|
+
import { reportFailedTurn } from "./failed-turn.mjs";
|
|
11
12
|
import { closeSync, existsSync, openSync, readdirSync, readSync, statSync } from "node:fs";
|
|
12
13
|
import { join } from "node:path";
|
|
13
14
|
|
|
@@ -26,6 +27,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
26
27
|
|
|
27
28
|
if (isInstance) {
|
|
28
29
|
holdOpeningTask(pi);
|
|
30
|
+
reportFailedTurn(pi, agentHome!);
|
|
29
31
|
|
|
30
32
|
pi.on("session_compact", async (event) => {
|
|
31
33
|
if (!existsSync(join(agentHome!, "STATE.md"))) return;
|
package/package.json
CHANGED