@jayyuen66/dsh-plugin-shared 0.2.5 → 0.2.6

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 CHANGED
@@ -136,7 +136,7 @@ The subpath column is the in-package specifier; value imports prefix it with the
136
136
  | Subpath | Provides |
137
137
  | --- | --- |
138
138
  | `.` | Barrel over the runtime modules below, served from `dist/plugin.js`: the same names plus `name` and a no-op `apply`, so the host loader can also take this package as a row. `canonicalize-region-paths` (build-time), `remote-marker` (value-imports typert), and `card-ui` (client-only) deliberately stay out; the root barrel must not pull an unused package into every consumer. |
139
- | `./lib/tool-events` | `scanToolEvents` returns the `calls` / `results` tables, PTC sub-calls included; `toolEventRowsOf` handles a single event and already carries normalized `arguments` and `badArguments`. `editPathOf` returns a `kind`-discriminated `EditTarget` with only `write` / `read-view`; the path is `undefined` when it cannot be read. `applyPatchTargetsOf` parses the ordered operations of an `apply_patch` input with the official `dsh-fs-patch`; `editPathsOf` expands every write target, including both sides of a move. Record fields are `readonly`. Re-exports the official `SessionEvent`; `PtcDispatchStartEventData` / `PtcDispatchEventData` are declared in this package and augment `SessionEventMap` locally, because the host moved that augmentation between packages inside the supported window. |
139
+ | `./lib/tool-events` | `scanToolEvents` returns the `calls` / `results` tables, PTC sub-calls included; `toolEventRowsOf` handles a single event and already carries normalized `arguments` and `badArguments`. `editPathOf` returns a `kind`-discriminated `EditTarget` with only `write` / `read-view`; the path is `undefined` when it cannot be read. `applyPatchTargetsOf` parses the ordered operations of an `apply_patch` input with the official `dsh-fs-patch`; `editPathsOf` expands every write target, including both sides of a move. Record fields are `readonly`. Each result row also carries the structured failure identity `error` from the event's `data.error` (`name` and `code` must be non-empty strings; a partial shape reads as absent, and `reason` is kept only when it is a string). Re-exports the official `SessionEvent`; `PtcDispatchStartEventData` / `PtcDispatchEventData` are declared in this package and augment `SessionEventMap` locally, because the host moved that augmentation between packages inside the supported window. |
140
140
  | `./lib/card-apply` | `claimApply` + `CardApplyCtx`: an apply idempotency guard built on an **own** flag on `globalThis` (a symbol, or `true` written by an outside holder) with `ctx.effect` cleanup. The flag is process-wide, so a second context on the same page is rejected by design. |
141
141
  | `./lib/card-diff` | `diffTouched`: which touched fields really differ from the snapshot, compared by form value. `undefined`, `null` and an absent key are one value; arrays and objects compare element by element; cycles terminate. |
142
142
  | `./lib/card-ui` | Client-only settings-card kit: `CardForm`, `Section`, `FieldGrid`, `StatusBar`, `Field`, `FieldLabel`, `InfoTip`, `ToggleField`, `NumberField`, `TextField`, `ListField`, `SelectField`, `SaveBar`, `splitHint` and the `CARD_UI_CSS` string. Built with `createElement` only; `react` is an optional peer and the subpath never enters the root barrel. The declared peer floor is `^19.3.0`; the kit uses only APIs that already existed in React 18 (`useId`, `useState`, `useEffect`, refs). |
package/README.zh-CN.md CHANGED
@@ -136,7 +136,7 @@ import { isRecord, fieldOf } from "@jayyuen66/dsh-plugin-shared/lib/record";
136
136
  | 子路径 | 提供什么 |
137
137
  | --- | --- |
138
138
  | `.` | 下面列出的运行期模块的 barrel,由 `dist/plugin.js` 提供:同样的导出名,再加 `name` 与一条空操作的 `apply`,宿主 Loader 因此也能把本包当作一行载入。`canonicalize-region-paths`(构建期)、`remote-marker`(值导入 typert)与 `card-ui`(客户端专用)刻意不进;根 barrel 不得把用不到的包带进每个消费方 |
139
- | `./lib/tool-events` | `scanToolEvents` 返回 `calls` / `results` 两张表,PTC 子调用一并合并;`toolEventRowsOf` 处理单个事件,交回的记录已带归一后的 `arguments` 与 `badArguments`。`editPathOf` 返回按 `kind` 判别的 `EditTarget`,只有 `write` / `read-view` 两个分支;路径取不到时为 `undefined`。`applyPatchTargetsOf` 用官方 `dsh-fs-patch` 解析 `apply_patch` 的有序操作;`editPathsOf` 展开全部写目标(move 的源与目的都算)。记录字段一律 `readonly`。同时再导出官方 `SessionEvent`;`PtcDispatchStartEventData` / `PtcDispatchEventData` 在本包内声明并自行增强 `SessionEventMap`,因为宿主在支持窗口内换过承载这份增强的包 |
139
+ | `./lib/tool-events` | `scanToolEvents` 返回 `calls` / `results` 两张表,PTC 子调用一并合并;`toolEventRowsOf` 处理单个事件,交回的记录已带归一后的 `arguments` 与 `badArguments`。`editPathOf` 返回按 `kind` 判别的 `EditTarget`,只有 `write` / `read-view` 两个分支;路径取不到时为 `undefined`。`applyPatchTargetsOf` 用官方 `dsh-fs-patch` 解析 `apply_patch` 的有序操作;`editPathsOf` 展开全部写目标(move 的源与目的都算)。记录字段一律 `readonly`。结果行另带结算事件 `data.error` 的结构化失败身份 `error`(`name` / `code` 必须是非空字符串,半截形状按缺席处理;`reason` 只在它是字符串时保留)。同时再导出官方 `SessionEvent`;`PtcDispatchStartEventData` / `PtcDispatchEventData` 在本包内声明并自行增强 `SessionEventMap`,因为宿主在支持窗口内换过承载这份增强的包 |
140
140
  | `./lib/card-apply` | `claimApply` + `CardApplyCtx`:保证 apply 幂等的保护逻辑,建立在 `globalThis` 上的**自有**标记(symbol,或外部写入的 `true`)加 `ctx.effect` 清理。标记是进程级的,所以同一页面的第二个 ctx 会被拒绝——这是有意的设计 |
141
141
  | `./lib/card-diff` | `diffTouched`:touched 层里哪些字段真的与快照不同,按表单值比较。`undefined`、`null` 与键缺失是同一种值;数组与对象逐元素比较;循环引用也能正常结束 |
142
142
  | `./lib/card-ui` | 客户端专用设置卡组件:`CardForm`、`Section`、`FieldGrid`、`StatusBar`、`Field`、`FieldLabel`、`InfoTip`、`ToggleField`、`NumberField`、`TextField`、`ListField`、`SelectField`、`SaveBar`、`splitHint` 与样式字符串 `CARD_UI_CSS`。只用 `createElement`;`react` 是 optional peer,该子路径永不进根 barrel。声明的 peer 下限是 `^19.3.0`;组件只用 React 18 就已存在的 API(`useId`、`useState`、`useEffect`、refs) |
@@ -1 +1 @@
1
- import{isRecord as e}from"./record.js";import{parsePatch as t}from"@deepseek-ai/dsh-fs-patch";function n(t){return e(t)&&t.isError===!0}function r(e){return e===!0}function i(t){return e(t.data)}function a(e){return typeof e==`string`&&e.length>0?e:void 0}function o(e){return typeof e==`string`&&e.length>0?e:void 0}function s(t){if(typeof t==`string`)try{let n=JSON.parse(t);return{arguments:e(n)?n:{},badArguments:!1}}catch{return{arguments:{},badArguments:!0}}return{arguments:e(t)?t:{},badArguments:!1}}function c(e,t){let n;if(!i(e))return n;if(e.type===`tool/call`){let r=o(e.data.name);if(r!==void 0){let i=s(e.data.arguments);n={name:r,callId:a(e.data.callId),arguments:i.arguments,badArguments:i.badArguments,seq:t}}}else if(e.type===`tool/ptc-dispatch-start`){let r=a(e.data.subCallId),i=o(e.data.name);if(r!==void 0&&i!==void 0){let a=s(e.data.arguments);n={name:i,callId:r,arguments:a.arguments,badArguments:a.badArguments,seq:t}}}return n}function l(t,o){let s;if(!i(t))return s;if(t.type===`tool/result`){let r=t.data.message,i=e(r)?r.source:void 0;s={callId:e(i)?a(i.callId):void 0,isError:n(r),seq:o}}else if(t.type===`tool/ptc-dispatch`){let e=a(t.data.subCallId);e!==void 0&&(s={callId:e,isError:r(t.data.isError),seq:o})}return s}function u(e,t){return{call:c(e,t),result:l(e,t)}}function d(t){let n=[],r=[];for(let[i,a]of t.entries())if(e(a)){let{call:e,result:t}=u(a,i);e!==void 0&&n.push(e),t!==void 0&&r.push(t)}return{calls:n,results:r}}function f(e,t){let n=e[t];return typeof n==`string`?n:void 0}function p(e){let n=e?.input;if(typeof n!=`string`||!n.includes(`*** Begin Patch`))return[];try{return t(n).map(e=>e.kind===`update`?e.moveTo===void 0?{kind:`update`,path:e.path}:{kind:`update`,path:e.path,moveTo:e.moveTo}:{kind:e.kind,path:e.path})}catch{return[]}}function m(e){let t=e.arguments;return e.name===`apply_patch`?{kind:`write`,path:p(t)[0]?.path}:e.name===`str_replace_editor`?t.command===`view`?{kind:`read-view`,path:f(t,`path`)}:{kind:`write`,path:f(t,`path`)}:{kind:`write`,path:f(t,`file_path`)}}function h(e){if(e.name===`apply_patch`){let t=p(e.arguments).flatMap(e=>e.kind===`update`&&e.moveTo!==void 0?[e.path,e.moveTo]:[e.path]);return t.filter((e,n)=>e.length>0&&t.indexOf(e)===n)}let t=m(e);return t.kind===`write`&&t.path!==void 0?[t.path]:[]}export{p as applyPatchTargetsOf,m as editPathOf,h as editPathsOf,d as scanToolEvents,u as toolEventRowsOf};
1
+ import{isRecord as e}from"./record.js";import{parsePatch as t}from"@deepseek-ai/dsh-fs-patch";function n(t){return e(t)&&t.isError===!0}function r(t){let n;if(e(t)){let{name:e,code:r,reason:i}=t;typeof e==`string`&&e!==``&&typeof r==`string`&&r!==``&&(n=typeof i==`string`?{name:e,code:r,reason:i}:{name:e,code:r})}return n}function i(e){return e===!0}function a(t){return e(t.data)}function o(e){return typeof e==`string`&&e.length>0?e:void 0}function s(e){return typeof e==`string`&&e.length>0?e:void 0}function c(t){if(typeof t==`string`)try{let n=JSON.parse(t);return{arguments:e(n)?n:{},badArguments:!1}}catch{return{arguments:{},badArguments:!0}}return{arguments:e(t)?t:{},badArguments:!1}}function l(e,t){let n;if(!a(e))return n;if(e.type===`tool/call`){let r=s(e.data.name);if(r!==void 0){let i=c(e.data.arguments);n={name:r,callId:o(e.data.callId),arguments:i.arguments,badArguments:i.badArguments,seq:t}}}else if(e.type===`tool/ptc-dispatch-start`){let r=o(e.data.subCallId),i=s(e.data.name);if(r!==void 0&&i!==void 0){let a=c(e.data.arguments);n={name:i,callId:r,arguments:a.arguments,badArguments:a.badArguments,seq:t}}}return n}function u(t,s){let c;if(!a(t))return c;if(t.type===`tool/result`){let i=t.data.message,a=e(i)?i.source:void 0;c={callId:e(a)?o(a.callId):void 0,isError:n(i),error:r(t.data.error),seq:s}}else if(t.type===`tool/ptc-dispatch`){let e=o(t.data.subCallId);e!==void 0&&(c={callId:e,isError:i(t.data.isError),error:r(t.data.error),seq:s})}return c}function d(e,t){return{call:l(e,t),result:u(e,t)}}function f(t){let n=[],r=[];for(let[i,a]of t.entries())if(e(a)){let{call:e,result:t}=d(a,i);e!==void 0&&n.push(e),t!==void 0&&r.push(t)}return{calls:n,results:r}}function p(e,t){let n=e[t];return typeof n==`string`?n:void 0}function m(e){let n=e?.input;if(typeof n!=`string`||!n.includes(`*** Begin Patch`))return[];try{return t(n).map(e=>e.kind===`update`?e.moveTo===void 0?{kind:`update`,path:e.path}:{kind:`update`,path:e.path,moveTo:e.moveTo}:{kind:e.kind,path:e.path})}catch{return[]}}function h(e){let t=e.arguments;return e.name===`apply_patch`?{kind:`write`,path:m(t)[0]?.path}:e.name===`str_replace_editor`?t.command===`view`?{kind:`read-view`,path:p(t,`path`)}:{kind:`write`,path:p(t,`path`)}:{kind:`write`,path:p(t,`file_path`)}}function g(e){if(e.name===`apply_patch`){let t=m(e.arguments).flatMap(e=>e.kind===`update`&&e.moveTo!==void 0?[e.path,e.moveTo]:[e.path]);return t.filter((e,n)=>e.length>0&&t.indexOf(e)===n)}let t=h(e);return t.kind===`write`&&t.path!==void 0?[t.path]:[]}export{m as applyPatchTargetsOf,h as editPathOf,g as editPathsOf,f as scanToolEvents,d as toolEventRowsOf};
@@ -71,10 +71,31 @@ export interface ToolCallRecord {
71
71
  */
72
72
  readonly seq: number;
73
73
  }
74
+ /**
75
+ * 失败的结构化身份:官方 `tool/result` 与 `tool/ptc-dispatch` 的 `data.error`
76
+ * (`{ name, code, reason? }`,只允许出现在 `isError: true` 的结算旁)。
77
+ *
78
+ * 复制而不是引用官方 `ToolErrorInfo`:本包的商品面同时服务多个宿主版本,而错误码是
79
+ * **持久化契约**(官方把 `[name, code]` 记在日志里供消费方比较字符串)。形状上逐字段同形,
80
+ * 两边改名会在这里的字段读取处暴露,不需要再引入一层运行时依赖。
81
+ */
82
+ export interface ToolErrorIdentity {
83
+ /** 错误类名(如 `AbortError`、`ApprovalError`)。 */
84
+ readonly name: string;
85
+ /** 稳定错误码(如 `ABORTED`、`APPROVAL_REJECTED`)。 */
86
+ readonly code: string;
87
+ /** 可选的原始用户可见细节;模型侧内容不含它。 */
88
+ readonly reason?: string;
89
+ }
74
90
  /** 一条 tool/result 的成败。同样只读。 */
75
91
  export interface ToolResultRecord {
76
92
  readonly callId: string | undefined;
77
93
  readonly isError: boolean;
94
+ /**
95
+ * 失败身份:`isError` 为真时由结算事件携带;缺失是正常情况(旧宿主、守卫拒绝、
96
+ * 工具体抛出的普通错误都不带身份),消费方必须把它当成"没有分类"而不是成功。
97
+ */
98
+ readonly error: ToolErrorIdentity | undefined;
78
99
  readonly seq: number;
79
100
  }
80
101
  /** 一条事件产出的记录行(call 与 result 互斥;非记录事件两位都是 undefined)。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayyuen66/dsh-plugin-shared",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "dsh 自研插件的共享工具库:tool 事件流记账扫描 + 卡片 apply/差异骨架 + 统一设置卡 UI 组件 + 官方作业结局映射 + 项目键派生 + 代理对安全截断。宿主半由各插件 import;客户端半以 ./client 共享行由插件 patch 启用,不由用户单独停用",
5
5
  "keywords": [
6
6
  "cordis",