@pellux/goodvibes-sdk 0.21.20 → 0.21.23

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 (65) hide show
  1. package/dist/_internal/contracts/types.d.ts +2 -1
  2. package/dist/_internal/contracts/types.d.ts.map +1 -1
  3. package/dist/_internal/daemon/runtime-session-routes.d.ts +12 -1
  4. package/dist/_internal/daemon/runtime-session-routes.d.ts.map +1 -1
  5. package/dist/_internal/daemon/runtime-session-routes.js +23 -5
  6. package/dist/_internal/daemon/system-routes.js +1 -1
  7. package/dist/_internal/platform/companion/companion-chat-rate-limiter.d.ts +40 -2
  8. package/dist/_internal/platform/companion/companion-chat-rate-limiter.d.ts.map +1 -1
  9. package/dist/_internal/platform/companion/companion-chat-rate-limiter.js +34 -5
  10. package/dist/_internal/platform/companion/companion-chat-routes.d.ts +13 -0
  11. package/dist/_internal/platform/companion/companion-chat-routes.d.ts.map +1 -1
  12. package/dist/_internal/platform/companion/companion-chat-routes.js +29 -0
  13. package/dist/_internal/platform/config/schema-domain-runtime.d.ts +5 -0
  14. package/dist/_internal/platform/config/schema-domain-runtime.d.ts.map +1 -1
  15. package/dist/_internal/platform/config/schema-domain-runtime.js +13 -0
  16. package/dist/_internal/platform/config/schema-types.d.ts +8 -2
  17. package/dist/_internal/platform/config/schema-types.d.ts.map +1 -1
  18. package/dist/_internal/platform/config/schema.d.ts.map +1 -1
  19. package/dist/_internal/platform/config/schema.js +1 -0
  20. package/dist/_internal/platform/control-plane/operator-contract.d.ts.map +1 -1
  21. package/dist/_internal/platform/control-plane/operator-contract.js +45 -1
  22. package/dist/_internal/platform/control-plane/session-broker.d.ts +12 -0
  23. package/dist/_internal/platform/control-plane/session-broker.d.ts.map +1 -1
  24. package/dist/_internal/platform/control-plane/session-broker.js +22 -0
  25. package/dist/_internal/platform/daemon/cli.js +24 -5
  26. package/dist/_internal/platform/daemon/facade-composition.d.ts +5 -0
  27. package/dist/_internal/platform/daemon/facade-composition.d.ts.map +1 -1
  28. package/dist/_internal/platform/daemon/facade-composition.js +1 -0
  29. package/dist/_internal/platform/daemon/facade.d.ts.map +1 -1
  30. package/dist/_internal/platform/daemon/facade.js +1 -0
  31. package/dist/_internal/platform/daemon/http/router-route-contexts.d.ts.map +1 -1
  32. package/dist/_internal/platform/daemon/http/router-route-contexts.js +4 -0
  33. package/dist/_internal/platform/daemon/http/router.d.ts +5 -0
  34. package/dist/_internal/platform/daemon/http/router.d.ts.map +1 -1
  35. package/dist/_internal/platform/daemon/http/router.js +1 -1
  36. package/dist/_internal/platform/daemon/types.d.ts +7 -0
  37. package/dist/_internal/platform/daemon/types.d.ts.map +1 -1
  38. package/dist/_internal/platform/pairing/companion-token.js +2 -2
  39. package/dist/_internal/platform/runtime/events/index.d.ts +4 -1
  40. package/dist/_internal/platform/runtime/events/index.d.ts.map +1 -1
  41. package/dist/_internal/platform/runtime/events/index.js +0 -15
  42. package/dist/_internal/platform/runtime/events/workspace.d.ts +22 -0
  43. package/dist/_internal/platform/runtime/events/workspace.d.ts.map +1 -1
  44. package/dist/_internal/platform/runtime/health/effect-handlers.d.ts.map +1 -1
  45. package/dist/_internal/platform/runtime/health/effect-handlers.js +12 -1
  46. package/dist/_internal/platform/runtime/services.d.ts +19 -0
  47. package/dist/_internal/platform/runtime/services.d.ts.map +1 -1
  48. package/dist/_internal/platform/runtime/services.js +31 -0
  49. package/dist/_internal/platform/state/memory-store.d.ts +11 -0
  50. package/dist/_internal/platform/state/memory-store.d.ts.map +1 -1
  51. package/dist/_internal/platform/state/memory-store.js +22 -0
  52. package/dist/_internal/platform/state/project-index.d.ts +13 -3
  53. package/dist/_internal/platform/state/project-index.d.ts.map +1 -1
  54. package/dist/_internal/platform/state/project-index.js +31 -0
  55. package/dist/_internal/platform/tools/state/index.d.ts +23 -0
  56. package/dist/_internal/platform/tools/state/index.d.ts.map +1 -1
  57. package/dist/_internal/platform/tools/state/index.js +49 -5
  58. package/dist/_internal/platform/version.js +1 -1
  59. package/dist/_internal/platform/workspace/daemon-home.d.ts +13 -1
  60. package/dist/_internal/platform/workspace/daemon-home.d.ts.map +1 -1
  61. package/dist/_internal/platform/workspace/daemon-home.js +101 -14
  62. package/dist/_internal/platform/workspace/workspace-swap-manager.d.ts +2 -0
  63. package/dist/_internal/platform/workspace/workspace-swap-manager.d.ts.map +1 -1
  64. package/dist/_internal/platform/workspace/workspace-swap-manager.js +25 -25
  65. package/package.json +1 -1
@@ -27,6 +27,7 @@ import { createEventEnvelope } from '../runtime/events/index.js';
27
27
  export class WorkspaceSwapManager {
28
28
  deps;
29
29
  currentWorkingDir;
30
+ swapInProgress = null;
30
31
  constructor(initialWorkingDir, deps) {
31
32
  this.deps = deps;
32
33
  this.currentWorkingDir = initialWorkingDir;
@@ -35,6 +36,18 @@ export class WorkspaceSwapManager {
35
36
  return this.currentWorkingDir;
36
37
  }
37
38
  async requestSwap(newWorkingDir) {
39
+ if (this.swapInProgress) {
40
+ return { ok: false, code: 'WORKSPACE_BUSY', reason: 'Another workspace swap is already in progress.', retryAfter: 1 };
41
+ }
42
+ this.swapInProgress = this._requestSwapInner(newWorkingDir);
43
+ try {
44
+ return await this.swapInProgress;
45
+ }
46
+ finally {
47
+ this.swapInProgress = null;
48
+ }
49
+ }
50
+ async _requestSwapInner(newWorkingDir) {
38
51
  const raw = newWorkingDir.trim();
39
52
  if (!raw) {
40
53
  return { ok: false, code: 'INVALID_PATH', reason: 'Working directory path must not be empty.' };
@@ -42,21 +55,15 @@ export class WorkspaceSwapManager {
42
55
  const resolved = isAbsolute(raw) ? resolve(raw) : resolve(this.currentWorkingDir, raw);
43
56
  const from = this.currentWorkingDir;
44
57
  const to = resolved;
45
- // Emit started
46
- this._emit('WORKSPACE_SWAP_STARTED', { type: 'WORKSPACE_SWAP_STARTED', from, to });
47
- // Check busy sessions
58
+ // Check busy sessions BEFORE emitting STARTED — don't emit STARTED if we'll immediately refuse.
48
59
  const busyCount = this.deps.getBusySessionCount();
49
60
  if (busyCount > 0) {
50
61
  const reason = `${busyCount} session(s) have pending input. Retry after active inputs complete.`;
51
- this._emit('WORKSPACE_SWAP_REFUSED', {
52
- type: 'WORKSPACE_SWAP_REFUSED',
53
- from,
54
- to,
55
- reason,
56
- retryAfter: 5,
57
- });
62
+ this._emit({ type: 'WORKSPACE_SWAP_REFUSED', from, to, reason, retryAfter: 5 });
58
63
  return { ok: false, code: 'WORKSPACE_BUSY', reason, retryAfter: 5 };
59
64
  }
65
+ // Swap is proceeding — emit STARTED now that busy check passed.
66
+ this._emit({ type: 'WORKSPACE_SWAP_STARTED', from, to });
60
67
  // Validate and create directory
61
68
  try {
62
69
  mkdirSync(join(resolved, '.goodvibes', 'sessions'), { recursive: true });
@@ -86,29 +93,22 @@ export class WorkspaceSwapManager {
86
93
  catch {
87
94
  // Non-fatal — swap succeeded but persistence failed
88
95
  }
89
- this._emit('WORKSPACE_SWAP_COMPLETED', {
90
- type: 'WORKSPACE_SWAP_COMPLETED',
91
- from,
92
- to: resolved,
93
- persistedInDaemonSettings,
94
- });
96
+ this._emit({ type: 'WORKSPACE_SWAP_COMPLETED', from, to: resolved, persistedInDaemonSettings });
95
97
  return { ok: true, previous: from, current: resolved };
96
98
  }
97
99
  // ---------------------------------------------------------------------------
98
100
  // Internal helpers
99
101
  // ---------------------------------------------------------------------------
100
- _emit(type, payload) {
102
+ _emit(payload) {
101
103
  if (!this.deps.runtimeBus)
102
104
  return;
103
105
  try {
104
- const envelope = createEventEnvelope(type, payload, {
105
- sessionId: 'system',
106
- source: 'workspace-swap-manager',
107
- });
108
- // Cast: workspace events are not in AnyRuntimeEvent's narrow union but are
109
- // registered under the 'workspace' domain. See analogous cast in
110
- // runtime/health/effect-handlers.ts for CASCADE_APPLIED.
111
- this.deps.runtimeBus.emit('workspace', envelope);
106
+ const envelope = createEventEnvelope(payload.type, payload, { sessionId: '', source: 'workspace-swap-manager' });
107
+ this.deps.runtimeBus.emit('workspace',
108
+ // WorkspaceEvent is the DomainEventMap['workspace'] union; createEventEnvelope
109
+ // infers the payload type as the concrete member rather than the full union.
110
+ // A single widening cast (not through unknown) is safe here.
111
+ envelope);
112
112
  }
113
113
  catch {
114
114
  // Never throw from event emission
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pellux/goodvibes-sdk",
3
- "version": "0.21.20",
3
+ "version": "0.21.23",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/mgd34msu/goodvibes-sdk.git"