@linxin666/dsh-client-ui-task-board 0.4.12 → 0.4.14

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 (61) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +9 -3
  3. package/README.zh.md +9 -3
  4. package/lib/client.js +1476 -478
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +1280 -65
  7. package/lib/types/client/board/AttachmentField.d.ts +70 -0
  8. package/lib/types/client/board/model-options.d.ts +21 -1
  9. package/lib/types/client/board/source-group.d.ts +27 -0
  10. package/lib/types/client/host-api.d.ts +25 -0
  11. package/lib/types/client/locales.d.ts +17 -0
  12. package/lib/types/client/pending-verify.d.ts +47 -0
  13. package/lib/types/client/service.d.ts +4 -1
  14. package/lib/types/core/attachment.d.ts +132 -0
  15. package/lib/types/core/controller.d.ts +26 -2
  16. package/lib/types/core/extension.d.ts +82 -0
  17. package/lib/types/core/session-reuse.d.ts +7 -1
  18. package/lib/types/core/tasks.d.ts +38 -1
  19. package/lib/types/core/use-cases/task-update.d.ts +21 -0
  20. package/lib/types/core/wire-projection.d.ts +35 -0
  21. package/lib/types/host/attachments.d.ts +250 -0
  22. package/lib/types/host/extension-registry.d.ts +40 -0
  23. package/lib/types/host-ledger.d.ts +16 -0
  24. package/lib/types/host-routes.d.ts +14 -0
  25. package/lib/types/host-runner.d.ts +53 -1
  26. package/lib/types/host-service.d.ts +59 -0
  27. package/lib/types/index.d.ts +23 -0
  28. package/lib/types/protocol.d.ts +39 -6
  29. package/locale/en.json +6 -0
  30. package/locale/zh.json +6 -0
  31. package/package.json +6 -2
  32. package/src/client/TaskBoardSettingsCard.tsx +11 -1
  33. package/src/client/board/AttachmentField.tsx +383 -0
  34. package/src/client/board/EditTaskModal.tsx +63 -0
  35. package/src/client/board/NewTaskModal.tsx +76 -4
  36. package/src/client/board/TaskBoard.tsx +47 -10
  37. package/src/client/board/TaskDetail.tsx +30 -2
  38. package/src/client/board/model-options.ts +32 -2
  39. package/src/client/board/source-group.ts +94 -0
  40. package/src/client/board.module.css +83 -0
  41. package/src/client/host-api.ts +70 -0
  42. package/src/client/index.ts +11 -0
  43. package/src/client/locales.ts +34 -0
  44. package/src/client/pending-verify.ts +90 -0
  45. package/src/client/service.ts +24 -0
  46. package/src/core/attachment.ts +287 -0
  47. package/src/core/controller.ts +47 -1
  48. package/src/core/extension.ts +86 -0
  49. package/src/core/session-reuse.ts +7 -1
  50. package/src/core/store.ts +10 -1
  51. package/src/core/tasks.ts +49 -0
  52. package/src/core/use-cases/task-update.ts +27 -2
  53. package/src/core/wire-projection.ts +81 -0
  54. package/src/host/attachments.ts +650 -0
  55. package/src/host/extension-registry.ts +150 -5
  56. package/src/host-ledger.ts +32 -4
  57. package/src/host-routes.ts +168 -13
  58. package/src/host-runner.ts +124 -4
  59. package/src/host-service.ts +165 -12
  60. package/src/index.ts +47 -0
  61. package/src/protocol.ts +57 -9
package/src/core/tasks.ts CHANGED
@@ -8,6 +8,7 @@ import type { FreezeSnapshot } from './freeze-snapshot.ts'
8
8
  import type { ExecutionVerification } from './verification.ts'
9
9
  import type { TaskHandover, TaskHandoverInput } from './handover.ts'
10
10
  import { normalizeTaskIntegrations, type TaskBoardExtensionPayload } from './extension.ts'
11
+ import { normalizeAttachments, type TaskAttachment } from './attachment.ts'
11
12
 
12
13
  /** Task lifecycle status, one per kanban column. */
13
14
  export type TaskStatus = 'backlog' | 'todo' | 'running' | 'done' | 'failed'
@@ -38,6 +39,27 @@ export interface ExecutionSummary {
38
39
  */
39
40
  export const EXECUTION_SUMMARY_LIMIT = 4000
40
41
 
42
+ /**
43
+ * Rework input recorded on the execution it opened: the reviewer's instructions
44
+ * for redoing work in the card's own session.
45
+ */
46
+ export interface ExecutionRework {
47
+ /** The rework instructions this run was given, as the reviewer wrote them. */
48
+ instructions: string
49
+ }
50
+
51
+ /**
52
+ * Repair a persisted rework block: only a non-blank instruction string
53
+ * survives, so a hand-edited ledger loses the block instead of the execution.
54
+ */
55
+ export function normalizeExecutionRework(value: unknown): ExecutionRework | undefined {
56
+ if (typeof value !== 'object' || value === null) return undefined
57
+ const instructions = (value as { instructions?: unknown }).instructions
58
+ if (typeof instructions !== 'string') return undefined
59
+ const trimmed = instructions.trim()
60
+ return trimmed === '' ? undefined : { instructions: trimmed }
61
+ }
62
+
41
63
  /**
42
64
  * One real execution attempt: the run's own id, the dsh session that ran it
43
65
  * (filled once the session is created), and the settled outcome once the
@@ -77,6 +99,13 @@ export interface ExecutionRecord {
77
99
  * `sessionId` and never claims a verdict the Host observed.
78
100
  */
79
101
  external?: boolean
102
+ /**
103
+ * Rework instructions this execution carries as extra input: a reviewer sent
104
+ * the previous run back, so the card re-ran in the same session with these
105
+ * instructions instead of having its frozen content rewritten. Absent on
106
+ * every ordinary run.
107
+ */
108
+ rework?: ExecutionRework
80
109
  /** Freeze instant captured from the card snapshot when the run opened. */
81
110
  frozenAt?: number
82
111
  /** Freeze source session captured from the card snapshot when the run opened. */
@@ -535,6 +564,14 @@ export interface TaskRecord {
535
564
  * absent means on-board.
536
565
  */
537
566
  hidden?: boolean
567
+ /**
568
+ * Files and images the card carries (issue #1979). Metadata only: the bytes
569
+ * live in the official attachment storage, and this record names the stored
570
+ * object, its size and the digest of the exact bytes the Host verified
571
+ * there. Additive and absent on every card written before the field
572
+ * existed, so an old card keeps running exactly as it did.
573
+ */
574
+ attachments?: TaskAttachment[]
538
575
  }
539
576
 
540
577
  /**
@@ -636,6 +673,12 @@ export interface NewTaskInput {
636
673
  status?: TaskStatus
637
674
  /** Create the card off-board (held in the ledger, never rendered). */
638
675
  hidden?: boolean
676
+ /**
677
+ * Files and images the new card carries (issue #1979). The metadata is
678
+ * host-verified against the official attachment storage before it reaches
679
+ * the ledger, so a create never records a claim the storage cannot prove.
680
+ */
681
+ attachments?: TaskAttachment[]
639
682
  }
640
683
 
641
684
  /** The five kanban columns, in display order. */
@@ -734,6 +777,7 @@ export function freezeOf(
734
777
  export function createTask(input: NewTaskInput, now: number, id: string): TaskRecord {
735
778
  const tags = normalizeTags(input.tags)
736
779
  const integrations = normalizeTaskIntegrations(input.integrations)
780
+ const attachments = normalizeAttachments(input.attachments)
737
781
  return {
738
782
  id,
739
783
  title: input.title.trim(),
@@ -762,6 +806,7 @@ export function createTask(input: NewTaskInput, now: number, id: string): TaskRe
762
806
  ...(input.handover === undefined ? {} : { handover: { ...input.handover, bundledAt: now } }),
763
807
  ...(tags === undefined ? {} : { tags }),
764
808
  ...(integrations === undefined ? {} : { integrations }),
809
+ ...(attachments === undefined ? {} : { attachments }),
765
810
  ...(input.hidden === true ? { hidden: true } : {}),
766
811
  }
767
812
  }
@@ -811,6 +856,8 @@ export function withSchedule(
811
856
  * running execution record. Returns the new task and the new execution.
812
857
  * @param runGroupId - cascade run group, when this run also opened executions
813
858
  * for the task's subtasks (see `core/subtask.ts`).
859
+ * @param rework - the reviewer's instructions, when this run is a rework of the
860
+ * card's previous work; recorded on the execution it opens.
814
861
  */
815
862
  export function startExecution(
816
863
  task: TaskRecord,
@@ -818,6 +865,7 @@ export function startExecution(
818
865
  executionId: string,
819
866
  initiatedBy?: string,
820
867
  runGroupId?: string,
868
+ rework?: ExecutionRework,
821
869
  ): { task: TaskRecord; execution: ExecutionRecord } {
822
870
  const execution: ExecutionRecord = {
823
871
  id: executionId,
@@ -826,6 +874,7 @@ export function startExecution(
826
874
  endedAt: undefined,
827
875
  result: undefined,
828
876
  error: undefined,
877
+ ...(rework === undefined ? {} : { rework }),
829
878
  ...(runGroupId === undefined || runGroupId === '' ? {} : { runGroupId }),
830
879
  ...(initiatedBy === undefined || initiatedBy === '' ? {} : { initiatedBy }),
831
880
  // Capture the card's freeze provenance on the execution record so the
@@ -9,6 +9,7 @@
9
9
  * stale UI can never persist a value the execution service rejects.
10
10
  */
11
11
  import { freezeOf, isTaskPermission, normalizeTags, normalizeTargetId, type TaskRecord, type TaskPermission, type TaskTag } from '../tasks.ts'
12
+ import { normalizeAttachments, type TaskAttachment } from '../attachment.ts'
12
13
  import type { FreezeSnapshot } from '../freeze-snapshot.ts'
13
14
  import type { TaskHandoverInput } from '../handover.ts'
14
15
 
@@ -27,6 +28,15 @@ export type TaskUpdatePatch = Partial<Pick<TaskRecord, 'title' | 'description' |
27
28
  * explicit null (or a list that normalizes to nothing) clears them.
28
29
  */
29
30
  tags?: TaskTag[] | null
31
+ /**
32
+ * Replaces the card's attachments (issue #1979).
33
+ *
34
+ * The attachments freeze WITH the card content: they are part of what the
35
+ * card hands to its execution, so an executed or archived card keeps the
36
+ * ones it ran with, exactly as it keeps the prompt it ran with. An explicit
37
+ * null clears them; a present array replaces the whole set.
38
+ */
39
+ attachments?: TaskAttachment[] | null
30
40
  }
31
41
 
32
42
  /** The fields that edit the task's content (what the user reads and what the
@@ -36,9 +46,21 @@ export type TaskUpdatePatch = Partial<Pick<TaskRecord, 'title' | 'description' |
36
46
  */
37
47
  export const TASK_CONTENT_FIELDS = ['title', 'description', 'prompt'] as const
38
48
 
49
+ /**
50
+ * The fields that freeze with the card content: the text the card says AND
51
+ * the attachments it carries.
52
+ *
53
+ * The attachments freeze with the content because they ARE part of what the
54
+ * card hands to its execution: a card whose first run already consumed an
55
+ * image keeps that image, and the record of what ran stays what it was. An
56
+ * executed or archived card therefore refuses an attachment change exactly
57
+ * as it refuses a prompt change.
58
+ */
59
+ export const TASK_FROZEN_FIELDS = [...TASK_CONTENT_FIELDS, 'attachments'] as const
60
+
39
61
  /** Whether an update patch touches any task-content field. */
40
62
  export function hasContentPatch(patch: TaskUpdatePatch): boolean {
41
- return (TASK_CONTENT_FIELDS as readonly string[]).some(field => field in patch)
63
+ return (TASK_FROZEN_FIELDS as readonly string[]).some(field => field in patch)
42
64
  }
43
65
 
44
66
  /**
@@ -77,7 +99,7 @@ export function applyUpdateTask(
77
99
  ): readonly TaskRecord[] {
78
100
  return tasks.map(task => {
79
101
  if (task.id !== id) return task
80
- const { freeze: freezePatch, handover: handoverPatch, tags: tagsPatch, ...rest } = patch
102
+ const { freeze: freezePatch, handover: handoverPatch, tags: tagsPatch, attachments: attachmentsPatch, ...rest } = patch
81
103
  const workspaceId = 'workspaceId' in patch ? normalizeTargetId(patch.workspaceId) : undefined
82
104
  const mode = 'mode' in patch ? normalizeTargetId(patch.mode) : undefined
83
105
  const permission = 'permission' in patch ? normalizePermission(task.permission, patch.permission) : undefined
@@ -99,6 +121,9 @@ export function applyUpdateTask(
99
121
  // Tags use the same convention: a present array replaces the set (after
100
122
  // repair), an explicit null or a fully-invalid list clears it.
101
123
  if ('tags' in patch) next.tags = tagsPatch == null ? undefined : normalizeTags(tagsPatch)
124
+ // Attachments follow the same convention: a present array replaces the
125
+ // whole set (after repair), an explicit null clears it.
126
+ if ('attachments' in patch) next.attachments = attachmentsPatch == null ? undefined : normalizeAttachments(attachmentsPatch)
102
127
  // The permission confirmation binds the exact permission value: a change
103
128
  // of the pinned permission or of the handover bundle re-arms the gate
104
129
  // (blocking confirm-then-swap escalation). handover was destructured out
@@ -0,0 +1,81 @@
1
+ /**
2
+ * What an extension's `integrations` container looks like once it leaves the
3
+ * Host.
4
+ *
5
+ * The container is provider-owned and crosses the board unread, and it also
6
+ * crosses the wire: the HTTP snapshot, every action answer, and the remote
7
+ * bridge's `board.snapshot` all carry it. A credential a provider stored there
8
+ * would therefore reach every browser and phone paired to this Host. This
9
+ * module is the one place that decides otherwise: the ledger keeps the payload
10
+ * verbatim (the provider reads it back through its in-process capability face,
11
+ * and a Host-side consumer reads the ledger itself), while the copy that leaves
12
+ * carries no credential.
13
+ *
14
+ * @module dsh-task-board/core/wire-projection
15
+ */
16
+ import type { TaskBoardSnapshot } from '../protocol.ts'
17
+ import type { TaskBoardExtensionPayload } from './extension.ts'
18
+ import type { TaskRecord } from './tasks.ts'
19
+
20
+ /**
21
+ * Keys stripped from an integration payload at every depth, as whole keys and
22
+ * compared case-insensitively.
23
+ *
24
+ * `leaseToken` is the name `dsh-task-board-team` writes for its mirror-card
25
+ * lease and `lease_token` the snake spelling, while the rest are the generic
26
+ * names a bearer credential hides under. The match is the whole key rather than
27
+ * a substring: a payload field that merely mentions one of these words while
28
+ * holding something the provider's own UI renders is not a credential and must
29
+ * keep travelling.
30
+ */
31
+ const CREDENTIAL_KEYS: ReadonlySet<string> = new Set([
32
+ 'leasetoken',
33
+ 'lease_token',
34
+ 'token',
35
+ 'secret',
36
+ 'password',
37
+ 'apikey',
38
+ 'credential',
39
+ ])
40
+
41
+ /** Copy one JSON value with every credential-keyed entry removed, at any depth. */
42
+ function withoutCredentials(value: unknown): unknown {
43
+ if (Array.isArray(value)) return value.map(withoutCredentials)
44
+ if (value === null || typeof value !== 'object') return value
45
+ const copy: Record<string, unknown> = {}
46
+ for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {
47
+ if (CREDENTIAL_KEYS.has(key.toLowerCase())) continue
48
+ copy[key] = withoutCredentials(entry)
49
+ }
50
+ return copy
51
+ }
52
+
53
+ /**
54
+ * The card as the wire may show it: the ledger record with its integration
55
+ * entries copied and stripped.
56
+ *
57
+ * A card that carries no integrations is returned untouched, so a provider that
58
+ * stores nothing sees exactly the record the board has always published.
59
+ * @param task - the ledger record about to be serialized.
60
+ * @returns the projected record; the ledger object is never mutated.
61
+ */
62
+ export function projectTaskForWire(task: TaskRecord): TaskRecord {
63
+ const stored = task.integrations
64
+ if (stored === undefined) return task
65
+ const integrations: Record<string, TaskBoardExtensionPayload> = {}
66
+ for (const [id, payload] of Object.entries(stored)) {
67
+ integrations[id] = withoutCredentials(payload) as TaskBoardExtensionPayload
68
+ }
69
+ return { ...task, integrations }
70
+ }
71
+
72
+ /**
73
+ * The snapshot as every read path serializes it: the HTTP `state` answer, the
74
+ * HTTP `action` answer, and the remote bridge's `board.snapshot` all start from
75
+ * the object this returns.
76
+ * @param snapshot - the snapshot the Host service built from its live state.
77
+ * @returns the same snapshot with each card projected through {@link projectTaskForWire}.
78
+ */
79
+ export function projectSnapshotForWire(snapshot: TaskBoardSnapshot): TaskBoardSnapshot {
80
+ return { ...snapshot, tasks: snapshot.tasks.map(projectTaskForWire) }
81
+ }