pi-canary 1.0.2 → 1.1.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.
@@ -15,6 +15,9 @@
15
15
  */
16
16
 
17
17
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
18
+ import { readFileSync } from "node:fs";
19
+ import { dirname, join } from "node:path";
20
+ import { fileURLToPath } from "node:url";
18
21
 
19
22
  // Loaded from sibling JSON at startup; /set overrides for the current session only
20
23
  const cfg = (() => {
@@ -25,8 +28,8 @@ const cfg = (() => {
25
28
  FAIL_COMPACT: 0,
26
29
  };
27
30
  try {
28
- const url = new URL("canary.json", import.meta.url);
29
- return { ...defaults, ...JSON.parse((globalThis as any).Deno.readTextFileSync(url)) };
31
+ const extDir = dirname(fileURLToPath(import.meta.url));
32
+ return { ...defaults, ...JSON.parse(readFileSync(join(extDir, "canary.json"), "utf-8")) };
30
33
  } catch {
31
34
  return defaults;
32
35
  }
@@ -89,6 +92,12 @@ export default function (pi: ExtensionAPI) {
89
92
  let verifyResponseTimestamp: number | null = null;
90
93
 
91
94
  pi.on("before_agent_start", (_event, _ctx) => {
95
+ // COUNT=0 disables the canary check entirely
96
+ if (cfg.COUNT === 0) {
97
+ phase = "idle";
98
+ currentTokens = null;
99
+ return;
100
+ }
92
101
  if (cfg.VARIANT === "fixed") {
93
102
  if (!fixedTokens || fixedTokens.length !== cfg.COUNT) {
94
103
  fixedTokens = Array.from({ length: cfg.COUNT }, generateToken);
@@ -270,7 +279,7 @@ export default function (pi: ExtensionAPI) {
270
279
  if (eq > 0 && val !== "") {
271
280
  if (key === "COUNT") {
272
281
  const n = parseInt(val, 10);
273
- if (n > 0) { cfg.COUNT = n; fixedTokens = null; results.push(`COUNT=${cfg.COUNT}`); }
282
+ if (n >= 0) { cfg.COUNT = n; fixedTokens = null; results.push(`COUNT=${cfg.COUNT}`); }
274
283
  else results.push(`invalid COUNT: ${val}`);
275
284
  } else if (key === "POSITION") {
276
285
  if (val === "start" || val === "equidistant" || val === "end") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-canary",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Pi extension: silently verifies agent context awareness every turn using hidden canary tokens. KV-cache friendly.",
5
5
  "keywords": ["pi-package", "pi", "pi-coding-agent", "extension", "context-awareness", "canary", "safety", "verification", "local-llm"],
6
6
  "license": "MIT",