@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.
Files changed (123) hide show
  1. package/NOTICE +1 -1
  2. package/README.en.md +4 -4
  3. package/README.md +4 -4
  4. package/README.zh.md +4 -4
  5. package/lib/client.js +4428 -1508
  6. package/lib/client.js.map +1 -1
  7. package/lib/index.js +2670 -496
  8. package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
  9. package/lib/types/client/PluginSettingsCard.d.ts +130 -19
  10. package/lib/types/client/RangeBubble.d.ts +46 -0
  11. package/lib/types/client/SegmentGroup.d.ts +28 -0
  12. package/lib/types/client/TaskBoardSettingsCard.d.ts +63 -0
  13. package/lib/types/client/board/AttachmentField.d.ts +70 -0
  14. package/lib/types/client/board/ExecutionLog.d.ts +24 -0
  15. package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
  16. package/lib/types/client/board/TaskForm.d.ts +4 -0
  17. package/lib/types/client/board/VerificationReport.d.ts +2 -15
  18. package/lib/types/client/board/model-options.d.ts +87 -0
  19. package/lib/types/client/board/preset-label.d.ts +21 -0
  20. package/lib/types/client/board/preset-roster.d.ts +45 -0
  21. package/lib/types/client/board/source-group.d.ts +27 -0
  22. package/lib/types/client/body-mutations.d.ts +45 -0
  23. package/lib/types/client/host-api.d.ts +25 -0
  24. package/lib/types/client/locales.d.ts +87 -9
  25. package/lib/types/client/pending-verify.d.ts +47 -0
  26. package/lib/types/client/plugin-card-seat.d.ts +3 -1
  27. package/lib/types/client/service.d.ts +4 -1
  28. package/lib/types/client/settings-form.d.ts +73 -51
  29. package/lib/types/core/attachment.d.ts +132 -0
  30. package/lib/types/core/card-defaults.d.ts +78 -0
  31. package/lib/types/core/controller.d.ts +57 -8
  32. package/lib/types/core/execution-summary.d.ts +52 -0
  33. package/lib/types/core/extension.d.ts +116 -0
  34. package/lib/types/core/launch-width.d.ts +31 -0
  35. package/lib/types/core/reasoning-effort.d.ts +57 -0
  36. package/lib/types/core/session-reuse.d.ts +7 -1
  37. package/lib/types/core/spend-budget.d.ts +28 -0
  38. package/lib/types/core/subtask.d.ts +100 -37
  39. package/lib/types/core/tasks.d.ts +94 -10
  40. package/lib/types/core/use-cases/task-create.d.ts +10 -5
  41. package/lib/types/core/use-cases/task-tag.d.ts +36 -0
  42. package/lib/types/core/use-cases/task-update.d.ts +22 -1
  43. package/lib/types/core/wire-projection.d.ts +35 -0
  44. package/lib/types/core/workspace-target.d.ts +23 -3
  45. package/lib/types/host/attachments.d.ts +250 -0
  46. package/lib/types/host/extension-registry.d.ts +40 -0
  47. package/lib/types/host/launch-admission.d.ts +71 -0
  48. package/lib/types/host-ledger.d.ts +114 -47
  49. package/lib/types/host-routes.d.ts +63 -0
  50. package/lib/types/host-runner.d.ts +164 -18
  51. package/lib/types/host-service.d.ts +182 -46
  52. package/lib/types/host-spend.d.ts +52 -0
  53. package/lib/types/index.d.ts +173 -54
  54. package/lib/types/loopback.d.ts +41 -1
  55. package/lib/types/protocol.d.ts +52 -11
  56. package/lib/types/tool-surface.d.ts +1 -0
  57. package/locale/en.json +6 -0
  58. package/locale/zh.json +6 -0
  59. package/package.json +35 -28
  60. package/src/client/CardDefaultPresetField.tsx +101 -0
  61. package/src/client/PluginSettingsCard.tsx +385 -111
  62. package/src/client/RangeBubble.tsx +164 -0
  63. package/src/client/SegmentGroup.tsx +93 -0
  64. package/src/client/TaskBoardSettingsCard.tsx +332 -37
  65. package/src/client/board/AttachmentField.tsx +383 -0
  66. package/src/client/board/EditTaskModal.tsx +63 -0
  67. package/src/client/board/ExecutionLog.tsx +154 -0
  68. package/src/client/board/LinkSubtaskModal.tsx +1 -1
  69. package/src/client/board/NewTaskModal.tsx +154 -45
  70. package/src/client/board/ReasoningEffortField.tsx +50 -0
  71. package/src/client/board/TagManagerModal.tsx +151 -2
  72. package/src/client/board/TaskBoard.tsx +47 -10
  73. package/src/client/board/TaskCard.tsx +45 -23
  74. package/src/client/board/TaskDetail.tsx +468 -258
  75. package/src/client/board/TaskForm.tsx +19 -4
  76. package/src/client/board/VerificationReport.tsx +143 -104
  77. package/src/client/board/model-options.ts +208 -0
  78. package/src/client/board/preset-label.ts +32 -0
  79. package/src/client/board/preset-roster.ts +58 -0
  80. package/src/client/board/source-group.ts +94 -0
  81. package/src/client/board/task-markdown.module.css +11 -8
  82. package/src/client/board-settings.module.css +35 -7
  83. package/src/client/board.module.css +1044 -105
  84. package/src/client/body-mutations.ts +133 -0
  85. package/src/client/host-api.ts +70 -0
  86. package/src/client/index.ts +109 -95
  87. package/src/client/locales.ts +205 -48
  88. package/src/client/pending-verify.ts +90 -0
  89. package/src/client/plugin-card-seat.ts +8 -2
  90. package/src/client/service.ts +24 -0
  91. package/src/client/settings-card.module.css +466 -89
  92. package/src/client/settings-entry-form.ts +0 -1
  93. package/src/client/settings-form.ts +102 -60
  94. package/src/core/attachment.ts +287 -0
  95. package/src/core/card-defaults.ts +132 -0
  96. package/src/core/controller.ts +90 -11
  97. package/src/core/execution-summary.ts +96 -0
  98. package/src/core/extension.ts +120 -0
  99. package/src/core/launch-width.ts +38 -0
  100. package/src/core/reasoning-effort.ts +92 -0
  101. package/src/core/session-reuse.ts +7 -1
  102. package/src/core/spend-budget.ts +35 -0
  103. package/src/core/store.ts +19 -1
  104. package/src/core/subtask.ts +144 -68
  105. package/src/core/tasks.ts +117 -10
  106. package/src/core/use-cases/task-create.ts +27 -16
  107. package/src/core/use-cases/task-tag.ts +56 -0
  108. package/src/core/use-cases/task-update.ts +33 -5
  109. package/src/core/wire-projection.ts +81 -0
  110. package/src/core/workspace-target.ts +27 -3
  111. package/src/host/agent-tools.ts +33 -21
  112. package/src/host/attachments.ts +650 -0
  113. package/src/host/extension-registry.ts +150 -5
  114. package/src/host/launch-admission.ts +139 -0
  115. package/src/host-ledger.ts +248 -117
  116. package/src/host-routes.ts +233 -15
  117. package/src/host-runner.ts +395 -61
  118. package/src/host-service.ts +512 -139
  119. package/src/host-spend.ts +105 -0
  120. package/src/index.ts +312 -92
  121. package/src/loopback.ts +57 -1
  122. package/src/protocol.ts +83 -18
  123. 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
+ }