dsh-plugin-inspiration-workbench 0.9.0 → 0.13.2
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 +27 -1
- package/lib/client.js +4191 -185
- package/lib/client.js.map +4 -4
- package/package.json +8 -2
- package/src/client/board.js +500 -30
- package/src/client/card-tools.js +1 -0
- package/src/client/docx-text.js +93 -0
- package/src/client/file-preview.js +103 -0
- package/src/client/file-store.js +74 -0
- package/src/client/flow-recorder.js +58 -0
- package/src/client/index.jsx +3 -4
- package/src/client/persistence.js +31 -0
- package/src/client/popovers.js +2 -2
- package/src/client/render.js +1 -0
- package/src/client/sessions.js +91 -11
- package/src/client/styles.css +116 -2
- package/src/client/task-ai.js +83 -0
- package/src/client/task-controller.js +620 -0
- package/src/client/task-intelligence.js +545 -0
- package/src/client/task-model.js +264 -0
- package/src/client/task-store.js +118 -0
- package/src/client/task-view.css +1263 -0
- package/src/client/task-view.js +1688 -0
- package/src/host/index.js +69 -7
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure task-domain helpers. This module deliberately has no DOM, clock, or
|
|
3
|
+
* storage dependencies so persisted data can be normalized deterministically.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const EXECUTION_STATUSES = Object.freeze([
|
|
7
|
+
'idle',
|
|
8
|
+
'running',
|
|
9
|
+
'needs_input',
|
|
10
|
+
'blocked',
|
|
11
|
+
'done',
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
export const ACCEPTANCE_STATUSES = Object.freeze([
|
|
15
|
+
'pending',
|
|
16
|
+
'review',
|
|
17
|
+
'accepted',
|
|
18
|
+
'rejected',
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
export const TASK_STATUSES = Object.freeze([
|
|
22
|
+
'needs_input',
|
|
23
|
+
'blocked',
|
|
24
|
+
'review',
|
|
25
|
+
'running',
|
|
26
|
+
'idle',
|
|
27
|
+
'done',
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const STATUS_RANK = Object.freeze({
|
|
31
|
+
needs_input: 0,
|
|
32
|
+
blocked: 1,
|
|
33
|
+
review: 2,
|
|
34
|
+
running: 3,
|
|
35
|
+
idle: 4,
|
|
36
|
+
done: 5,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const EXECUTION_ALIASES = Object.freeze({
|
|
40
|
+
idle: 'idle',
|
|
41
|
+
pending: 'idle',
|
|
42
|
+
queued: 'idle',
|
|
43
|
+
waiting: 'idle',
|
|
44
|
+
cancelled: 'idle',
|
|
45
|
+
canceled: 'idle',
|
|
46
|
+
running: 'running',
|
|
47
|
+
active: 'running',
|
|
48
|
+
in_progress: 'running',
|
|
49
|
+
needs_input: 'needs_input',
|
|
50
|
+
need_input: 'needs_input',
|
|
51
|
+
waiting_input: 'needs_input',
|
|
52
|
+
awaiting_input: 'needs_input',
|
|
53
|
+
question: 'needs_input',
|
|
54
|
+
approval: 'needs_input',
|
|
55
|
+
blocked: 'blocked',
|
|
56
|
+
failed: 'blocked',
|
|
57
|
+
failure: 'blocked',
|
|
58
|
+
error: 'blocked',
|
|
59
|
+
done: 'done',
|
|
60
|
+
complete: 'done',
|
|
61
|
+
completed: 'done',
|
|
62
|
+
succeeded: 'done',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const ACCEPTANCE_ALIASES = Object.freeze({
|
|
66
|
+
pending: 'pending',
|
|
67
|
+
none: 'pending',
|
|
68
|
+
not_submitted: 'pending',
|
|
69
|
+
review: 'review',
|
|
70
|
+
in_review: 'review',
|
|
71
|
+
awaiting_review: 'review',
|
|
72
|
+
accepted: 'accepted',
|
|
73
|
+
accept: 'accepted',
|
|
74
|
+
approved: 'accepted',
|
|
75
|
+
passed: 'accepted',
|
|
76
|
+
not_required: 'accepted',
|
|
77
|
+
rejected: 'rejected',
|
|
78
|
+
denied: 'rejected',
|
|
79
|
+
changes_requested: 'rejected',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
function object(value) {
|
|
83
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function text(value) {
|
|
87
|
+
if (typeof value === 'string') return value.trim();
|
|
88
|
+
if (typeof value === 'number' && Number.isFinite(value)) return String(value);
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function token(value) {
|
|
93
|
+
return text(value).toLowerCase().replace(/[\s-]+/g, '_');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function executionStatus(value) {
|
|
97
|
+
return EXECUTION_ALIASES[token(value)] || 'idle';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function acceptanceStatus(value) {
|
|
101
|
+
return ACCEPTANCE_ALIASES[token(value)] || 'pending';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function statusesOf(value) {
|
|
105
|
+
const task = object(value);
|
|
106
|
+
const execution = object(task.execution);
|
|
107
|
+
const acceptance = object(task.acceptance);
|
|
108
|
+
const executionValue = task.executionStatus ?? execution.status;
|
|
109
|
+
const acceptanceValue = task.acceptanceStatus ?? acceptance.status;
|
|
110
|
+
const overall = token(task.status);
|
|
111
|
+
|
|
112
|
+
let normalizedExecution;
|
|
113
|
+
if (executionValue != null) {
|
|
114
|
+
normalizedExecution = executionStatus(executionValue);
|
|
115
|
+
} else if (overall === 'review' || overall === 'done') {
|
|
116
|
+
normalizedExecution = 'done';
|
|
117
|
+
} else {
|
|
118
|
+
normalizedExecution = executionStatus(overall);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let normalizedAcceptance;
|
|
122
|
+
if (acceptanceValue != null) {
|
|
123
|
+
normalizedAcceptance = acceptanceStatus(acceptanceValue);
|
|
124
|
+
} else if (overall === 'review') {
|
|
125
|
+
normalizedAcceptance = 'review';
|
|
126
|
+
} else if (overall === 'done') {
|
|
127
|
+
normalizedAcceptance = 'accepted';
|
|
128
|
+
} else {
|
|
129
|
+
normalizedAcceptance = 'pending';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
executionStatus: normalizedExecution,
|
|
134
|
+
acceptanceStatus: normalizedAcceptance,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Derive the single display/work-queue status without collapsing the two
|
|
140
|
+
* persisted dimensions. Completed work is reviewed until explicitly accepted;
|
|
141
|
+
* rejected work returns to idle for another execution cycle.
|
|
142
|
+
*/
|
|
143
|
+
export function deriveTaskStatus(task) {
|
|
144
|
+
const { executionStatus: execution, acceptanceStatus: acceptance } = statusesOf(task);
|
|
145
|
+
if (execution === 'needs_input') return 'needs_input';
|
|
146
|
+
if (execution === 'blocked') return 'blocked';
|
|
147
|
+
if (acceptance === 'review') return 'review';
|
|
148
|
+
if (execution === 'running') return 'running';
|
|
149
|
+
if (execution === 'done' && acceptance === 'accepted') return 'done';
|
|
150
|
+
if (execution === 'done' && acceptance !== 'rejected') return 'review';
|
|
151
|
+
return 'idle';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Normalize one task while preserving domain fields owned by other modules. */
|
|
155
|
+
export function normalizeTask(value) {
|
|
156
|
+
const task = object(value);
|
|
157
|
+
const statuses = statusesOf(task);
|
|
158
|
+
return {
|
|
159
|
+
...task,
|
|
160
|
+
id: text(task.id),
|
|
161
|
+
title: text(task.title),
|
|
162
|
+
description: text(task.description),
|
|
163
|
+
...statuses,
|
|
164
|
+
status: deriveTaskStatus(statuses),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function compareText(left, right) {
|
|
169
|
+
if (left < right) return -1;
|
|
170
|
+
if (left > right) return 1;
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function numericOrder(task) {
|
|
175
|
+
const value = Number(task.order);
|
|
176
|
+
return task.order !== '' && task.order != null && Number.isFinite(value) ? value : 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Return normalized tasks in work-queue order. Actionable states come first;
|
|
181
|
+
* explicit order, id, title, then original position provide deterministic ties.
|
|
182
|
+
* Neither the input array nor any task object is mutated.
|
|
183
|
+
*/
|
|
184
|
+
export function sortTasks(value) {
|
|
185
|
+
if (!Array.isArray(value)) return [];
|
|
186
|
+
return value
|
|
187
|
+
.map((task, index) => ({ task: normalizeTask(task), index }))
|
|
188
|
+
.sort((left, right) => {
|
|
189
|
+
const a = left.task;
|
|
190
|
+
const b = right.task;
|
|
191
|
+
return (STATUS_RANK[a.status] - STATUS_RANK[b.status])
|
|
192
|
+
|| (numericOrder(a) - numericOrder(b))
|
|
193
|
+
|| compareText(a.id, b.id)
|
|
194
|
+
|| compareText(a.title, b.title)
|
|
195
|
+
|| (left.index - right.index);
|
|
196
|
+
})
|
|
197
|
+
.map(({ task }) => task);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function timestamp(value) {
|
|
201
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
|
202
|
+
const raw = text(value);
|
|
203
|
+
if (!raw) return 0;
|
|
204
|
+
if (Number.isFinite(Number(raw))) return Number(raw);
|
|
205
|
+
const parsed = Date.parse(raw);
|
|
206
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function sequence(value, fallback) {
|
|
210
|
+
const parsed = Number(value);
|
|
211
|
+
return value !== '' && value != null && Number.isFinite(parsed) ? parsed : fallback;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Normalize a flow event. Missing/invalid timestamps become zero rather than
|
|
216
|
+
* the current time, keeping replay pure. Invalid events return null.
|
|
217
|
+
*/
|
|
218
|
+
export function normalizeFlowEvent(value, fallbackSequence = 0) {
|
|
219
|
+
const event = object(value);
|
|
220
|
+
const edgeKey = text(event.edgeKey);
|
|
221
|
+
const state = text(event.state ?? event.status ?? event.toStatus ?? event.to);
|
|
222
|
+
if (!edgeKey || !state) return null;
|
|
223
|
+
return {
|
|
224
|
+
...event,
|
|
225
|
+
id: text(event.id ?? event.eventId),
|
|
226
|
+
edgeKey,
|
|
227
|
+
state,
|
|
228
|
+
timestamp: timestamp(event.timestamp ?? event.at ?? event.updatedAt ?? event.createdAt ?? event.time),
|
|
229
|
+
sequence: sequence(event.sequence ?? event.seq, fallbackSequence),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Project the newest normalized event for every edgeKey. Timestamp wins, then
|
|
235
|
+
* explicit sequence, then input order. Invalid events are ignored.
|
|
236
|
+
*/
|
|
237
|
+
export function projectFlowEvents(value) {
|
|
238
|
+
if (!Array.isArray(value)) return {};
|
|
239
|
+
const latest = new Map();
|
|
240
|
+
value.forEach((raw, index) => {
|
|
241
|
+
const event = normalizeFlowEvent(raw, index);
|
|
242
|
+
if (!event) return;
|
|
243
|
+
const previous = latest.get(event.edgeKey);
|
|
244
|
+
const newer = !previous
|
|
245
|
+
|| event.timestamp > previous.event.timestamp
|
|
246
|
+
|| (event.timestamp === previous.event.timestamp && event.sequence > previous.event.sequence)
|
|
247
|
+
|| (event.timestamp === previous.event.timestamp
|
|
248
|
+
&& event.sequence === previous.event.sequence
|
|
249
|
+
&& index > previous.index);
|
|
250
|
+
if (newer) latest.set(event.edgeKey, { event, index });
|
|
251
|
+
});
|
|
252
|
+
return Object.fromEntries(
|
|
253
|
+
[...latest.entries()]
|
|
254
|
+
.sort(([left], [right]) => compareText(left, right))
|
|
255
|
+
.map(([edgeKey, { event }]) => [edgeKey, event]),
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Project only the newest state string for every edgeKey. */
|
|
260
|
+
export function projectFlowStates(events) {
|
|
261
|
+
return Object.fromEntries(
|
|
262
|
+
Object.entries(projectFlowEvents(events)).map(([edgeKey, event]) => [edgeKey, event.state]),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { fetchTaskState, pushTaskState, subscribeRemoteLayout } from './persistence.js';
|
|
2
|
+
|
|
3
|
+
const TASK_STORAGE_KEY = 'dsh.inspiration-workbench.tasks.v1';
|
|
4
|
+
|
|
5
|
+
/** Task metadata + flow history, with an offline local copy and Host convergence. */
|
|
6
|
+
export function createTaskStore(options = {}) {
|
|
7
|
+
const clientId = options.clientId || Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
8
|
+
const storage = options.storage || (typeof window !== 'undefined' ? window.localStorage : null);
|
|
9
|
+
const fetchRemote = options.fetchRemote || fetchTaskState;
|
|
10
|
+
const pushRemote = options.pushRemote || pushTaskState;
|
|
11
|
+
const subscribe = options.subscribe || subscribeRemoteLayout;
|
|
12
|
+
const listeners = new Set();
|
|
13
|
+
let tasks = [];
|
|
14
|
+
let flowEvents = [];
|
|
15
|
+
let updatedAt = 0;
|
|
16
|
+
let rev = 0;
|
|
17
|
+
let saveTimer = 0;
|
|
18
|
+
let disposed = false;
|
|
19
|
+
let stopSync = null;
|
|
20
|
+
|
|
21
|
+
function snapshot() {
|
|
22
|
+
return { tasks: tasks.slice(), flowEvents: flowEvents.slice(), updatedAt, rev };
|
|
23
|
+
}
|
|
24
|
+
function notify() {
|
|
25
|
+
const value = snapshot();
|
|
26
|
+
for (const listener of listeners) listener(value);
|
|
27
|
+
}
|
|
28
|
+
function readLocal() {
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(storage?.getItem(TASK_STORAGE_KEY) || 'null');
|
|
31
|
+
if (!parsed || typeof parsed !== 'object') return null;
|
|
32
|
+
return {
|
|
33
|
+
tasks: Array.isArray(parsed.tasks) ? parsed.tasks : [],
|
|
34
|
+
flowEvents: Array.isArray(parsed.flowEvents) ? parsed.flowEvents : [],
|
|
35
|
+
updatedAt: Number(parsed.updatedAt) || 0,
|
|
36
|
+
};
|
|
37
|
+
} catch { return null; }
|
|
38
|
+
}
|
|
39
|
+
function writeLocal() {
|
|
40
|
+
try { storage?.setItem(TASK_STORAGE_KEY, JSON.stringify({ tasks, flowEvents, updatedAt })); } catch { /* Host may still save */ }
|
|
41
|
+
}
|
|
42
|
+
function adopt(value) {
|
|
43
|
+
tasks = Array.isArray(value?.tasks) ? value.tasks : [];
|
|
44
|
+
flowEvents = Array.isArray(value?.flowEvents) ? value.flowEvents : [];
|
|
45
|
+
updatedAt = Number(value?.updatedAt) || 0;
|
|
46
|
+
rev = Number(value?.rev) || rev;
|
|
47
|
+
writeLocal();
|
|
48
|
+
notify();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function load() {
|
|
52
|
+
const local = readLocal();
|
|
53
|
+
if (local) adopt(local);
|
|
54
|
+
const remote = await fetchRemote();
|
|
55
|
+
if (remote && Number(remote.updatedAt) >= updatedAt) adopt(remote);
|
|
56
|
+
if (!stopSync) {
|
|
57
|
+
stopSync = subscribe((nextRev, sourceId) => {
|
|
58
|
+
if (disposed || nextRev === rev || (sourceId && sourceId === clientId) || saveTimer) return;
|
|
59
|
+
rev = nextRev;
|
|
60
|
+
void fetchRemote().then((remoteState) => {
|
|
61
|
+
if (remoteState && Number(remoteState.updatedAt) > updatedAt && !saveTimer) adopt(remoteState);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return snapshot();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function saveSoon() {
|
|
69
|
+
if (disposed) return;
|
|
70
|
+
updatedAt = Date.now();
|
|
71
|
+
writeLocal();
|
|
72
|
+
notify();
|
|
73
|
+
clearTimeout(saveTimer);
|
|
74
|
+
saveTimer = setTimeout(async () => {
|
|
75
|
+
saveTimer = 0;
|
|
76
|
+
const result = await pushRemote(tasks, flowEvents, clientId);
|
|
77
|
+
if (result?.rev) rev = result.rev;
|
|
78
|
+
if (result?.updatedAt) updatedAt = result.updatedAt;
|
|
79
|
+
}, 220);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
snapshot,
|
|
84
|
+
load,
|
|
85
|
+
saveSoon,
|
|
86
|
+
subscribe(listener) {
|
|
87
|
+
listeners.add(listener);
|
|
88
|
+
return () => listeners.delete(listener);
|
|
89
|
+
},
|
|
90
|
+
setTasks(next) { tasks = Array.isArray(next) ? next : []; saveSoon(); },
|
|
91
|
+
addTasks(next) {
|
|
92
|
+
const additions = Array.isArray(next) ? next : [];
|
|
93
|
+
if (!additions.length) return;
|
|
94
|
+
const byId = new Map(tasks.map((task) => [task.id, task]));
|
|
95
|
+
for (const task of additions) byId.set(task.id, { ...byId.get(task.id), ...task });
|
|
96
|
+
tasks = [...byId.values()];
|
|
97
|
+
saveSoon();
|
|
98
|
+
},
|
|
99
|
+
updateTask(id, patch) {
|
|
100
|
+
tasks = tasks.map((task) => task.id === id ? { ...task, ...patch, id, updatedAt: Date.now() } : task);
|
|
101
|
+
saveSoon();
|
|
102
|
+
},
|
|
103
|
+
removeTask(id) { tasks = tasks.filter((task) => task.id !== id); saveSoon(); },
|
|
104
|
+
setFlowEvents(next) { flowEvents = Array.isArray(next) ? next.slice(-500) : []; saveSoon(); },
|
|
105
|
+
async flush() {
|
|
106
|
+
clearTimeout(saveTimer);
|
|
107
|
+
saveTimer = 0;
|
|
108
|
+
return await pushRemote(tasks, flowEvents, clientId);
|
|
109
|
+
},
|
|
110
|
+
dispose() {
|
|
111
|
+
disposed = true;
|
|
112
|
+
clearTimeout(saveTimer);
|
|
113
|
+
stopSync?.();
|
|
114
|
+
stopSync = null;
|
|
115
|
+
listeners.clear();
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|