@pontia/pi-client-plugin 0.1.0 → 0.2.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/package.json +6 -6
- package/src/discovery.ts +5 -3
- package/src/index.ts +12 -1
- package/src/pi-message.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pontia/pi-client-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Pi extension that connects coding-agent sessions to Pontia.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"pi-package",
|
|
30
30
|
"pontia-client-plugin"
|
|
31
31
|
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
35
|
+
},
|
|
32
36
|
"pi": {
|
|
33
37
|
"extensions": [
|
|
34
38
|
"./src/index.ts"
|
|
@@ -42,9 +46,5 @@
|
|
|
42
46
|
"@types/node": "^22.15.3",
|
|
43
47
|
"typescript": "^5.8.3",
|
|
44
48
|
"vitest": "^3.1.2"
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"test": "vitest run",
|
|
48
|
-
"typecheck": "tsc --noEmit"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|
package/src/discovery.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { isAbsolute, join, parse, sep } from "node:path";
|
|
3
3
|
import type { EnvLike } from "./context.js";
|
|
4
4
|
|
|
5
|
+
const DEFAULT_BIND_ADDR = "127.0.0.1:8080";
|
|
6
|
+
|
|
5
7
|
export interface PontiaConnection {
|
|
6
8
|
baseUrl: string;
|
|
7
9
|
internalEventUrl: string;
|
|
@@ -72,9 +74,9 @@ export async function resolvePontiaConnection(options: PontiaDiscoveryOptions =
|
|
|
72
74
|
return undefined;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
const
|
|
76
|
-
if (!
|
|
77
|
-
const baseUrl = baseUrlFromBindAddr(
|
|
77
|
+
const configuredBindAddr = parseTomlString(raw, "bind_addr");
|
|
78
|
+
if (!configuredBindAddr && /^\s*bind_addr\s*=/m.test(raw)) return undefined;
|
|
79
|
+
const baseUrl = baseUrlFromBindAddr(configuredBindAddr ?? DEFAULT_BIND_ADDR);
|
|
78
80
|
if (!baseUrl) return undefined;
|
|
79
81
|
return connectionFromBaseUrl(baseUrl, parseTomlString(raw, "external_api_token"));
|
|
80
82
|
}
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,12 @@ function reportAccepted(result: EventReportResult | boolean): boolean {
|
|
|
20
20
|
return typeof result === "boolean" ? result : result.accepted;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function isPersistentTuiContext(ctx: unknown): boolean {
|
|
24
|
+
if (!ctx || typeof ctx !== "object") return false;
|
|
25
|
+
if ((ctx as Record<string, unknown>).mode !== "tui") return false;
|
|
26
|
+
return piSessionDetailsFromHookContext(ctx).clientSessionFile !== undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
export interface PontiaPiExtensionDependencies {
|
|
24
30
|
env?: EnvLike;
|
|
25
31
|
loadContext?: (env: EnvLike, sessionContext?: SessionContext) => Promise<LoadTurnContextResult>;
|
|
@@ -144,6 +150,7 @@ export function createPontiaPiExtension(pi: ExtensionAPI, dependencies: PontiaPi
|
|
|
144
150
|
pi.registerCommand("pontia-edit", {
|
|
145
151
|
description: "Replay a Pontia Inbox message from a historical Pi entry",
|
|
146
152
|
handler: async (args, ctx) => {
|
|
153
|
+
if (!isPersistentTuiContext(ctx)) return;
|
|
147
154
|
const inboxMessageId = args.trim();
|
|
148
155
|
const logFile = currentHookLogFile();
|
|
149
156
|
if (!/^msg_[^\s]+$/.test(inboxMessageId)) {
|
|
@@ -308,6 +315,10 @@ export function createPontiaPiExtension(pi: ExtensionAPI, dependencies: PontiaPi
|
|
|
308
315
|
const reason = (event as unknown as Record<string, unknown> | undefined)?.reason;
|
|
309
316
|
if (readyReported && reason !== "fork" && reason !== "resume") return;
|
|
310
317
|
if (reason !== "startup" && reason !== "new" && reason !== "resume" && reason !== "fork") return;
|
|
318
|
+
if (!isPersistentTuiContext(ctx)) {
|
|
319
|
+
reportingDisabled = true;
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
311
322
|
|
|
312
323
|
try {
|
|
313
324
|
const sessionDetails = piSessionDetailsFromHookContext(ctx);
|
|
@@ -552,7 +563,7 @@ export function createPontiaPiExtension(pi: ExtensionAPI, dependencies: PontiaPi
|
|
|
552
563
|
|
|
553
564
|
const state = activeTurn;
|
|
554
565
|
const terminalLeafId = leafIdFromHookContext(ctx);
|
|
555
|
-
if (agentEndWasInterrupted(event)) {
|
|
566
|
+
if (agentEndWasInterrupted(event, ctx?.signal)) {
|
|
556
567
|
await state.reporter.report(state.context, buildTurnInterruptedEvent(state.context, terminalLeafId));
|
|
557
568
|
await reportFinalMessageRefresh(state);
|
|
558
569
|
return;
|
package/src/pi-message.ts
CHANGED
|
@@ -65,8 +65,8 @@ function lastAssistantMessageFromAgentEnd(event: PiAgentEndEventLike): Record<st
|
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export function agentEndWasInterrupted(event: PiAgentEndEventLike): boolean {
|
|
69
|
-
return lastAssistantMessageFromAgentEnd(event)?.stopReason === "aborted";
|
|
68
|
+
export function agentEndWasInterrupted(event: PiAgentEndEventLike, signal?: AbortSignal): boolean {
|
|
69
|
+
return signal?.aborted === true || lastAssistantMessageFromAgentEnd(event)?.stopReason === "aborted";
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export function errorMessageFromAgentEnd(event: PiAgentEndEventLike): string | undefined {
|