@fish-under-sea/dsh-client-ui-task-board-fish 1.0.2 → 1.1.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/NOTICE +1 -1
- package/README.en.md +4 -4
- package/README.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +4428 -1508
- package/lib/client.js.map +1 -1
- package/lib/index.js +2670 -496
- package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
- package/lib/types/client/PluginSettingsCard.d.ts +130 -19
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +63 -0
- package/lib/types/client/board/AttachmentField.d.ts +70 -0
- package/lib/types/client/board/ExecutionLog.d.ts +24 -0
- package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
- package/lib/types/client/board/TaskForm.d.ts +4 -0
- package/lib/types/client/board/VerificationReport.d.ts +2 -15
- package/lib/types/client/board/model-options.d.ts +87 -0
- package/lib/types/client/board/preset-label.d.ts +21 -0
- package/lib/types/client/board/preset-roster.d.ts +45 -0
- package/lib/types/client/board/source-group.d.ts +27 -0
- package/lib/types/client/body-mutations.d.ts +45 -0
- package/lib/types/client/host-api.d.ts +25 -0
- package/lib/types/client/locales.d.ts +87 -9
- package/lib/types/client/pending-verify.d.ts +47 -0
- package/lib/types/client/plugin-card-seat.d.ts +3 -1
- package/lib/types/client/service.d.ts +4 -1
- package/lib/types/client/settings-form.d.ts +73 -51
- package/lib/types/core/attachment.d.ts +132 -0
- package/lib/types/core/card-defaults.d.ts +78 -0
- package/lib/types/core/controller.d.ts +57 -8
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +116 -0
- package/lib/types/core/launch-width.d.ts +31 -0
- package/lib/types/core/reasoning-effort.d.ts +57 -0
- package/lib/types/core/session-reuse.d.ts +7 -1
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/subtask.d.ts +100 -37
- package/lib/types/core/tasks.d.ts +94 -10
- package/lib/types/core/use-cases/task-create.d.ts +10 -5
- package/lib/types/core/use-cases/task-tag.d.ts +36 -0
- package/lib/types/core/use-cases/task-update.d.ts +22 -1
- package/lib/types/core/wire-projection.d.ts +35 -0
- package/lib/types/core/workspace-target.d.ts +23 -3
- package/lib/types/host/attachments.d.ts +250 -0
- package/lib/types/host/extension-registry.d.ts +40 -0
- package/lib/types/host/launch-admission.d.ts +71 -0
- package/lib/types/host-ledger.d.ts +114 -47
- package/lib/types/host-routes.d.ts +63 -0
- package/lib/types/host-runner.d.ts +164 -18
- package/lib/types/host-service.d.ts +182 -46
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +173 -54
- package/lib/types/loopback.d.ts +41 -1
- package/lib/types/protocol.d.ts +52 -11
- package/lib/types/tool-surface.d.ts +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +35 -28
- package/src/client/CardDefaultPresetField.tsx +101 -0
- package/src/client/PluginSettingsCard.tsx +385 -111
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/TaskBoardSettingsCard.tsx +332 -37
- package/src/client/board/AttachmentField.tsx +383 -0
- package/src/client/board/EditTaskModal.tsx +63 -0
- package/src/client/board/ExecutionLog.tsx +154 -0
- package/src/client/board/LinkSubtaskModal.tsx +1 -1
- package/src/client/board/NewTaskModal.tsx +154 -45
- package/src/client/board/ReasoningEffortField.tsx +50 -0
- package/src/client/board/TagManagerModal.tsx +151 -2
- package/src/client/board/TaskBoard.tsx +47 -10
- package/src/client/board/TaskCard.tsx +45 -23
- package/src/client/board/TaskDetail.tsx +468 -258
- package/src/client/board/TaskForm.tsx +19 -4
- package/src/client/board/VerificationReport.tsx +143 -104
- package/src/client/board/model-options.ts +208 -0
- package/src/client/board/preset-label.ts +32 -0
- package/src/client/board/preset-roster.ts +58 -0
- package/src/client/board/source-group.ts +94 -0
- package/src/client/board/task-markdown.module.css +11 -8
- package/src/client/board-settings.module.css +35 -7
- package/src/client/board.module.css +1044 -105
- package/src/client/body-mutations.ts +133 -0
- package/src/client/host-api.ts +70 -0
- package/src/client/index.ts +109 -95
- package/src/client/locales.ts +205 -48
- package/src/client/pending-verify.ts +90 -0
- package/src/client/plugin-card-seat.ts +8 -2
- package/src/client/service.ts +24 -0
- package/src/client/settings-card.module.css +466 -89
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/settings-form.ts +102 -60
- package/src/core/attachment.ts +287 -0
- package/src/core/card-defaults.ts +132 -0
- package/src/core/controller.ts +90 -11
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +120 -0
- package/src/core/launch-width.ts +38 -0
- package/src/core/reasoning-effort.ts +92 -0
- package/src/core/session-reuse.ts +7 -1
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +19 -1
- package/src/core/subtask.ts +144 -68
- package/src/core/tasks.ts +117 -10
- package/src/core/use-cases/task-create.ts +27 -16
- package/src/core/use-cases/task-tag.ts +56 -0
- package/src/core/use-cases/task-update.ts +33 -5
- package/src/core/wire-projection.ts +81 -0
- package/src/core/workspace-target.ts +27 -3
- package/src/host/agent-tools.ts +33 -21
- package/src/host/attachments.ts +650 -0
- package/src/host/extension-registry.ts +150 -5
- package/src/host/launch-admission.ts +139 -0
- package/src/host-ledger.ts +248 -117
- package/src/host-routes.ts +233 -15
- package/src/host-runner.ts +395 -61
- package/src/host-service.ts +512 -139
- package/src/host-spend.ts +105 -0
- package/src/index.ts +312 -92
- package/src/loopback.ts +57 -1
- package/src/protocol.ts +83 -18
- package/src/tool-surface.ts +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Today's measured spend, read from the usage ledger this deployment keeps at
|
|
3
|
+
* `$DSH_HOME/dsh-usage/usage-ledger.json`.
|
|
4
|
+
*
|
|
5
|
+
* The measure is the family usage ledger rather than a counter this plugin
|
|
6
|
+
* accumulates from `session/event`, for two reasons. The ledger is durable, so
|
|
7
|
+
* a cap cannot be reset by restarting the Host (the Loader remounts a row on
|
|
8
|
+
* any config change, and a spend counter that lived only in memory would forget
|
|
9
|
+
* the day). And a second fold of the same events inside the board would have to
|
|
10
|
+
* persist its own totals to be worth anything, which means a second writer of
|
|
11
|
+
* spend state in one process.
|
|
12
|
+
*
|
|
13
|
+
* What that costs: the file belongs to the dsh-usage plugin, so a deployment
|
|
14
|
+
* that does not mount it keeps no ledger and the cap cannot measure anything.
|
|
15
|
+
* That case is reported once per process and the gate then refuses nothing —
|
|
16
|
+
* wedging the board because a sibling plugin is absent would be worse than a
|
|
17
|
+
* cap that says it cannot see. The 3 s flush debounce of that plugin is the
|
|
18
|
+
* other cost: the reading trails the busiest moments by at most one debounce.
|
|
19
|
+
* @module @fish-under-sea/dsh-client-ui-task-board-fish/host-spend
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { readFileSync } from 'node:fs'
|
|
23
|
+
import { join } from 'node:path'
|
|
24
|
+
import { dshHome } from './dsh-home.ts'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The token fields one ledger bucket totals. Billed input is uncached input
|
|
28
|
+
* plus both cache buckets; output already includes reasoning, so reasoning is
|
|
29
|
+
* deliberately not added again — the sum is the one the usage panel shows.
|
|
30
|
+
*/
|
|
31
|
+
const TOKEN_FIELDS = ['inputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens'] as const
|
|
32
|
+
|
|
33
|
+
/** Reported at most once per process: an unmeasurable cap is a startup fact, not a per-run one. */
|
|
34
|
+
let reportedUnmeasurable = false
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Local-date key (`YYYY-MM-DD`) of an instant, the bucketing the usage ledger
|
|
38
|
+
* itself uses: the cap and the usage panel therefore roll over at the same
|
|
39
|
+
* local midnight.
|
|
40
|
+
* @param ms - clock instant (ms epoch).
|
|
41
|
+
* @returns the day key.
|
|
42
|
+
*/
|
|
43
|
+
export function spendDateKey(ms: number): string {
|
|
44
|
+
const date = new Date(ms)
|
|
45
|
+
const month = String(date.getMonth() + 1).padStart(2, '0')
|
|
46
|
+
const day = String(date.getDate()).padStart(2, '0')
|
|
47
|
+
return `${date.getFullYear()}-${month}-${day}`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Total tokens one ledger day recorded, across every provider and model of that
|
|
52
|
+
* day. Anything that is not a finite token count contributes 0, so a ledger
|
|
53
|
+
* written by another version degrades to a smaller reading instead of NaN.
|
|
54
|
+
* @param day - one day bucket as the ledger stores it, when it is one.
|
|
55
|
+
* @returns the day's token total.
|
|
56
|
+
*/
|
|
57
|
+
export function ledgerDayTokens(day: unknown): number {
|
|
58
|
+
if (typeof day !== 'object' || day === null) return 0
|
|
59
|
+
let total = 0
|
|
60
|
+
for (const models of Object.values(day as Record<string, unknown>)) {
|
|
61
|
+
if (typeof models !== 'object' || models === null) continue
|
|
62
|
+
for (const bucket of Object.values(models as Record<string, unknown>)) {
|
|
63
|
+
if (typeof bucket !== 'object' || bucket === null) continue
|
|
64
|
+
for (const field of TOKEN_FIELDS) {
|
|
65
|
+
const value = (bucket as Record<string, unknown>)[field]
|
|
66
|
+
if (typeof value === 'number' && Number.isFinite(value) && value > 0) total += value
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return total
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Path of the usage ledger for this DSH home.
|
|
75
|
+
* @returns the absolute ledger path.
|
|
76
|
+
*/
|
|
77
|
+
export function spendLedgerPath(): string {
|
|
78
|
+
return join(dshHome(), 'dsh-usage', 'usage-ledger.json')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Tokens already spent today, or undefined when no measurement is available.
|
|
83
|
+
*
|
|
84
|
+
* Undefined is "cannot see", not "spent nothing": the caller fails open and
|
|
85
|
+
* reports it, because a spend cap that cannot read its own source must never
|
|
86
|
+
* decide that no work may run.
|
|
87
|
+
* @param now - clock instant (ms epoch).
|
|
88
|
+
* @param path - ledger path (test seam).
|
|
89
|
+
* @returns today's token total, or undefined when the ledger is unreadable.
|
|
90
|
+
*/
|
|
91
|
+
export function usedTokensToday(now: number = Date.now(), path: string = spendLedgerPath()): number | undefined {
|
|
92
|
+
try {
|
|
93
|
+
const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'))
|
|
94
|
+
const days = typeof parsed === 'object' && parsed !== null ? (parsed as { days?: unknown }).days : undefined
|
|
95
|
+
if (typeof days !== 'object' || days === null) return undefined
|
|
96
|
+
return ledgerDayTokens((days as Record<string, unknown>)[spendDateKey(now)])
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (!reportedUnmeasurable) {
|
|
99
|
+
reportedUnmeasurable = true
|
|
100
|
+
const detail = error instanceof Error ? error.message : String(error)
|
|
101
|
+
console.warn(`[dsh-task-board] spend cap cannot be measured from ${path}: ${detail}; runs are not gated until that ledger is readable`)
|
|
102
|
+
}
|
|
103
|
+
return undefined
|
|
104
|
+
}
|
|
105
|
+
}
|