dsh-taskbridge 1.8.0 → 1.9.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 (50) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +246 -231
  3. package/antigravity/agents/dsh-taskbridge.md +17 -14
  4. package/antigravity/skills/dsh-taskbridge/SKILL.md +40 -27
  5. package/bin/dsh-delegate-codex-agent.js +9 -4
  6. package/codex/skills/dsh-taskbridge/SKILL.md +131 -0
  7. package/codex/skills/dsh-taskbridge/rules-reference-96027c387cb9b7587efa4aa3836235d86db1108068e007dc08196e807ca25e5d.md +114 -0
  8. package/docs/INTRODUCTION.md +148 -119
  9. package/docs/INTRODUCTION.zh.md +151 -134
  10. package/docs/antigravity-integration.md +47 -42
  11. package/docs/assets/taskbridge-workflow.en.svg +72 -0
  12. package/docs/assets/taskbridge-workflow.zh.png +0 -0
  13. package/docs/claude-code.md +18 -18
  14. package/docs/codex-integration.md +139 -113
  15. package/docs/conversation-placement.md +7 -6
  16. package/docs/releases/1.8.0.zh.md +16 -16
  17. package/docs/releases/1.8.1.zh.md +24 -0
  18. package/docs/releases/1.9.0.zh.md +31 -0
  19. package/docs/runtime-compatibility.md +7 -9
  20. package/docs/silent-wait.md +17 -26
  21. package/docs/taskbridge-upgrade.md +4 -4
  22. package/lib/client.d.ts +74 -3
  23. package/lib/client.js +7 -7
  24. package/locale/en.json +7 -7
  25. package/locale/zh.json +7 -7
  26. package/package.json +11 -4
  27. package/src/antigravity/installer.js +1099 -1046
  28. package/src/antigravity/seam.js +142 -142
  29. package/src/client/api.js +258 -16
  30. package/src/client/index.jsx +130 -26
  31. package/src/client/task-cleanup.js +130 -5
  32. package/src/codex/agent-ownership.js +72 -12
  33. package/src/codex/installer.js +691 -268
  34. package/src/config/defaults.js +11 -15
  35. package/src/http/execution-plane.js +17 -0
  36. package/src/http/user-plane.js +17 -1
  37. package/src/index.d.ts +9 -1
  38. package/src/index.js +86 -64
  39. package/src/jobs/engine.js +279 -5
  40. package/src/jobs/history.js +18 -2
  41. package/src/jobs/plan-store.js +83 -0
  42. package/src/jobs/record-cleanup.js +714 -195
  43. package/src/mcp/server.js +271 -38
  44. package/src/mcp/wait.js +34 -15
  45. package/src/runtime/agent-runner.js +1 -0
  46. package/src/runtime/permissions.js +18 -0
  47. package/src/runtime/session-placement.js +36 -1
  48. package/src/runtime/worker-prompt.js +14 -9
  49. package/src/workspace/worktrees.js +155 -1
  50. package/codex/dsh-taskbridge.toml +0 -170
package/src/client/api.js CHANGED
@@ -33,9 +33,11 @@
33
33
  // `createStore`'s caller in `index.jsx` to `cleanupProjection()`).
34
34
  export {
35
35
  CLEANUP_BLOCKER_LABELS,
36
+ CLEANUP_PRESETS,
36
37
  MAX_CLEANUP_CHAINS,
37
38
  cleanupBlockerLabel,
38
39
  cleanupCandidates,
40
+ cleanupConfirmText,
39
41
  cleanupOutcome,
40
42
  cleanupProjection,
41
43
  cleanupRequest,
@@ -43,7 +45,9 @@ export {
43
45
  cleanupSelectionSummary,
44
46
  cleanupWarningText,
45
47
  describeCleanupOutcome,
48
+ describeOrphanCleanupOutcome,
46
49
  pruneCleanupSelection,
50
+ selectCleanupCandidatesByPreset,
47
51
  toggleCleanupSelection,
48
52
  withSelectionState,
49
53
  } from './task-cleanup.js';
@@ -96,6 +100,7 @@ export const ROUTES = Object.freeze({
96
100
  // execution chains. It is a `POST`, never a load-time or refresh-time write, and it
97
101
  // only ever names chains and their exact rounds.
98
102
  tasksCleanup: `${USER_PLANE_PREFIX}/tasks/cleanup`,
103
+ tasksCleanupOrphans: `${USER_PLANE_PREFIX}/tasks/cleanup-orphans`,
99
104
  // The one planning write the page has: a batch of planning nodes. It creates
100
105
  // records only — it cannot dispatch, authorize or review anything.
101
106
  plans: `${USER_PLANE_PREFIX}/plans`,
@@ -357,7 +362,17 @@ export function createApi(options = {}) {
357
362
  */
358
363
  async cleanupTasks(body) {
359
364
  const chains = Array.isArray(body?.chains) ? body.chains : [];
360
- return await request('POST', ROUTES.tasksCleanup, { confirm: true, chains });
365
+ const payload = { confirm: true, chains };
366
+ if (body?.archiveSessions === true) payload.archiveSessions = true;
367
+ if (body?.removeWorktrees === true) payload.removeWorktrees = true;
368
+ if (body?.cleanPlans === true) payload.cleanPlans = true;
369
+ return await request('POST', ROUTES.tasksCleanup, payload);
370
+ },
371
+ async cleanupOrphans(options = {}) {
372
+ const payload = { confirm: true };
373
+ if (typeof options?.archiveSessions === 'boolean') payload.archiveSessions = options.archiveSessions;
374
+ if (typeof options?.removeWorktrees === 'boolean') payload.removeWorktrees = options.removeWorktrees;
375
+ return await request('POST', ROUTES.tasksCleanupOrphans, payload);
361
376
  },
362
377
  /**
363
378
  * Create a batch of planning nodes.
@@ -869,7 +884,7 @@ export const CODEX_ACTIONS = Object.freeze(['install', 'repair', 'remove']);
869
884
  * configured, and both can be ready while the local-call switch is still off.
870
885
  */
871
886
  export const CODEX_TARGETS = Object.freeze([
872
- { key: 'agent', label: 'Codex 子智能体文件' },
887
+ { key: 'agent', label: 'Codex 原生技能(skills/dsh-taskbridge/SKILL.md)' },
873
888
  { key: 'mcp', label: 'Codex MCP 条目' },
874
889
  { key: 'switch', label: 'DSH 本机调用开关' },
875
890
  ]);
@@ -910,7 +925,7 @@ export function codexTargetView(codex, switchState, target) {
910
925
  : '已关闭:Codex 可以查询状态,但新任务会被拒绝;本页不会替你打开它。',
911
926
  };
912
927
  }
913
- const block = target === 'agent' ? codex?.agent : codex?.mcp;
928
+ const block = target === 'agent' ? (codex?.skill ?? codex?.agent) : codex?.mcp;
914
929
  if (block === null || block === undefined || typeof block !== 'object') {
915
930
  return { key: target, label, state: 'unknown', tone: 'off', detail: '宿主尚未回报该状态。' };
916
931
  }
@@ -946,11 +961,18 @@ export function codexTargetView(codex, switchState, target) {
946
961
  */
947
962
  export function describeCodexOutcome(outcome) {
948
963
  if (outcome === null || outcome === undefined) return '';
949
- const names = { agent: '子智能体文件', mcp: 'MCP 条目' };
950
- const changed = Array.isArray(outcome.changed) ? outcome.changed.map((key) => names[key] ?? key) : [];
964
+ const names = { agent: '技能文件(SKILL.md)', legacyAgent: '旧版子智能体文件', mcp: 'MCP 条目' };
965
+ const rawChanged = Array.isArray(outcome.changed) ? outcome.changed : [];
951
966
  const refused = Array.isArray(outcome.refused) ? outcome.refused : [];
952
967
  const parts = [];
953
- if (changed.length > 0) parts.push(`已写入:${changed.join('、')}`);
968
+ if (outcome.action === 'remove') {
969
+ if (rawChanged.length > 0) parts.push(`已移除:${rawChanged.map((key) => names[key] ?? key).join('、')}`);
970
+ } else {
971
+ const written = rawChanged.filter((key) => key !== 'legacyAgent').map((key) => names[key] ?? key);
972
+ const cleaned = rawChanged.filter((key) => key === 'legacyAgent').map((key) => names[key] ?? key);
973
+ if (written.length > 0) parts.push(`已写入:${written.join('、')}`);
974
+ if (cleaned.length > 0) parts.push(`已清理:${cleaned.join('、')}`);
975
+ }
954
976
  if (refused.length > 0) parts.push(`未改动:${refused.map((entry) => names[entry?.target] ?? entry?.target ?? '未知').join('、')}`);
955
977
  if (parts.length === 0) {
956
978
  return outcome.action === 'remove' ? '没有需要移除的插件托管文件。' : '已是最新,没有需要写入的内容。';
@@ -2555,6 +2577,16 @@ export function planCreateRequest(draft) {
2555
2577
  * @param {object} options - `api` transport, `now` clock.
2556
2578
  * @returns {object} store with `subscribe`, `getSnapshot` and action methods.
2557
2579
  */
2580
+ /** Backoff schedule (ms) when `init()` hits a startup 404 right after "Enable immediately". */
2581
+ const DEFAULT_INIT_RETRY_DELAYS_MS = Object.freeze([250, 500, 1000, 1500, 2000, 2500, 3000]);
2582
+
2583
+ /** Whether an error indicates the plugin backend HTTP routes have not mounted yet. */
2584
+ function isStartupRoutePendingError(error) {
2585
+ return error?.code === 'HTTP_404'
2586
+ || error?.code === 'USER_PLANE_UNKNOWN_ROUTE'
2587
+ || error?.code === 'USER_PLANE_UNREACHABLE';
2588
+ }
2589
+
2558
2590
  export function createStore(options = {}) {
2559
2591
  const api = options.api ?? createApi();
2560
2592
  // The task-record cleanup projection. It is injected rather than imported so this
@@ -2568,6 +2600,9 @@ export function createStore(options = {}) {
2568
2600
  const saveDebounceMs = Number.isFinite(options.saveDebounceMs) && options.saveDebounceMs >= 0
2569
2601
  ? Math.trunc(options.saveDebounceMs)
2570
2602
  : 700;
2603
+ const initRetryDelaysMs = Array.isArray(options.initRetryDelaysMs)
2604
+ ? options.initRetryDelaysMs.filter((ms) => Number.isFinite(ms) && ms >= 0).map((ms) => Math.trunc(ms))
2605
+ : DEFAULT_INIT_RETRY_DELAYS_MS;
2571
2606
  const scheduleImpl = typeof options.schedule === 'function'
2572
2607
  ? options.schedule
2573
2608
  : (fn, ms) => setTimeout(fn, ms);
@@ -2589,6 +2624,13 @@ export function createStore(options = {}) {
2589
2624
  let saveTimer = null;
2590
2625
  /** Explicit discard marker: the next debounce tick must not resurrect edits. */
2591
2626
  let saveSuppressed = false;
2627
+ /** Coalesced in-flight `init()` promise so remounting while bootstrapping never overlaps. */
2628
+ let initInFlight = null;
2629
+ /** Pending startup retry timer handle and canceller for `dispose()`. */
2630
+ let initRetryTimer = null;
2631
+ let cancelInitRetryWait = null;
2632
+ /** Last startup-failure notice emitted by `init()`, cleared automatically on recovery. */
2633
+ let initErrorNoticeId = null;
2592
2634
  /**
2593
2635
  * Sequence of `openTask` calls. A detail read may only publish its answer if no
2594
2636
  * NEWER read started meanwhile, so a slow response for an old row cannot replace the
@@ -2695,12 +2737,15 @@ export function createStore(options = {}) {
2695
2737
  }
2696
2738
 
2697
2739
  /**
2698
- * Append one operator-facing message.
2740
+ * Append one operator-facing message, deduplicating identical live notices so
2741
+ * parallel transient failures never stack repeated identical banners.
2699
2742
  * @param {'info'|'error'|'success'} level - severity.
2700
2743
  * @param {string} text - Chinese text.
2701
2744
  * @returns {number} notice id.
2702
2745
  */
2703
2746
  function notify(level, text) {
2747
+ const existing = state.notices.find((notice) => notice.level === level && notice.text === text);
2748
+ if (existing !== undefined) return existing.id;
2704
2749
  const id = state.revision + 1 + Math.random();
2705
2750
  patch({ notices: [...state.notices, { id, level, text }].slice(-6) });
2706
2751
  return id;
@@ -2710,6 +2755,31 @@ export function createStore(options = {}) {
2710
2755
  patch({ notices: state.notices.filter((notice) => notice.id !== id) });
2711
2756
  }
2712
2757
 
2758
+ /** Wait `ms` before retrying startup readiness; resolves `false` if disposed meanwhile. */
2759
+ function waitForInitRetry(ms) {
2760
+ return new Promise((resolve) => {
2761
+ if (disposed) {
2762
+ resolve(false);
2763
+ return;
2764
+ }
2765
+ let settled = false;
2766
+ const finish = (keepGoing) => {
2767
+ if (settled) return;
2768
+ settled = true;
2769
+ initRetryTimer = null;
2770
+ cancelInitRetryWait = null;
2771
+ resolve(keepGoing);
2772
+ };
2773
+ cancelInitRetryWait = () => {
2774
+ if (initRetryTimer !== null) {
2775
+ try { cancelScheduleImpl(initRetryTimer); } catch { /* ignore */ }
2776
+ }
2777
+ finish(false);
2778
+ };
2779
+ initRetryTimer = scheduleImpl(() => finish(!disposed), Math.max(0, ms));
2780
+ });
2781
+ }
2782
+
2713
2783
  async function track(key, work) {
2714
2784
  patch({ loading: { ...state.loading, [key]: true } });
2715
2785
  try {
@@ -3786,10 +3856,10 @@ export function createStore(options = {}) {
3786
3856
  },
3787
3857
 
3788
3858
  /** Remove a confirmed selection whose exact rounds still match the current tree. */
3789
- async cleanupTasks(selection) {
3859
+ async cleanupTasks(selection, options = {}) {
3790
3860
  const view = cleanup;
3791
3861
  const candidates = view.candidates(state.tree ?? null);
3792
- const prepared = view.request(selection ?? {}, candidates);
3862
+ const prepared = view.request(selection ?? {}, candidates, options);
3793
3863
  if (prepared.problems.length > 0) {
3794
3864
  notify('error', prepared.problems[0]);
3795
3865
  return { ok: false, error: new ApiError('CLEANUP_INVALID', prepared.problems[0]) };
@@ -3797,6 +3867,9 @@ export function createStore(options = {}) {
3797
3867
  return await track('cleanup', async () => {
3798
3868
  try {
3799
3869
  const outcome = await api.cleanupTasks(prepared.body);
3870
+ if (outcome?.cleaned && options?.hostWorkspaces) {
3871
+ await reconcileHostWorkspacesWithCleaned(options.hostWorkspaces, outcome.cleaned);
3872
+ }
3800
3873
  const deleted = view.outcome(outcome);
3801
3874
  const sentence = view.describe(outcome);
3802
3875
  if (sentence === '') throw new ApiError('CLEANUP_RESULT_UNCONFIRMED', '宿主未确认删除结果');
@@ -3822,20 +3895,115 @@ export function createStore(options = {}) {
3822
3895
  });
3823
3896
  },
3824
3897
 
3825
- /** Load everything the page needs; the catalog is loaded but not awaited. */
3898
+ /** Sweep residual worktrees and dispatched sessions whose task records were already removed. */
3899
+ async cleanupOrphans(options = {}) {
3900
+ if (typeof api.cleanupOrphans !== 'function') {
3901
+ notify('error', '当前宿主未提供残留清理接口。');
3902
+ return { ok: false };
3903
+ }
3904
+ return await track('cleanupOrphans', async () => {
3905
+ try {
3906
+ const outcome = await api.cleanupOrphans({
3907
+ archiveSessions: options?.archiveSessions !== false,
3908
+ removeWorktrees: options?.removeWorktrees !== false,
3909
+ });
3910
+ if (outcome?.cleaned && options?.hostWorkspaces) {
3911
+ await reconcileHostWorkspacesWithCleaned(options.hostWorkspaces, outcome.cleaned);
3912
+ }
3913
+ const sentence = typeof cleanup.describeOrphans === 'function'
3914
+ ? cleanup.describeOrphans(outcome)
3915
+ : '已完成残留隔离工作树与已删记录派工对话清理。';
3916
+ notify('success', sentence || '已完成残留清理。');
3917
+ await store.refreshTasks('manual');
3918
+ return { ok: true, outcome };
3919
+ } catch (error) {
3920
+ notify('error', describeError(error));
3921
+ return { ok: false, error };
3922
+ }
3923
+ });
3924
+ },
3925
+
3926
+ /**
3927
+ * Load everything the page needs; tolerates the short cold-start window right after
3928
+ * "Enable immediately" when the frontend mounts before backend HTTP routes finish
3929
+ * registering, retrying `/status` silently instead of stacking 404 banners.
3930
+ */
3826
3931
  async init() {
3827
- await Promise.all([store.refreshStatus(), store.loadSettings(), store.loadNativeProviders(), store.loadTasks()]);
3828
- // Diagnostic read only. `init` must never perform a Codex write: installing
3829
- // files is an explicit operator action, not a side effect of opening a page.
3830
- void store.refreshCodexStatus();
3831
- void store.refreshAntigravityStatus();
3832
- void store.loadCatalog();
3932
+ if (disposed) return;
3933
+ if (initInFlight !== null) return await initInFlight;
3934
+ const run = (async () => {
3935
+ let startupNoticeId = null;
3936
+ let statusOutcome = null;
3937
+ let statusReady = false;
3938
+ let lastStartupError = null;
3939
+
3940
+ for (let attempt = 0; attempt <= initRetryDelaysMs.length; attempt += 1) {
3941
+ if (disposed) return;
3942
+ statusOutcome = await track('status', async () => {
3943
+ try {
3944
+ const body = await api.getStatus();
3945
+ patch({ status: body });
3946
+ return { ok: true, body };
3947
+ } catch (error) {
3948
+ return { ok: false, error };
3949
+ }
3950
+ });
3951
+ if (statusOutcome.ok) {
3952
+ statusReady = true;
3953
+ break;
3954
+ }
3955
+ if (!isStartupRoutePendingError(statusOutcome.error) || attempt === initRetryDelaysMs.length) {
3956
+ lastStartupError = statusOutcome.error;
3957
+ break;
3958
+ }
3959
+ if (startupNoticeId === null) {
3960
+ startupNoticeId = notify('info', '插件服务正在启动,正在自动重试连接…');
3961
+ }
3962
+ const keepGoing = await waitForInitRetry(initRetryDelaysMs[attempt]);
3963
+ if (!keepGoing || disposed) return;
3964
+ }
3965
+
3966
+ if (startupNoticeId !== null) {
3967
+ dismissNotice(startupNoticeId);
3968
+ startupNoticeId = null;
3969
+ }
3970
+ if (disposed) return;
3971
+
3972
+ if (statusReady && initErrorNoticeId !== null) {
3973
+ dismissNotice(initErrorNoticeId);
3974
+ initErrorNoticeId = null;
3975
+ }
3976
+
3977
+ if (!statusReady) {
3978
+ const err = lastStartupError ?? statusOutcome?.error;
3979
+ if (err !== undefined && err !== null) {
3980
+ initErrorNoticeId = notify('error', describeError(err));
3981
+ if (isStartupRoutePendingError(err)) {
3982
+ patch({ nativeProvidersError: describeError(err), tasksError: err });
3983
+ return;
3984
+ }
3985
+ }
3986
+ }
3987
+
3988
+ await Promise.all([store.loadSettings(), store.loadNativeProviders(), store.loadTasks()]);
3989
+ if (disposed) return;
3990
+ // Diagnostic read only. `init` must never perform a Codex write: installing
3991
+ // files is an explicit operator action, not a side effect of opening a page.
3992
+ void store.refreshCodexStatus();
3993
+ void store.refreshAntigravityStatus();
3994
+ void store.loadCatalog();
3995
+ })().finally(() => {
3996
+ if (initInFlight === run) initInFlight = null;
3997
+ });
3998
+ initInFlight = run;
3999
+ return await run;
3833
4000
  },
3834
4001
 
3835
4002
  /** Release subscriptions and drop the one-time token. */
3836
4003
  dispose() {
3837
4004
  cancelPendingSave();
3838
4005
  disposed = true;
4006
+ if (typeof cancelInitRetryWait === 'function') cancelInitRetryWait();
3839
4007
  state = { ...state, token: null, tokenConnectionId: null };
3840
4008
  listeners.clear();
3841
4009
  },
@@ -3843,3 +4011,77 @@ export function createStore(options = {}) {
3843
4011
 
3844
4012
  return store;
3845
4013
  }
4014
+
4015
+ function normalizeClientPathKey(pathValue) {
4016
+ if (typeof pathValue !== 'string') return '';
4017
+ const trimmed = pathValue.trim().replace(/[\\/]+$/u, '');
4018
+ return trimmed.toLowerCase();
4019
+ }
4020
+
4021
+ async function reconcileHostWorkspacesWithCleaned(hostWorkspacesOrGetter, cleaned) {
4022
+ if (!cleaned || typeof cleaned !== 'object') return;
4023
+ let wsService = null;
4024
+ try {
4025
+ wsService = typeof hostWorkspacesOrGetter === 'function' ? hostWorkspacesOrGetter() : hostWorkspacesOrGetter;
4026
+ } catch {
4027
+ wsService = null;
4028
+ }
4029
+ if (!wsService || typeof wsService !== 'object') return;
4030
+
4031
+ if (typeof wsService.archiveSession === 'function' && Array.isArray(cleaned.archivedSessionIds)) {
4032
+ for (const sessionId of cleaned.archivedSessionIds) {
4033
+ if (typeof sessionId === 'string' && sessionId !== '') {
4034
+ try {
4035
+ await wsService.archiveSession(sessionId);
4036
+ } catch {
4037
+ // Best-effort client-side session archive.
4038
+ }
4039
+ }
4040
+ }
4041
+ }
4042
+
4043
+ let snapshot = null;
4044
+ try {
4045
+ snapshot = wsService.list?.getSnapshot?.() ?? null;
4046
+ } catch {
4047
+ snapshot = null;
4048
+ }
4049
+ const items = Array.isArray(snapshot?.items) ? snapshot.items : [];
4050
+ const itemById = new Map();
4051
+ for (const item of items) {
4052
+ if (typeof item?.workspaceId === 'string' && item.workspaceId !== '') {
4053
+ itemById.set(item.workspaceId, item);
4054
+ }
4055
+ }
4056
+
4057
+ const removedWorkspaceIds = Array.isArray(cleaned.removedWorkspaceIds) ? cleaned.removedWorkspaceIds : [];
4058
+ const workspaceSet = new Set(removedWorkspaceIds);
4059
+
4060
+ if (Array.isArray(cleaned.removedWorktreePaths) && cleaned.removedWorktreePaths.length > 0 && items.length > 0) {
4061
+ const removedPathKeys = new Set(cleaned.removedWorktreePaths.map(normalizeClientPathKey).filter(Boolean));
4062
+ for (const item of items) {
4063
+ const key = normalizeClientPathKey(item?.path);
4064
+ if (key !== '' && removedPathKeys.has(key) && typeof item.workspaceId === 'string' && !workspaceSet.has(item.workspaceId)) {
4065
+ workspaceSet.add(item.workspaceId);
4066
+ removedWorkspaceIds.push(item.workspaceId);
4067
+ }
4068
+ }
4069
+ cleaned.removedWorkspaceIds = removedWorkspaceIds;
4070
+ }
4071
+
4072
+ if (typeof wsService.delete === 'function' && removedWorkspaceIds.length > 0) {
4073
+ for (const workspaceId of removedWorkspaceIds) {
4074
+ if (typeof workspaceId !== 'string' || workspaceId === '') continue;
4075
+ const item = itemById.get(workspaceId) ?? null;
4076
+ if (item !== null && typeof item.path === 'string' && /[\\/]worktrees[\\/]*$/iu.test(item.path.trim())) {
4077
+ // Never remove the parent TaskBridge worktrees root container workspace itself.
4078
+ continue;
4079
+ }
4080
+ try {
4081
+ await wsService.delete(workspaceId);
4082
+ } catch {
4083
+ // Best-effort client-side workspace removal.
4084
+ }
4085
+ }
4086
+ }
4087
+ }