pi-adaptive-thinking 0.2.2 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-adaptive-thinking",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "description": "Pi extension for adaptive reasoning-effort control",
6
6
  "keywords": [
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "files": [
25
25
  "src",
26
+ "skills",
26
27
  "README.md",
27
28
  "LICENSE"
28
29
  ],
@@ -42,6 +43,9 @@
42
43
  "pi": {
43
44
  "extensions": [
44
45
  "./src/index.ts"
46
+ ],
47
+ "skills": [
48
+ "./skills"
45
49
  ]
46
50
  },
47
51
  "scripts": {
@@ -0,0 +1,13 @@
1
+ ---
2
+ name: pi-adaptive-thinking
3
+ description: Configure or diagnose pi-adaptive-thinking when thinking-level tools are missing or session levels behave unexpectedly.
4
+ license: MIT
5
+ ---
6
+
7
+ # Pi Adaptive Thinking
8
+
9
+ 1. Read [`../../README.md`](../../README.md)'s Configuration and Behavior sections. Stop when you can name the expected tool names, precedence rule, and reset behavior.
10
+ 2. Inspect extension-load errors and both documented configuration layers. Identify the effective source or exact parse failure.
11
+ 3. Verify the registered names, then call the status tool once. Classify the symptom as configuration, unsupported model level, baseline state, no-op, consecutive setter rejection, or expected reset.
12
+ 4. For a requested change, edit the intended layer, keep `guidance` static, validate JSON, and reload Pi.
13
+ 5. Finish when the effective source and registered names are known and the status evidence matches the expected behavior after reload.
@@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { open, rm, stat } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { StringEnum } from "@earendil-works/pi-ai";
5
6
  import type {
6
7
  AgentEndEvent,
7
8
  AgentToolResult,
@@ -12,10 +13,11 @@ import type {
12
13
  ToolCallEventResult,
13
14
  ToolDefinition,
14
15
  } from "@earendil-works/pi-coding-agent";
15
- import { type Static, Type } from "typebox";
16
+ import { type Static, type TSchema, Type } from "typebox";
16
17
  import { Parse } from "typebox/value";
17
18
  import { loadConfig, type AdaptiveThinkingConfig } from "./config-loader.js";
18
19
  import {
20
+ fallbackThinkingLevels,
19
21
  isThinkingLevel,
20
22
  resolveSupportedThinkingLevels,
21
23
  type PiThinkingLevel,
@@ -53,9 +55,26 @@ type ToolParameters = Static<typeof ToolParameters>;
53
55
 
54
56
  const StatusToolParameters = Type.Object({}, { additionalProperties: false });
55
57
 
56
- type ThinkingLevelStatus = {
57
- currentLevel: PiThinkingLevel | "unknown";
58
- supportedLevels: PiThinkingLevel[];
58
+ const ThinkingLevelSchema = StringEnum(fallbackThinkingLevels);
59
+
60
+ /** Exact final-details schema returned by the Thinking Level Status tool. */
61
+ export const ThinkingLevelStatusSchema = Type.Object(
62
+ {
63
+ currentLevel: Type.Union([ThinkingLevelSchema, Type.Literal("unknown")]),
64
+ supportedLevels: Type.Array(ThinkingLevelSchema),
65
+ },
66
+ { additionalProperties: false },
67
+ );
68
+
69
+ const UndefinedToolOutputSchema = Type.Undefined();
70
+
71
+ type ThinkingLevelStatus = Static<typeof ThinkingLevelStatusSchema>;
72
+
73
+ type ToolDefinitionWithOutputSchema<
74
+ TParameters extends TSchema,
75
+ TOutputSchema extends TSchema,
76
+ > = ToolDefinition<TParameters, Static<TOutputSchema>> & {
77
+ outputSchema: TOutputSchema;
59
78
  };
60
79
 
61
80
  /** The extension-context fields Adaptive Thinking reads at its lifecycle and tool seams. */
@@ -85,11 +104,14 @@ export type AdaptiveThinkingSetThinkingLevelParameters = Static<typeof ToolParam
85
104
  /** Current and supported thinking levels returned by the status tool. */
86
105
  export type AdaptiveThinkingLevelStatus = ThinkingLevelStatus;
87
106
 
88
- type SetThinkingLevelTool = Omit<ToolDefinition<typeof ToolParameters, undefined>, "execute"> & {
107
+ type SetThinkingLevelTool = Omit<
108
+ ToolDefinitionWithOutputSchema<typeof ToolParameters, typeof UndefinedToolOutputSchema>,
109
+ "execute"
110
+ > & {
89
111
  execute: AdaptiveThinkingToolExecution<AdaptiveThinkingSetThinkingLevelParameters, undefined>;
90
112
  };
91
113
  type GetThinkingLevelTool = Omit<
92
- ToolDefinition<typeof StatusToolParameters, ThinkingLevelStatus>,
114
+ ToolDefinitionWithOutputSchema<typeof StatusToolParameters, typeof ThinkingLevelStatusSchema>,
93
115
  "execute"
94
116
  > & {
95
117
  execute: AdaptiveThinkingToolExecution<Record<string, never>, ThinkingLevelStatus>;
@@ -337,6 +359,7 @@ export function registerAdaptiveThinking(pi: AdaptiveThinkingExtensionHost) {
337
359
  `Do not call ${config.toolName} twice in a row; reassess only after new evidence from other tool calls or user input.`,
338
360
  ],
339
361
  parameters: ToolParameters,
362
+ outputSchema: UndefinedToolOutputSchema,
340
363
  execute: async (toolCallId, params: ToolParameters, _signal, _onUpdate, ctx) => {
341
364
  const state = runtime;
342
365
  if (!state) return textResult("Adaptive Thinking is not enabled for this session.");
@@ -399,6 +422,7 @@ export function registerAdaptiveThinking(pi: AdaptiveThinkingExtensionHost) {
399
422
  `Use ${config.statusToolName} only when thinking-level state is uncertain; do not poll it routinely.`,
400
423
  ],
401
424
  parameters: StatusToolParameters,
425
+ outputSchema: ThinkingLevelStatusSchema,
402
426
  execute: async (_toolCallId, _params, _signal, _onUpdate, ctx) => {
403
427
  const currentLevel = pi.getThinkingLevel();
404
428
  return thinkingLevelStatusResult(