dsh-coding 0.0.1 → 0.1.1-rc2

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.
Files changed (78) hide show
  1. package/AGENTS.md +80 -0
  2. package/LICENSE +21 -21
  3. package/README.md +120 -54
  4. package/cordis.patch.yml +274 -4
  5. package/docs/CHANGELOG.md +47 -0
  6. package/docs/DETAIL.md +272 -0
  7. package/icon.svg +6 -6
  8. package/lib/apply-patch.js +268 -0
  9. package/lib/client/capsule.js +120 -0
  10. package/lib/client/card.js +308 -0
  11. package/lib/client/command-row.js +76 -0
  12. package/lib/client/config-page.js +392 -0
  13. package/lib/client/definition.js +164 -0
  14. package/lib/client/index.js +129 -0
  15. package/lib/client/locales.js +170 -0
  16. package/lib/client/mode-picker.js +77 -0
  17. package/lib/client/styles.js +283 -0
  18. package/lib/client.js +1802 -0
  19. package/lib/coding-projection.js +349 -0
  20. package/lib/config.js +218 -0
  21. package/lib/contract.js +138 -0
  22. package/lib/editor.js +23 -0
  23. package/lib/failures.js +142 -0
  24. package/lib/handoff.js +347 -0
  25. package/lib/index.js +110 -7
  26. package/lib/language.js +136 -0
  27. package/lib/memory.js +336 -0
  28. package/lib/messages.js +43 -0
  29. package/lib/models.js +154 -0
  30. package/lib/patch.js +235 -0
  31. package/lib/preset.js +1552 -0
  32. package/lib/reasoning-levels.js +28 -0
  33. package/lib/reasoning-projection.js +178 -0
  34. package/lib/reasoning.js +585 -0
  35. package/lib/stages.js +344 -0
  36. package/lib/state.js +585 -0
  37. package/lib/system-language.js +56 -0
  38. package/lib/types/apply-patch.d.ts +13 -0
  39. package/lib/types/client/capsule.d.ts +9 -0
  40. package/lib/types/client/card.d.ts +76 -0
  41. package/lib/types/client/command-row.d.ts +42 -0
  42. package/lib/types/client/config-page.d.ts +136 -0
  43. package/lib/types/client/definition.d.ts +51 -0
  44. package/lib/types/client/index.d.ts +10 -0
  45. package/lib/types/client/locales.d.ts +18 -0
  46. package/lib/types/client/mode-picker.d.ts +25 -0
  47. package/lib/types/client/styles.d.ts +28 -0
  48. package/lib/types/coding-projection.d.ts +116 -0
  49. package/lib/types/config.d.ts +208 -0
  50. package/lib/types/contract.d.ts +33 -0
  51. package/lib/types/editor.d.ts +9 -0
  52. package/lib/types/failures.d.ts +62 -0
  53. package/lib/types/handoff.d.ts +132 -0
  54. package/lib/types/index.d.ts +150 -0
  55. package/lib/types/language.d.ts +56 -0
  56. package/lib/types/memory.d.ts +71 -0
  57. package/lib/types/messages.d.ts +27 -0
  58. package/lib/types/models.d.ts +82 -0
  59. package/lib/types/patch.d.ts +37 -0
  60. package/lib/types/preset.d.ts +22 -0
  61. package/lib/types/reasoning-levels.d.ts +20 -0
  62. package/lib/types/reasoning-projection.d.ts +64 -0
  63. package/lib/types/reasoning.d.ts +141 -0
  64. package/lib/types/stages.d.ts +193 -0
  65. package/lib/types/state.d.ts +273 -0
  66. package/lib/types/system-language.d.ts +10 -0
  67. package/lib/types/verification-tool.d.ts +32 -0
  68. package/lib/types/verification.d.ts +77 -0
  69. package/lib/types/verifier.d.ts +9 -0
  70. package/lib/types/volatile.d.ts +17 -0
  71. package/lib/verification-tool.js +176 -0
  72. package/lib/verification.js +337 -0
  73. package/lib/verifier.js +25 -0
  74. package/lib/volatile.js +20 -0
  75. package/locale/en.json +3 -2
  76. package/locale/zh.json +3 -2
  77. package/package.json +84 -9
  78. package/lib/index.d.ts +0 -11
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The three Coding reasoning levels and the pure mapping between a level and a
3
+ * provider effort id.
4
+ *
5
+ * Dependency-free on purpose: the Host controller and the browser card both
6
+ * import this module, so it must never pull in a Node-only package.
7
+ *
8
+ * @module dsh-coding/reasoning-levels
9
+ */
10
+ /** Rank a level so plan growth can only escalate inside one turn. */
11
+ export function rank(level) {
12
+ return level === 'low' ? 1 : level === 'high' ? 2 : 3;
13
+ }
14
+ export function higher(a, b) {
15
+ return rank(a) >= rank(b) ? a : b;
16
+ }
17
+ /**
18
+ * Map a provider effort id back to the Coding level it stands for. The chat
19
+ * box reports provider ids (`minimal`, `medium`, `xhigh`), while this preset
20
+ * reasons in `low`/`high`/`max`; unknown ids stay at the conservative default.
21
+ */
22
+ export function levelForEffort(effort) {
23
+ if (effort === 'max' || effort === 'xhigh')
24
+ return 'max';
25
+ if (effort === 'high' || effort === 'medium')
26
+ return 'high';
27
+ return 'low';
28
+ }
@@ -0,0 +1,178 @@
1
+ /** Projection key shared by the Host fold and the Web card. */
2
+ export const REASONING_PROJECTION_KEY = 'dshCodingReasoning';
3
+ /** Bound the history the state carries; older cards fall back to pending. */
4
+ const MAX_TURNS = 100;
5
+ function isLevel(value) {
6
+ return value === 'low' || value === 'high' || value === 'max';
7
+ }
8
+ /** Numeric `turn/start` and `turn/end` payloads; anything else is ignored. */
9
+ function eventTurn(event) {
10
+ const value = event?.data?.turn;
11
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
12
+ }
13
+ /** Read a session override from a `coding_reasoning` tool call's JSON arguments. */
14
+ export function overrideFromToolArguments(raw) {
15
+ if (typeof raw !== 'string')
16
+ return undefined;
17
+ try {
18
+ const parsed = JSON.parse(raw);
19
+ const value = parsed?.effort;
20
+ if (value === 'auto')
21
+ return 'auto';
22
+ return isLevel(value) ? value : undefined;
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ /** Effort id the user picked in the chat box; `model/selection` owns it. */
29
+ function effortFromSelection(event) {
30
+ const value = event;
31
+ if (value.type !== 'model/selection')
32
+ return undefined;
33
+ const effort = value.data?.reasoningEffort;
34
+ if (typeof effort !== 'string')
35
+ return null;
36
+ const trimmed = effort.trim();
37
+ return trimmed === '' ? null : trimmed;
38
+ }
39
+ /** Effort id written into the request header; absent or blank means none. */
40
+ function effortFromHeader(event) {
41
+ const value = event;
42
+ if (value.type !== 'request/header')
43
+ return undefined;
44
+ const effort = value.data?.header?.config?.reasoningEffort;
45
+ if (typeof effort !== 'string')
46
+ return null;
47
+ const trimmed = effort.trim();
48
+ return trimmed === '' ? null : trimmed;
49
+ }
50
+ /** Validate one persisted or wire value as {@link ReasoningProjectionState}. */
51
+ function parseState(value) {
52
+ if (typeof value !== 'object' || value === null) {
53
+ throw new Error('dsh-coding: reasoning projection state is not an object');
54
+ }
55
+ const v = value;
56
+ const override = v['override'];
57
+ if (override !== null && !isLevel(override)) {
58
+ throw new Error('dsh-coding: reasoning projection override is not a level');
59
+ }
60
+ const userEffort = v['userEffort'];
61
+ if (userEffort !== null && typeof userEffort !== 'string') {
62
+ throw new Error('dsh-coding: reasoning projection userEffort is not a string');
63
+ }
64
+ const effort = v['effort'];
65
+ if (effort !== null && typeof effort !== 'string') {
66
+ throw new Error('dsh-coding: reasoning projection effort is not a string');
67
+ }
68
+ if (typeof v['running'] !== 'boolean') {
69
+ throw new Error('dsh-coding: reasoning projection running is not a boolean');
70
+ }
71
+ const latest = v['latest'];
72
+ if (typeof latest !== 'number' || !Number.isFinite(latest)) {
73
+ throw new Error('dsh-coding: reasoning projection latest is not a number');
74
+ }
75
+ const turns = v['turns'];
76
+ if (!Array.isArray(turns)) {
77
+ throw new Error('dsh-coding: reasoning projection turns is not an array');
78
+ }
79
+ return {
80
+ override,
81
+ userEffort,
82
+ effort,
83
+ running: v['running'],
84
+ latest,
85
+ turns: turns.map((item) => {
86
+ if (typeof item !== 'object' || item === null) {
87
+ throw new Error('dsh-coding: reasoning projection turn is not an object');
88
+ }
89
+ const t = item;
90
+ const turn = t['turn'];
91
+ if (typeof turn !== 'number' || !Number.isFinite(turn)) {
92
+ throw new Error('dsh-coding: reasoning projection turn.turn is not a number');
93
+ }
94
+ const tOverride = t['override'];
95
+ if (tOverride !== null && !isLevel(tOverride)) {
96
+ throw new Error('dsh-coding: reasoning projection turn.override is not a level');
97
+ }
98
+ const tUserEffort = t['userEffort'];
99
+ if (tUserEffort !== null && typeof tUserEffort !== 'string') {
100
+ throw new Error('dsh-coding: reasoning projection turn.userEffort is not a string');
101
+ }
102
+ const tEffort = t['effort'];
103
+ if (tEffort !== null && typeof tEffort !== 'string') {
104
+ throw new Error('dsh-coding: reasoning projection turn.effort is not a string');
105
+ }
106
+ return { turn, override: tOverride, userEffort: tUserEffort, effort: tEffort };
107
+ }),
108
+ };
109
+ }
110
+ export const reasoningProjection = {
111
+ key: REASONING_PROJECTION_KEY,
112
+ // v2 adds the request-header effort and the per-turn snapshots the card
113
+ // freezes; a cached v1 state must be discarded and rebuilt.
114
+ stateVersion: 2,
115
+ stateSchema: { parse: parseState },
116
+ init: () => ({
117
+ override: null,
118
+ userEffort: null,
119
+ effort: null,
120
+ running: false,
121
+ latest: 0,
122
+ turns: [],
123
+ }),
124
+ apply: (state, event) => {
125
+ const value = event;
126
+ if (value.type === 'tool/call' && value.data?.name === 'coding_reasoning') {
127
+ const override = overrideFromToolArguments(value.data.arguments ?? value.data.args);
128
+ if (override === undefined)
129
+ return state;
130
+ const next = override === 'auto' ? null : override;
131
+ // An explicit tool decision replaces whatever the chat box picked.
132
+ return next === state.override && state.userEffort === null
133
+ ? state
134
+ : { ...state, override: next, userEffort: null };
135
+ }
136
+ const picked = effortFromSelection(event);
137
+ if (picked !== undefined) {
138
+ // `agent.model.select()` writes `model/selection` too. Folding this
139
+ // plugin's own automatic level as a chat-box pick would pin `auto`
140
+ // forever, so an effort-bearing selection only counts while no turn is
141
+ // open. An effort-less one is the explicit "back to automatic": this
142
+ // plugin never produces it, so it stays meaningful mid-turn.
143
+ if (state.running && picked !== null)
144
+ return state;
145
+ return picked === state.userEffort && state.override === null
146
+ ? state
147
+ : { ...state, userEffort: picked, override: null };
148
+ }
149
+ const effort = effortFromHeader(event);
150
+ if (effort !== undefined) {
151
+ return effort === state.effort ? state : { ...state, effort };
152
+ }
153
+ const turn = eventTurn(event);
154
+ if (turn !== undefined && (value.type === 'turn/start' || value.type === 'turn/end')) {
155
+ if (value.type === 'turn/start') {
156
+ return state.running ? state : { ...state, running: true };
157
+ }
158
+ // Snapshot the reasoning state when a turn closes: its card must keep
159
+ // the level that turn actually used, while later turns move on.
160
+ const latest = Math.max(state.latest, turn);
161
+ const turns = [
162
+ ...state.turns.filter((item) => item.turn !== turn),
163
+ { turn, override: state.override, userEffort: state.userEffort, effort: state.effort },
164
+ ].slice(-MAX_TURNS);
165
+ return { ...state, latest, turns, running: false };
166
+ }
167
+ return state;
168
+ },
169
+ wire: {
170
+ // Every value must be lossless JSON: the Host forwards this block inside
171
+ // `api-session/added`.
172
+ viewSchema: { parse: parseState },
173
+ view: (state) => state,
174
+ // Per-session detail; keeping it out of summaries avoids copying it into
175
+ // every Session-list row.
176
+ summary: false,
177
+ },
178
+ };