@skrr-ai/cli 0.1.39 → 0.1.40

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.
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.describeUnselectedWorkspace = describeUnselectedWorkspace;
4
4
  exports.listWorkspaces = listWorkspaces;
5
+ exports.ambientWorkspaceId = ambientWorkspaceId;
6
+ exports.clearAmbientWorkspaceCache = clearAmbientWorkspaceCache;
5
7
  exports.listWorkspaceListing = listWorkspaceListing;
6
8
  exports.getWorkspace = getWorkspace;
7
9
  exports.matchWorkspace = matchWorkspace;
@@ -60,6 +62,42 @@ function describeUnselectedWorkspace(listing) {
60
62
  async function listWorkspaces() {
61
63
  return (await listWorkspaceListing()).rows;
62
64
  }
65
+ /**
66
+ * The workspace a bare session actually writes to, for callers merging the
67
+ * caller's vocabulary or defaults across scopes.
68
+ *
69
+ * `OVERSKY_WORKSPACE_ID` is only populated when a workspace was SELECTED —
70
+ * `workspaces use`, `--workspace`, or a daemon session handoff. An account
71
+ * that never selected one still has a server-side `defaultWorkspaceId`, and
72
+ * every unscoped write lands there; a caller that only read the variable
73
+ * would reason about a smaller world than the one the server writes into
74
+ * (observed: `labels list` reported a user-only vocabulary while three
75
+ * workspace-scoped labels existed and were attachable).
76
+ *
77
+ * The listing fetch is memoized and fail-open: this runs to give a better
78
+ * answer, and must never become the error — an unreachable server returns
79
+ * `undefined`, which is the same world the caller saw before this existed.
80
+ */
81
+ let memoizedDefaultWorkspaceId;
82
+ async function ambientWorkspaceId(env = process.env) {
83
+ const explicit = env.OVERSKY_WORKSPACE_ID?.trim();
84
+ if (explicit)
85
+ return explicit;
86
+ if (memoizedDefaultWorkspaceId !== undefined) {
87
+ return memoizedDefaultWorkspaceId ?? undefined;
88
+ }
89
+ try {
90
+ memoizedDefaultWorkspaceId = (await listWorkspaceListing()).defaultWorkspaceId ?? null;
91
+ }
92
+ catch {
93
+ memoizedDefaultWorkspaceId = null;
94
+ }
95
+ return memoizedDefaultWorkspaceId ?? undefined;
96
+ }
97
+ /** Test seam — a memoized network result must not leak between specs. */
98
+ function clearAmbientWorkspaceCache() {
99
+ memoizedDefaultWorkspaceId = undefined;
100
+ }
63
101
  /** `listWorkspaces`, keeping the envelope's caller-level fields. */
64
102
  async function listWorkspaceListing() {
65
103
  const rows = [];