@jetcrab/pi-desk-tool-reason 0.0.0-stage → 1.0.1-dev.9001

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mikey O'Brien
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # Pi Desk — pi-desk-tool-reason
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 包名:`@jetcrab/pi-desk-tool-reason`。插件接口以源码导出为准,个人配置不随包分发。
4
+
5
+ 许可与第三方来源见本目录的 LICENSE 及适用的归属说明。
package/UPSTREAM.md ADDED
@@ -0,0 +1,7 @@
1
+ # Upstream
2
+
3
+ 本扩展从本地归档的 `tidy-tools` 定制实现中提取工具 `reasoning` 参数的注入与执行前剥离逻辑;该本地归档不随本仓库分发。
4
+
5
+ 归档实现基于 [`@mobrienv/pi-tidy-tools`](https://github.com/mikeyobrien/pi-tidy-tools) **0.4.1**,遵循随本扩展保留的 MIT `LICENSE`。
6
+
7
+ 当前扩展只保留 `reasoning` 工具参数逻辑,不包含上游的 TUI 渲染、命令、配置、Diff 或 Bash 高亮功能。
@@ -0,0 +1,2 @@
1
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
2
+ export default function toolReasoning(pi: ExtensionAPI): void;
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ import { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition } from '@earendil-works/pi-coding-agent';
2
+ import { composeSourceTool } from './tool-composition.js';
3
+ const TOOL_FACTORIES = [
4
+ createReadToolDefinition,
5
+ createWriteToolDefinition,
6
+ createEditToolDefinition,
7
+ createBashToolDefinition,
8
+ createGrepToolDefinition,
9
+ createFindToolDefinition,
10
+ createLsToolDefinition
11
+ ];
12
+ function executionCwd(args) {
13
+ const context = args[4];
14
+ if (!context || typeof context !== 'object') {
15
+ throw new Error('tool-reasoning requires a Pi execution context');
16
+ }
17
+ const cwd = context.cwd;
18
+ if (typeof cwd !== 'string' || !cwd) {
19
+ throw new Error('tool-reasoning requires a Pi execution cwd');
20
+ }
21
+ return cwd;
22
+ }
23
+ // MyPi consumes extension tools without emitting session_start. Register now,
24
+ // then rebuild the original tool at execution time so every WorkSession uses ctx.cwd.
25
+ function createSourceTool(factory) {
26
+ const source = factory(process.cwd());
27
+ return {
28
+ ...source,
29
+ async execute(...args) {
30
+ const runtimeSource = factory(executionCwd(args));
31
+ return runtimeSource.execute(...args);
32
+ }
33
+ };
34
+ }
35
+ export default function toolReasoning(pi) {
36
+ for (const factory of TOOL_FACTORIES) {
37
+ const source = createSourceTool(factory);
38
+ pi.registerTool(composeSourceTool(source));
39
+ }
40
+ }
@@ -0,0 +1,7 @@
1
+ export interface SourceToolDefinition {
2
+ name: string;
3
+ parameters: Record<string, unknown>;
4
+ execute: (...args: unknown[]) => Promise<unknown>;
5
+ [key: string]: unknown;
6
+ }
7
+ export declare function composeSourceTool(source: SourceToolDefinition): SourceToolDefinition;
@@ -0,0 +1,40 @@
1
+ const REASONING_DESCRIPTION = 'Short phrase (≤12 words) stating the GOAL behind this call — the why-in-context, not the what. Do NOT restate the file, path, or command; instead give the intent or what you expect to find/confirm.';
2
+ function withReasoning(parameters) {
3
+ const properties = parameters.properties;
4
+ const sourceProperties = properties && typeof properties === 'object' ? properties : {};
5
+ return {
6
+ ...parameters,
7
+ properties: {
8
+ reasoning: {
9
+ type: 'string',
10
+ description: REASONING_DESCRIPTION
11
+ },
12
+ ...sourceProperties
13
+ }
14
+ };
15
+ }
16
+ function withoutReasoning(params) {
17
+ if (!params || typeof params !== 'object')
18
+ return {};
19
+ const { reasoning: _reasoning, ...rest } = params;
20
+ return rest;
21
+ }
22
+ export function composeSourceTool(source) {
23
+ const properties = source.parameters.properties;
24
+ if (properties && typeof properties === 'object' && Object.hasOwn(properties, 'reasoning')) {
25
+ throw new Error(`${source.name} source schema already defines reasoning`);
26
+ }
27
+ const sourceExecute = source.execute;
28
+ const tool = {
29
+ ...source,
30
+ parameters: withReasoning(source.parameters),
31
+ async execute(...args) {
32
+ args[1] = withoutReasoning(args[1]);
33
+ return sourceExecute.call(source, ...args);
34
+ }
35
+ };
36
+ delete tool.renderCall;
37
+ delete tool.renderResult;
38
+ delete tool.renderShell;
39
+ return tool;
40
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@jetcrab/pi-desk-tool-reason",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "git+https://github.com/JetCrab/pi-desk.git",
6
+ "directory": "plugins/pi-desk-tool-reason"
7
+ },
8
+ "version": "1.0.1-dev.9001",
9
+ "publishConfig": {
10
+ "registry": "https://registry.npmjs.org",
11
+ "access": "public"
12
+ },
13
+ "description": "Pi Desk tool reasoning extension",
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "exports": {
17
+ ".": "./dist/index.js"
18
+ },
19
+ "types": "./dist/index.d.ts",
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "LICENSE",
24
+ "UPSTREAM.md"
25
+ ],
26
+ "peerDependencies": {
27
+ "@earendil-works/pi-coding-agent": "*"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20",
31
+ "tsx": "^4.23.12",
32
+ "typescript": "^5"
33
+ },
34
+ "keywords": [
35
+ "pi-package"
36
+ ],
37
+ "pi": {
38
+ "extensions": [
39
+ "./dist/index.js"
40
+ ]
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json",
44
+ "test": "node --import tsx --test tests/*.test.mjs"
45
+ }
6
46
  }