pi-quiver 6.13.2 → 6.14.1

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.
@@ -8,7 +8,7 @@
8
8
  * convention as the other opt-in extensions).
9
9
  */
10
10
 
11
- import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
11
+ import { getAgentDir, type ExtensionAPI, type ExtensionContext, type Theme } from "@earendil-works/pi-coding-agent";
12
12
  import { Text } from "@earendil-works/pi-tui";
13
13
  import { Type } from "@sinclair/typebox";
14
14
  import { readFileSync } from "node:fs";
@@ -216,7 +216,7 @@ export default function slackExtension(pi: ExtensionAPI) {
216
216
  let registered = false;
217
217
 
218
218
  pi.on("session_start", async (_event, ctx) => {
219
- const cfg = resolveSlackConfig(ctx.cwd, process.env, (m) => ctx.hasUI ? ctx.ui.notify(m, "warning") : console.warn(m));
219
+ const cfg = resolveSlackConfig(ctx.cwd, process.env, (m) => ctx.hasUI ? ctx.ui.notify(m, "warning") : console.warn(m), getAgentDir());
220
220
  if (cfg.enabled !== true) return;
221
221
  if (registered) return;
222
222
  registered = true;
@@ -1,105 +1,13 @@
1
- /**
2
- * Shared settings-resolution for pi-quiver extensions that read opt-in
3
- * config from pi's `settings.json`.
4
- *
5
- * Layers, lowest precedence first:
6
- * 1. global - `<getAgentDir()>/settings.json`
7
- * 2. project - `<cwd>/.pi/settings.json`
8
- *
9
- * The global path comes from pi's own `getAgentDir()`, which honours the
10
- * `PI_CODING_AGENT_DIR` env override (else `~/.pi/agent`). That keeps it
11
- * correct when these extensions are consumed as a git-tag-pinned package -
12
- * unlike deriving the path from `import.meta.url`, which only held while an
13
- * extension lived inside `<agentHome>/extensions/`.
14
- *
15
- * Within each layer, a nested `quiver.<key>` takes precedence over the flat
16
- * `<key>` by presence alone (even when malformed); the flat top-level
17
- * fallback is frozen to the pre-quiver LEGACY_FLAT_KEYS and never extended.
18
- */
19
-
20
- import { readFileSync } from "node:fs";
21
- import { join } from "node:path";
1
+ /** Pi-aware settings paths and config resolution for extensions. */
22
2
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
23
- import { DOC_TO_MD_OPTIONS } from "./doc-to-md-options.ts";
3
+ import { resolveConfigFrom, settingsPathsFor } from "./settings-core.ts";
24
4
 
25
- export function readSettings(path: string): Record<string, unknown> | undefined {
26
- try {
27
- return JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>;
28
- } catch {
29
- return undefined;
30
- }
31
- }
5
+ export { readSettings, QUIVER_CONFIG_KEYS } from "./settings-core.ts";
32
6
 
33
7
  export function settingsPaths(cwd: string): string[] {
34
- return [join(getAgentDir(), "settings.json"), join(cwd, ".pi", "settings.json")];
35
- }
36
-
37
- /** Flat top-level fallback is frozen to these pre-quiver keys; never extend. */
38
- const LEGACY_FLAT_KEYS = new Set(["fastMode", "sessionAutoName", "swordHeader", "providerStallWatchdog"]);
39
-
40
- /**
41
- * Lint allowlist: every pi-quiver settings block and its fields. A key read
42
- * by an extension but missing here is reported as unknown - register new
43
- * keys here first.
44
- */
45
- export const QUIVER_CONFIG_KEYS: Record<string, readonly string[]> = {
46
- fastMode: ["enabled"],
47
- sessionAutoName: ["enabled", "ghosttyTab", "herdrTab", "rules", "deny", "revisitFirstTurn", "revisitEveryTurns"],
48
- swordHeader: ["enabled"],
49
- providerStallWatchdog: ["enabled", "firstEventMs", "warningMs", "recoveryMs", "maxStallRetries", "models"],
50
- slack: ["enabled", "cachePath", "policyPath", "userTokenEnv", "userTokenCommand", "userTokenCommandTimeoutSeconds", "botTokenEnv", "uploadThresholdChars"],
51
- docToMd: DOC_TO_MD_OPTIONS.filter((o) => o.settable).map((o) => o.key),
52
- };
53
-
54
- const isPlainObject = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === "object" && !Array.isArray(v);
55
-
56
- const emittedWarnings = new Set<string>();
57
-
58
- function emitWarning(warn: ((message: string) => void) | undefined, message: string): void {
59
- if (!warn || emittedWarnings.has(message)) return;
60
- emittedWarnings.add(message);
61
- warn(message);
62
- }
63
-
64
- /** Structural findings for one parsed settings file: flat legacy use, non-object quiver, unknown blocks, unknown fields. */
65
- function lintSettings(settings: Record<string, unknown>): string[] {
66
- const lines: string[] = [];
67
- for (const key of Object.keys(settings)) if (LEGACY_FLAT_KEYS.has(key)) lines.push(`"${key}" at top level - move under "quiver"`);
68
- const root = settings.quiver;
69
- if (root === undefined) return lines;
70
- if (!isPlainObject(root)) return [...lines, `"quiver" is not an object - ignored`];
71
- const fieldLines: string[] = [];
72
- for (const [block, value] of Object.entries(root)) {
73
- if (!Object.hasOwn(QUIVER_CONFIG_KEYS, block)) {
74
- lines.push(`"quiver.${block}" - unknown block; accepted: ${Object.keys(QUIVER_CONFIG_KEYS).join(", ")}`);
75
- continue;
76
- }
77
- if (!isPlainObject(value)) continue;
78
- const fields = QUIVER_CONFIG_KEYS[block];
79
- for (const field of Object.keys(value)) if (!fields.includes(field)) fieldLines.push(`"quiver.${block}.${field}" - unknown; accepted: ${fields.join(", ")}`);
80
- }
81
- return [...lines, ...fieldLines];
82
- }
83
-
84
- function formatLint(findings: Array<[path: string, lines: string[]]>): string {
85
- const tail = "unknown or misplaced keys - unknown ones fall back to defaults";
86
- if (findings.length === 1) {
87
- const [path, lines] = findings[0];
88
- return [`pi-quiver settings (${path}): ${tail}`, ...lines.map((l) => ` ${l}`)].join("\n");
89
- }
90
- return [`pi-quiver settings: ${tail}`, ...findings.flatMap(([path, lines]) => [` ${path}`, ...lines.map((l) => ` ${l}`)])].join("\n");
8
+ return settingsPathsFor(getAgentDir(), cwd);
91
9
  }
92
10
 
93
- /**
94
- * Resolve a single extension config key across the settings layers.
95
- * `quiver.<key>` wins over flat `<key>` within a layer by presence (even
96
- * when malformed); flat fallback exists only for LEGACY_FLAT_KEYS. `coerce`
97
- * validates the layer's candidate into a partial patch (or `undefined` to
98
- * skip); patches merge over `defaults` in layer order (project wins).
99
- * `warn` receives one sentence per malformed key plus one condensed
100
- * structural lint (flat legacy use, unknown blocks, unknown fields) - each
101
- * distinct message once per process.
102
- */
103
11
  export function resolveConfig<T extends object>(
104
12
  cwd: string,
105
13
  key: string,
@@ -107,22 +15,5 @@ export function resolveConfig<T extends object>(
107
15
  coerce: (raw: unknown, warn?: (message: string) => void) => Partial<T> | undefined,
108
16
  warn?: (message: string) => void,
109
17
  ): T {
110
- const cfg: T = { ...defaults };
111
- const findings: Array<[string, string[]]> = [];
112
- for (const path of settingsPaths(cwd)) {
113
- const settings = readSettings(path);
114
- if (!settings) continue;
115
- const lines = lintSettings(settings);
116
- if (lines.length > 0) findings.push([path, lines]);
117
- const nested = isPlainObject(settings.quiver) ? settings.quiver : undefined;
118
- const hasNested = nested !== undefined && Object.hasOwn(nested, key);
119
- const hasFlat = Object.hasOwn(settings, key);
120
- if (!hasNested && !(hasFlat && LEGACY_FLAT_KEYS.has(key))) continue;
121
- const candidate = hasNested ? nested![key] : settings[key];
122
- const patch = coerce(candidate, (message) => emitWarning(warn, message));
123
- if (patch) Object.assign(cfg, patch);
124
- else emitWarning(warn, `pi-quiver: "${key}" in ${path} has an unrecognized value; ignored.`);
125
- }
126
- if (findings.length > 0) emitWarning(warn, formatLint(findings));
127
- return cfg;
18
+ return resolveConfigFrom(settingsPaths(cwd), key, defaults, coerce, warn);
128
19
  }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Shared settings-resolution for pi-quiver extensions that read opt-in
3
+ * config from pi's `settings.json`.
4
+ *
5
+ * Layers, lowest precedence first:
6
+ * 1. global - `<agentDir>/settings.json`
7
+ * 2. project - `<cwd>/.pi/settings.json`
8
+ *
9
+ * Within each layer, a nested `quiver.<key>` takes precedence over the flat
10
+ * `<key>` by presence alone (even when malformed); the flat top-level
11
+ * fallback is frozen to the pre-quiver LEGACY_FLAT_KEYS and never extended.
12
+ */
13
+
14
+ import { readFileSync } from "node:fs";
15
+ import { join } from "node:path";
16
+ import { DOC_TO_MD_OPTIONS } from "./doc-to-md-options.ts";
17
+
18
+ export function readSettings(path: string): Record<string, unknown> | undefined {
19
+ try {
20
+ return JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>;
21
+ } catch {
22
+ return undefined;
23
+ }
24
+ }
25
+
26
+ export function settingsPathsFor(agentDir: string, cwd: string): string[] {
27
+ return [join(agentDir, "settings.json"), join(cwd, ".pi", "settings.json")];
28
+ }
29
+
30
+ /** Flat top-level fallback is frozen to these pre-quiver keys; never extend. */
31
+ const LEGACY_FLAT_KEYS = new Set(["fastMode", "sessionAutoName", "swordHeader", "providerStallWatchdog"]);
32
+
33
+ /**
34
+ * Lint allowlist: every pi-quiver settings block and its fields. A key read
35
+ * by an extension but missing here is reported as unknown - register new
36
+ * keys here first.
37
+ */
38
+ export const QUIVER_CONFIG_KEYS: Record<string, readonly string[]> = {
39
+ fastMode: ["enabled"],
40
+ sessionAutoName: ["enabled", "ghosttyTab", "herdrTab", "rules", "deny", "revisitFirstTurn", "revisitEveryTurns"],
41
+ swordHeader: ["enabled"],
42
+ providerStallWatchdog: ["enabled", "firstEventMs", "warningMs", "recoveryMs", "maxStallRetries", "models"],
43
+ slack: ["enabled", "cachePath", "policyPath", "userTokenEnv", "userTokenCommand", "userTokenCommandTimeoutSeconds", "botTokenEnv", "uploadThresholdChars"],
44
+ docToMd: DOC_TO_MD_OPTIONS.filter((o) => o.settable).map((o) => o.key),
45
+ };
46
+
47
+ const isPlainObject = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === "object" && !Array.isArray(v);
48
+
49
+ const emittedWarnings = new Set<string>();
50
+
51
+ function emitWarning(warn: ((message: string) => void) | undefined, message: string): void {
52
+ if (!warn || emittedWarnings.has(message)) return;
53
+ emittedWarnings.add(message);
54
+ warn(message);
55
+ }
56
+
57
+ /** Structural findings for one parsed settings file: flat legacy use, non-object quiver, unknown blocks, unknown fields. */
58
+ function lintSettings(settings: Record<string, unknown>): string[] {
59
+ const lines: string[] = [];
60
+ for (const key of Object.keys(settings)) if (LEGACY_FLAT_KEYS.has(key)) lines.push(`"${key}" at top level - move under "quiver"`);
61
+ const root = settings.quiver;
62
+ if (root === undefined) return lines;
63
+ if (!isPlainObject(root)) return [...lines, `"quiver" is not an object - ignored`];
64
+ const fieldLines: string[] = [];
65
+ for (const [block, value] of Object.entries(root)) {
66
+ if (!Object.hasOwn(QUIVER_CONFIG_KEYS, block)) {
67
+ lines.push(`"quiver.${block}" - unknown block; accepted: ${Object.keys(QUIVER_CONFIG_KEYS).join(", ")}`);
68
+ continue;
69
+ }
70
+ if (!isPlainObject(value)) continue;
71
+ const fields = QUIVER_CONFIG_KEYS[block];
72
+ for (const field of Object.keys(value)) if (!fields.includes(field)) fieldLines.push(`"quiver.${block}.${field}" - unknown; accepted: ${fields.join(", ")}`);
73
+ }
74
+ return [...lines, ...fieldLines];
75
+ }
76
+
77
+ function formatLint(findings: Array<[path: string, lines: string[]]>): string {
78
+ const tail = "unknown or misplaced keys - unknown ones fall back to defaults";
79
+ if (findings.length === 1) {
80
+ const [path, lines] = findings[0];
81
+ return [`pi-quiver settings (${path}): ${tail}`, ...lines.map((l) => ` ${l}`)].join("\n");
82
+ }
83
+ return [`pi-quiver settings: ${tail}`, ...findings.flatMap(([path, lines]) => [` ${path}`, ...lines.map((l) => ` ${l}`)])].join("\n");
84
+ }
85
+
86
+ /**
87
+ * Resolve a single extension config key across the settings layers.
88
+ * `quiver.<key>` wins over flat `<key>` within a layer by presence (even
89
+ * when malformed); flat fallback exists only for LEGACY_FLAT_KEYS. `coerce`
90
+ * validates the layer's candidate into a partial patch (or `undefined` to
91
+ * skip); patches merge over `defaults` in layer order (project wins).
92
+ * `warn` receives one sentence per malformed key plus one condensed
93
+ * structural lint (flat legacy use, unknown blocks, unknown fields) - each
94
+ * distinct message once per process.
95
+ */
96
+ export function resolveConfigFrom<T extends object>(
97
+ paths: string[],
98
+ key: string,
99
+ defaults: T,
100
+ coerce: (raw: unknown, warn?: (message: string) => void) => Partial<T> | undefined,
101
+ warn?: (message: string) => void,
102
+ ): T {
103
+ const cfg: T = { ...defaults };
104
+ const findings: Array<[string, string[]]> = [];
105
+ for (const path of paths) {
106
+ const settings = readSettings(path);
107
+ if (!settings) continue;
108
+ const lines = lintSettings(settings);
109
+ if (lines.length > 0) findings.push([path, lines]);
110
+ const nested = isPlainObject(settings.quiver) ? settings.quiver : undefined;
111
+ const hasNested = nested !== undefined && Object.hasOwn(nested, key);
112
+ const hasFlat = Object.hasOwn(settings, key);
113
+ if (!hasNested && !(hasFlat && LEGACY_FLAT_KEYS.has(key))) continue;
114
+ const candidate = hasNested ? nested![key] : settings[key];
115
+ const patch = coerce(candidate, (message) => emitWarning(warn, message));
116
+ if (patch) Object.assign(cfg, patch);
117
+ else emitWarning(warn, `pi-quiver: "${key}" in ${path} has an unrecognized value; ignored.`);
118
+ }
119
+ if (findings.length > 0) emitWarning(warn, formatLint(findings));
120
+ return cfg;
121
+ }
package/lib/slack-core.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * parameters, so callers (extensions/slack.ts, tests) control everything
5
5
  * this module reads.
6
6
  *
7
- * Config ladder: `resolveConfig` (shared, `lib/extension-config.ts`) for the
7
+ * Config ladder: `resolveConfigFrom` (shared, `lib/settings-core.ts`) for the
8
8
  * settings.json layers (pi-home, repo `.pi/settings.json`), then a
9
9
  * slack-local `PI_QUIVER_SLACK_*` env-var overlay applied on top.
10
10
  */
@@ -14,7 +14,7 @@ import { createHash } from "node:crypto";
14
14
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
15
15
  import { tmpdir } from "node:os";
16
16
  import { dirname, join } from "node:path";
17
- import { resolveConfig } from "./extension-config.ts";
17
+ import { resolveConfigFrom, settingsPathsFor } from "./settings-core.ts";
18
18
 
19
19
  export interface SlackConfig {
20
20
  enabled: boolean;
@@ -146,8 +146,8 @@ export function applyEnvOverrides(
146
146
  return result;
147
147
  }
148
148
 
149
- export function resolveSlackConfig(cwd: string, env: Record<string, string | undefined>, warn?: (message: string) => void): SlackConfig {
150
- return applyEnvOverrides(resolveConfig(cwd, "slack", DEFAULT_SLACK_CONFIG, coerce, warn), env, warn);
149
+ export function resolveSlackConfig(cwd: string, env: Record<string, string | undefined>, warn: ((message: string) => void) | undefined, agentDir: string): SlackConfig {
150
+ return applyEnvOverrides(resolveConfigFrom(settingsPathsFor(agentDir, cwd), "slack", DEFAULT_SLACK_CONFIG, coerce, warn), env, warn);
151
151
  }
152
152
 
153
153
  export function discoverRepoRoot(cwd: string): string {
@@ -306,7 +306,7 @@ export type ApiCall = (
306
306
 
307
307
  export type UploadBytes = (url: string, bytes: Uint8Array, opts?: { signal?: AbortSignal }) => Promise<void>;
308
308
 
309
- const JSON_METHODS = new Set(["chat.postMessage", "chat.update"]);
309
+ const JSON_METHODS = new Set(["chat.postMessage", "chat.update", "canvases.edit"]);
310
310
 
311
311
  export const ERROR_HINTS: Record<string, string> = {
312
312
  channel_not_found: "check the name or run slack_cache_refresh",
@@ -757,16 +757,15 @@ export interface MutationResult {
757
757
  detailTs?: string;
758
758
  }
759
759
 
760
- // Deliberately separate from SlackConfig.uploadThresholdChars (doc/specs/2026-08-29-gh-7-slack-extension.md
761
- // Announce protocol): this is a fixed hard error for plain text/headline; uploadThresholdChars is a
762
- // configurable cutoff that only gates thread_body -> upload in the announce protocol.
760
+ // Headline discipline is separate from Slack's hard ceiling and the configurable upload threshold.
763
761
  export const MAX_TEXT_LENGTH = 4_000;
762
+ export const SLACK_TEXT_HARD_LIMIT = 40_000;
764
763
 
765
- function assertTextWithinLimit(text: string | undefined): void {
766
- if (text !== undefined && text.length > MAX_TEXT_LENGTH) {
764
+ export function assertTextWithinLimit(text: string | undefined, limit = MAX_TEXT_LENGTH): void {
765
+ if (text !== undefined && text.length > limit) {
767
766
  throw new SlackError(
768
767
  "text_too_long",
769
- `text is ${text.length} UTF-16 code units, over the ${MAX_TEXT_LENGTH} limit; use thread_body for announcements or slack_upload for documents.`,
768
+ `text is ${text.length} UTF-16 code units, over the ${limit} limit; use thread_body for announcements or slack_upload for documents.`,
770
769
  );
771
770
  }
772
771
  }
@@ -798,9 +797,10 @@ export async function postPlain(
798
797
  unfurl_links?: boolean;
799
798
  unfurl_media?: boolean;
800
799
  },
801
- deps: CoreDeps,
800
+ deps: CoreDeps & { identity?: "user" | "bot" },
802
801
  ): Promise<MutationResult> {
803
- if (!(args.blocks && args.thread_ts !== undefined)) assertTextWithinLimit(args.text);
802
+ if (deps.identity === "bot") assertTextWithinLimit(args.text, SLACK_TEXT_HARD_LIMIT);
803
+ else if (!(args.blocks && args.thread_ts !== undefined)) assertTextWithinLimit(args.text);
804
804
 
805
805
  const params: Record<string, unknown> = { channel: args.channel };
806
806
  if (args.text !== undefined) params.text = args.text;
@@ -958,7 +958,7 @@ export function persistDetail(body: string, format: "md" | "json" = "md"): strin
958
958
  return path;
959
959
  }
960
960
 
961
- function assertHeadline(text: string): void {
961
+ export function assertHeadline(text: string): void {
962
962
  if (text.length === 0) {
963
963
  throw new SlackError("invalid_headline", "text is empty; announce requires a non-empty single-line headline.");
964
964
  }
@@ -1194,8 +1194,10 @@ export async function postMessage(
1194
1194
  unfurl_links?: boolean;
1195
1195
  unfurl_media?: boolean;
1196
1196
  },
1197
- deps: CoreDeps & { uploadBytes: UploadBytes; thresholdChars: number; persist?: (body: string, format?: "md" | "json") => string },
1197
+ deps: CoreDeps & { identity?: "user" | "bot"; uploadBytes: UploadBytes; thresholdChars: number; persist?: (body: string, format?: "md" | "json") => string },
1198
1198
  ): Promise<MutationResult | AnnounceResult> {
1199
+ if (deps.identity === "bot" && args.thread_body === undefined) return postPlain(args, deps);
1200
+
1199
1201
  if (args.thread_body !== undefined && args.thread_ts === undefined) {
1200
1202
  return announce(
1201
1203
  { channel: args.channel, text: args.text ?? "", thread_body: args.thread_body, blocks: args.blocks },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-quiver",
3
- "version": "6.13.2",
3
+ "version": "6.14.1",
4
4
  "description": "Personal pack of Pi coding-agent extensions: context-safe fetch, doc_to_md PDF/DOCX/PPTX-to-Markdown conversion, session naming, a themed ASCII startup header, Opus 4.8 fast mode, and a provider-stall watchdog.",
5
5
  "author": "Jacek Juraszek",
6
6
  "license": "MIT",