@codemem/pi-extension 0.46.0-rc.3 → 0.46.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/README.md +4 -3
- package/dist/client.d.ts +20 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +669 -453
- package/dist/index.js.map +1 -1
- package/dist/inject.d.ts +44 -0
- package/dist/inject.d.ts.map +1 -0
- package/dist/plugin-log.d.ts +11 -0
- package/dist/plugin-log.d.ts.map +1 -0
- package/dist/viewer.d.ts +32 -2
- package/dist/viewer.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/inject.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache-stable memory injection for pi's `context` event.
|
|
3
|
+
*
|
|
4
|
+
* Replays the exact framed bytes already decided for older user messages and
|
|
5
|
+
* fetches at most one new pack for the latest undecided user message, appending
|
|
6
|
+
* the block to that message only. Mutates the request copy in place and never
|
|
7
|
+
* returns anything — a context handler that returns { messages } drops system
|
|
8
|
+
* messages on Pi 0.84 and collapses them mid-conversation on Pi 0.87.
|
|
9
|
+
*
|
|
10
|
+
* Decisions live in memory for this extension instance only. A restart starts
|
|
11
|
+
* with an empty cache and is not cache-safe; older messages replay again only
|
|
12
|
+
* after new decisions build up.
|
|
13
|
+
*/
|
|
14
|
+
import type { PiCodememClient } from "./client.js";
|
|
15
|
+
import type { PiExtensionConfig } from "./config.js";
|
|
16
|
+
/** Structural view of a pi AgentMessage (pi-agent-core types are not a dependency). */
|
|
17
|
+
export type PiContextMessage = {
|
|
18
|
+
role?: unknown;
|
|
19
|
+
content?: unknown;
|
|
20
|
+
timestamp?: unknown;
|
|
21
|
+
};
|
|
22
|
+
export type PiInjector = {
|
|
23
|
+
/** Mutates the given request-copy messages in place; returns nothing. */
|
|
24
|
+
inject(messages: PiContextMessage[], signal?: AbortSignal): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* One-shot replay skip. Arm only after session_compact with willRetry.
|
|
27
|
+
* The next inject replays and does not fetch.
|
|
28
|
+
*/
|
|
29
|
+
noteCompaction(): void;
|
|
30
|
+
/** Drop a replay skip that will not be the immediate resume. */
|
|
31
|
+
clearCompaction(): void;
|
|
32
|
+
/** Re-key decision identity on session_start. */
|
|
33
|
+
rekey(sessionId: string): void;
|
|
34
|
+
};
|
|
35
|
+
export declare function createPiInjector(options: {
|
|
36
|
+
client: PiCodememClient;
|
|
37
|
+
config: PiExtensionConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Timestamp when the message has one. When it does not, a fresh id that is
|
|
40
|
+
* not the ingest counter, so a missing timestamp is not cached.
|
|
41
|
+
*/
|
|
42
|
+
discriminator: (message: PiContextMessage) => string | number;
|
|
43
|
+
}): PiInjector;
|
|
44
|
+
//# sourceMappingURL=inject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AASrD,uFAAuF;AACvF,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACxB,yEAAyE;IACzE,MAAM,CAAC,QAAQ,EAAE,gBAAgB,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E;;;OAGG;IACH,cAAc,IAAI,IAAI,CAAC;IACvB,gEAAgE;IAChE,eAAe,IAAI,IAAI,CAAC;IACxB,iDAAiD;IACjD,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAgOF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACzC,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,iBAAiB,CAAC;IAC1B;;;OAGG;IACH,aAAa,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,MAAM,GAAG,MAAM,CAAC;CAC9D,GAAG,UAAU,CAiEb"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function pluginLogPath(): string;
|
|
2
|
+
/** `inject.pack.ok source=pi` line previously written only by `pi-hook-inject`. */
|
|
3
|
+
export declare function logPiInjectPack(fields: {
|
|
4
|
+
origin: "local" | "viewer";
|
|
5
|
+
items: number;
|
|
6
|
+
packTokens: number;
|
|
7
|
+
queryLen: number;
|
|
8
|
+
empty: boolean;
|
|
9
|
+
project: string | null;
|
|
10
|
+
}): void;
|
|
11
|
+
//# sourceMappingURL=plugin-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-log.d.ts","sourceRoot":"","sources":["../src/plugin-log.ts"],"names":[],"mappings":"AAkBA,wBAAgB,aAAa,IAAI,MAAM,CAKtC;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACvC,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,GAAG,IAAI,CAkBP"}
|
package/dist/viewer.d.ts
CHANGED
|
@@ -53,8 +53,38 @@ export declare function viewerRequestTarget(cwd: string, env?: NodeJS.ProcessEnv
|
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
55
|
export declare function isViewerTargetConflict(status: number, body: unknown): boolean;
|
|
56
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
57
|
+
/** Renderer-owned pack item spans (core PackResponse.rendered_items). */
|
|
58
|
+
export type RenderedPackItem = {
|
|
59
|
+
id: number;
|
|
60
|
+
fingerprint: string;
|
|
61
|
+
spans: Array<{
|
|
62
|
+
start: number;
|
|
63
|
+
end: number;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
/** Successful proven pack body; null when unproven, failing, or non-JSON. */
|
|
67
|
+
export type ProvenPack = {
|
|
68
|
+
packText: string;
|
|
69
|
+
/** Present only when the response carried renderer span data. */
|
|
70
|
+
renderedItems?: RenderedPackItem[];
|
|
71
|
+
/** metrics.total_items from the same response. */
|
|
72
|
+
itemCount?: number;
|
|
73
|
+
/** metrics.pack_tokens from the same response, when present. */
|
|
74
|
+
packTokens?: number;
|
|
75
|
+
};
|
|
56
76
|
export declare function profileMatchesViewerTarget(profile: unknown, dbPath: string, identity: unknown): boolean;
|
|
57
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* PackResponse contract check. A valid zero-item pack has a string `pack_text`
|
|
79
|
+
* and numeric `metrics.total_items` (0 is success). `{}`, a non-string `pack_text`,
|
|
80
|
+
* a missing item count, a non-array `rendered_items`, or an `error` field is not a pack.
|
|
81
|
+
*/
|
|
82
|
+
export declare function parseProvenPack(body: unknown): ProvenPack | null;
|
|
83
|
+
/**
|
|
84
|
+
* GET /api/prompt-pack-profile, then POST /api/pack with db_path + identity_target.
|
|
85
|
+
* Returns a contract-valid pack, including a zero-item pack; null means unproven,
|
|
86
|
+
* failed, or a body that is not a PackResponse, and the caller may fall back.
|
|
87
|
+
*/
|
|
58
88
|
export declare function proveAndPostPack(config: PiExtensionConfig, args: {
|
|
59
89
|
context: string;
|
|
60
90
|
cwd: string;
|
|
@@ -62,7 +92,7 @@ export declare function proveAndPostPack(config: PiExtensionConfig, args: {
|
|
|
62
92
|
signal: AbortSignal;
|
|
63
93
|
limit?: number;
|
|
64
94
|
tokenBudget?: number;
|
|
65
|
-
}): Promise<
|
|
95
|
+
}): Promise<ProvenPack | null>;
|
|
66
96
|
/** Probe viewer with a cheap GET. Returns true when reachable. */
|
|
67
97
|
export declare function probeViewer(config: PiExtensionConfig, signal?: AbortSignal): Promise<boolean>;
|
|
68
98
|
/**
|
package/dist/viewer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewer.d.ts","sourceRoot":"","sources":["../src/viewer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAcrD,MAAM,MAAM,aAAa,GAAG;IAC3B,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;IACrB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,wBAAgB,mBAAmB,IAAI,aAAa,CAOnD;AAMD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAEpE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAE5D;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAEzD;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAEtE;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGtE;AAeD,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAI7F;AAED,kFAAkF;AAClF,wBAAgB,yBAAyB,CACxC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,GAAG,GAAE,MAAsB;IAQ1B,SAAS;IACT,gBAAgB;IAChB,QAAQ;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
|
|
3
|
-
"version": "0.46.0
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "CodeMem extension for the pi coding agent — ingest, injection, and native memory tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"typebox": "*"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@codemem/core": "^0.46.0
|
|
25
|
+
"@codemem/core": "^0.46.0",
|
|
26
26
|
"@earendil-works/pi-coding-agent": "^0.84.1",
|
|
27
27
|
"@types/node": "^24.12.4",
|
|
28
28
|
"typebox": "^1.3.7",
|