Skip to content

Commit a37ab7a

Browse files
sahrizviclaude
andcommitted
feat(workspace): state the linked workspace every turn, and mean the Altimate one
"Which workspace is this project linked to?" had one answer only when the workspace was routing something. #1278 put the binding into the routing directive in `awareness.ts`, which is silent by design whenever there is nothing to steer — so an unlinked project, an unverifiable link, and a workspace that materialised no integrations each rendered nothing, and the model answered with whichever "workspace" happened to be nearby in context: a Databricks workspace, an IDE workspace folder, or a guess. Identity now has one owner. `identity.ts` renders a short `## Altimate Workspace` section on every turn from the binding itself (`resolveBindingOutcome`), independent of routing: - bound: names the workspace (id kept even when the name sanitises to nothing) and says that a workspace-IDENTITY question resolves to it — never to another service's own "workspace". - unbound: says none is linked and how to link one. - unknown: asserts neither a workspace nor "unlinked"; says to retry. Each branch scopes its instruction to a genuine identity question ("this", "current", "active" or an unqualified "workspace" asking what THIS project is connected to). An earlier draft fired on any mention of the word and nagged about linking in the middle of unrelated Databricks conversations; the tests pin that it no longer does. Behind the pilot flag like the rest. `awareness.ts` goes back to routing only: `bindingSection`, `NAMES_BINDING` and the identity charge against `MAX_SECTION_CHARS` are gone, and the `nothing-materialised` state is byte-identical silence again (#1291's two tests that asserted the old line inside the routing section now assert silence). `prompt.ts` places the identity section right after the environment block, ahead of skills and routing. Two strings elsewhere used "workspace" for something else and are reworded so the word means one thing in the product: the Databricks auth prompt says `<databricks-workspace-host>`, and the nothing-built validator says "this project is configured to require artifacts". Tests: 1498 pass across the workspace, plugin, prompt and validator suites; typecheck clean. Rebased onto v0.12.0. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
1 parent 8877e56 commit a37ab7a

8 files changed

Lines changed: 510 additions & 172 deletions

File tree

‎packages/opencode/src/altimate/plugin/databricks.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export async function DatabricksAuthPlugin(_input: PluginInput): Promise<Hooks>
127127
authorize: async () => ({
128128
url: "https://accounts.cloud.databricks.com",
129129
instructions:
130-
"Enter your credentials as: <workspace-host>::<PAT-token>\n e.g. myworkspace.cloud.databricks.com::dapi1234567890abcdef\n Create a PAT in Databricks: Settings → Developer → Access Tokens → Generate New Token",
130+
"Enter your credentials as: <databricks-workspace-host>::<PAT-token>\n e.g. myworkspace.cloud.databricks.com::dapi1234567890abcdef\n Create a PAT in Databricks: Settings → Developer → Access Tokens → Generate New Token",
131131
method: "code" as const,
132132
callback: async (code: string) => {
133133
const parsed = parseDatabricksPAT(code)

‎packages/opencode/src/altimate/validators/dbt-nothing-built.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export const DbtNothingBuiltValidator: Validator = {
428428
// agent to distrust the gate.
429429
`The task document at ${safeTaskFile} names required deliverables${namedText}, but this session built other deliverables and none of them matched those names. The named work was not done.`
430430
: `The task document at ${safeTaskFile} names required deliverables${namedText}, but this session wrote no project files and produced no fresh successful build artifact. Nothing was built, so the task is not done.`
431-
: `This session wrote no project files and produced no fresh successful build artifact, but the workspace is configured to require artifacts. Nothing was built, so the task is not done.`
431+
: `This session wrote no project files and produced no fresh successful build artifact, but this project is configured to require artifacts. Nothing was built, so the task is not done.`
432432

433433
return {
434434
ok: false,

‎packages/opencode/src/altimate/workspace/awareness.ts‎

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ export const MAX_SECTION_CHARS = 2_000
5959

6060
const HEADING = "## Workspace integrations"
6161

62-
const BINDING_HEADING = "## Workspace"
63-
6462
/** How each capability is named to the model. Keyed on the `Capability` union, so a
6563
* new capability is a compile error here rather than an unlabelled row. */
6664
const CAPABILITY_LABEL: Record<Capability, string> = {
@@ -128,51 +126,13 @@ const DISABLED_COPY: Record<NonNullable<Precedence["disabledReason"]>, string> =
128126
"nothing-materialised": "",
129127
}
130128

131-
/** Whether the workspace may be NAMED in this state. Separate from `DISABLED_COPY`
132-
* because identity and routing are different claims: the routing directive stays
133-
* silent unless there is something to steer, but "which workspace is this project
134-
* linked to" is a question the model is asked directly and could not previously
135-
* answer — nothing else puts the binding in the prompt, and no tool reports it.
136-
*
137-
* Keyed on the union so a new `disabledReason` is a compile error here rather than
138-
* silently naming — or silently failing to name — a workspace. `false` for the three
139-
* unverified states for the reason `UNVERIFIED_SECTION` gives: nothing has confirmed
140-
* the binding those states were derived from, and under `unattributed` the engine may
141-
* belong to a different workspace than the one the link names. `false` for the hatch
142-
* and `pilot-off` because neither carries a name to print (see `EMPTY` in
143-
* `precedence.ts`) — a bound project with the hatch on therefore stays unnamed, which
144-
* is a data limitation of that call site, not a decision made here.
145-
*
146-
* NOTE: this deliberately breaks the "byte-identical system prompt" property that
147-
* `DISABLED_COPY` claims for `nothing-materialised`. A project bound to a workspace
148-
* that materialised no integrations is exactly the case users hit — a freshly created
149-
* workspace — and it is the case where being told nothing is most confusing. */
150-
const NAMES_BINDING: Record<NonNullable<Precedence["disabledReason"]>, boolean> = {
151-
"pilot-off": false,
152-
"escape-hatch": false,
153-
unbound: false,
154-
"binding-unreadable": false,
155-
unattributed: false,
156-
"derive-failed": false,
157-
"nothing-materialised": true,
158-
}
159-
160-
/** The identity line: what this project is linked to, independent of whether anything
161-
* is being routed. Empty when the state may not name a binding, or when the snapshot
162-
* carries no name to print. */
163-
function bindingSection(precedence: Precedence): string {
164-
const nameable = precedence.enabled || (precedence.disabledReason ? NAMES_BINDING[precedence.disabledReason] : false)
165-
if (!nameable) return ""
166-
// A name that sanitises to nothing must not erase the identity when the id
167-
// is known: the line is the only place the binding is stated. Without an id
168-
// either there is nothing left to print.
169-
if (!inertWorkspaceName(precedence.workspaceName) && !precedence.workspaceId) return ""
170-
return [
171-
BINDING_HEADING,
172-
"",
173-
`This project is linked to Altimate workspace ${workspaceLabel(precedence.workspaceName, precedence.workspaceId)}.`,
174-
].join("\n")
175-
}
129+
// Identity — "which Altimate Workspace is this project linked to" — is NOT stated
130+
// here. It lives in `identity.ts`, which renders it every turn from the binding
131+
// itself, independent of routing: a project can be linked and route nothing (a
132+
// workspace that materialised no integrations), or be unlinked, or be unverifiable
133+
// this turn, and each of those deserves a definite answer that a routing directive,
134+
// silent by design whenever there is nothing to steer, cannot give. One owner, so the
135+
// two can never disagree about what the project is linked to.
176136

177137
/**
178138
* Render the section, or "" when there is nothing to steer.
@@ -193,21 +153,13 @@ function bindingSection(precedence: Precedence): string {
193153
*/
194154
export function systemSection(precedence: Precedence | undefined): string {
195155
if (!precedence) return ""
196-
// Identity first, then routing. Either half can be empty; both empty renders "".
197-
// The identity line is charged against MAX_SECTION_CHARS rather than added on top:
198-
// the cap exists to bound what this module injects, so letting a new part sit
199-
// outside it would raise the real ceiling silently.
200-
const binding = bindingSection(precedence)
201-
const routing = routingSection(precedence, binding ? binding.length + SEPARATOR.length : 0)
202-
return [binding, routing].filter(Boolean).join(SEPARATOR)
156+
return routingSection(precedence)
203157
}
204158

205-
const SEPARATOR = "\n\n"
206-
207-
/** The routing directive. Unchanged contract: silent unless the workspace is really
208-
* routing, so the model is never steered toward tools it should not use. The one
209-
* addition is the extension tools a live IDE bridge serves, which ride along in
210-
* both shapes and are the only thing said in the extension-only shape. */
159+
/** The routing directive. Silent unless the workspace is really routing, so the
160+
* model is never steered toward tools it should not use. The one addition is the
161+
* extension tools a live IDE bridge serves, which ride along in both shapes and are
162+
* the only thing said in the extension-only shape. */
211163
function routingSection(precedence: Precedence, reserved = 0): string {
212164
const extLines = servedExtensions(precedence).map(extensionLine)
213165
if (!precedence.enabled) {
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// altimate_change - new file
2+
//
3+
// Model-facing statement of Altimate Workspace identity: which workspace (if any) this
4+
// project is linked to, rendered UNCONDITIONALLY so "this/current/active workspace" has
5+
// exactly one deterministic answer every turn. Independent of `awareness.ts`, which
6+
// exists to steer warehouse tool-call routing and is silent by design whenever no
7+
// integration is served — correct for routing, wrong for identity. A user can ask
8+
// "which workspace is my project connected to" on a session with zero served
9+
// connections and still deserves a real answer.
10+
//
11+
// The naming conflict: "workspace" names two unrelated things in this product — the
12+
// Altimate Workspace a project is *linked* to (`state.ts`'s binding), and other
13+
// services' own use of the word (Databricks' native "workspace" concept, in
14+
// particular). Nothing previously told the model which one "workspace" means when the
15+
// user says it bare, so it could answer with whichever "workspace" happened to be
16+
// nearby in context — confidently, and wrong. This module states the linked workspace
17+
// (or its absence, or that it's currently unverifiable) explicitly, and instructs the
18+
// model to resolve a genuine workspace-identity QUESTION to it — never to substitute
19+
// another service's "workspace" as the answer. That instruction is deliberately scoped
20+
// to an actual identity question (see `TRIGGER` below), not to every incidental mention
21+
// of the word: an earlier draft fired on any appearance of "workspace" at all, which
22+
// meant nagging about linking mid-conversation about an unrelated Databricks topic, or
23+
// pedantically re-qualifying every casual mention of one. Neither is this feature's
24+
// job — resolving "this/current/active workspace" is.
25+
import { resolveBindingOutcome, type BindingOutcome } from "./state"
26+
import { inertWorkspaceName } from "./workspace-name"
27+
import { isEnabled } from "./engine-seams"
28+
import { Instance } from "../../project/instance"
29+
30+
/** Independent of `awareness.ts`'s MAX_SECTION_CHARS (2,000) — this section is a short,
31+
* fixed-shape identity statement, not an open-ended list of served integrations, so a
32+
* much smaller ceiling is enough. Exists mainly as a guard against a pathological
33+
* workspace name defeating `inertWorkspaceName`'s own 80-code-point cap. */
34+
export const MAX_SECTION_CHARS = 800
35+
36+
const HEADING = "## Altimate Workspace"
37+
38+
/** The trigger for every active instruction below: a genuine workspace-IDENTITY
39+
* question from the user, not any incidental appearance of the word. Scoped this way
40+
* on purpose — an earlier draft said "whenever 'workspace' comes up" for the unbound
41+
* case, and an unconditional disambiguation rule for the bound case, and both were
42+
* over-triggering: a model that takes either literally interjects a linking pitch, or
43+
* pedantically re-qualifies every mention of a Databricks workspace, in the middle of
44+
* a conversation that was never about the Altimate Workspace at all. Restated once
45+
* here so both branches phrase the same condition identically. */
46+
const TRIGGER =
47+
'the user\'s own message asks a workspace-IDENTITY question — "workspace" ' +
48+
'unqualified, or "this"/"current"/"active" workspace, used to ask what THIS ' +
49+
"project is connected to (not a passing mention of some other service's workspace)"
50+
51+
const LINK_HINT =
52+
'To link one: in this session, open the command palette and run "Link this project ' +
53+
"to a workspace\"; or run `altimate-code link` in a terminal."
54+
55+
/** Pure formatter — takes an already-resolved outcome so it is testable without
56+
* mocking the binding cache / network. `systemSection` below is the thin async
57+
* wrapper that actually resolves one. Enforces `MAX_SECTION_CHARS` itself (rather than
58+
* leaving it to the caller) so the cap is part of the pure, testable surface — the
59+
* guard is against a pathological workspace name, and every branch below is built from
60+
* one, so it belongs where the name is rendered. */
61+
export function render(outcome: BindingOutcome): string {
62+
return capSection(renderBody(outcome))
63+
}
64+
65+
/** Exported so the cap's own contract has direct coverage — `inertWorkspaceName`
66+
* already bounds the one variable input (the workspace name) to 80 code points, so no
67+
* real `render()` call can currently produce output long enough to exercise this via
68+
* `render()` alone. It stays as defense in depth against a future branch that adds
69+
* unbounded text. */
70+
export function capSection(out: string): string {
71+
return out.length > MAX_SECTION_CHARS ? out.slice(0, MAX_SECTION_CHARS) : out
72+
}
73+
74+
function renderBody(outcome: BindingOutcome): string {
75+
if (outcome.status === "bound") {
76+
const label = workspaceLabel(outcome.binding.datamateName, String(outcome.binding.datamateId))
77+
return [
78+
HEADING,
79+
"",
80+
`This project is linked to Altimate Workspace ${label}.`,
81+
`When ${TRIGGER}, the answer is this Altimate Workspace — never substitute ` +
82+
"another service's own \"workspace\" (a Databricks workspace, an IDE's " +
83+
"workspace folder, etc.) for it. Outside such a question, other services' own " +
84+
'"workspace" concepts can be discussed normally — there is no need to relabel ' +
85+
"or footnote every incidental mention of one.",
86+
].join("\n")
87+
}
88+
89+
if (outcome.status === "unbound") {
90+
// No Altimate Workspace is linked, so there is nothing to protect the bare word
91+
// "workspace" for in casual conversation — another service's own "workspace" can
92+
// come up normally. The active instruction is scoped to TRIGGER (a real identity
93+
// question), not "any mention of the word" — the earlier draft's "whenever
94+
// 'workspace' comes up" phrasing was exactly the over-triggering this fixes.
95+
return [
96+
HEADING,
97+
"",
98+
"No Altimate Workspace is linked to this project.",
99+
`When ${TRIGGER}, say plainly that none is linked yet and offer to help link ` +
100+
"one.",
101+
LINK_HINT,
102+
"Outside such a question, other services' own \"workspace\" concepts (e.g. a " +
103+
"Databricks workspace) are unrelated — discuss them normally, with no linking " +
104+
"pitch attached.",
105+
].join("\n")
106+
}
107+
108+
// "unknown" — the local cache and the server disagree, or neither is reachable this
109+
// turn. Assert nothing about the Altimate Workspace: not a specific one, and not
110+
// "unlinked" either — both would be a guess the next revalidation could contradict.
111+
// Other services' own "workspace" concepts are unaffected by this uncertainty.
112+
return [
113+
HEADING,
114+
"",
115+
"Whether this project is linked to an Altimate Workspace could not be verified " +
116+
"this turn.",
117+
`When ${TRIGGER}, say link status is temporarily unavailable and to try again ` +
118+
"shortly. Do not name a specific Altimate Workspace and do not say none is " +
119+
"linked.",
120+
"Outside such a question, other services' own \"workspace\" concepts (e.g. a " +
121+
"Databricks workspace) are unaffected and can be discussed normally.",
122+
].join("\n")
123+
}
124+
125+
function workspaceLabel(name: string, id: string): string {
126+
// A name that sanitises to nothing must not erase the identity: the id is the
127+
// stable half, and `""` reads as a bug.
128+
return `${JSON.stringify(inertWorkspaceName(name) || "(unnamed)")} (id ${id})`
129+
}
130+
131+
/** Called on every step of the agentic loop, same as `awareness.ts`'s section —
132+
* `resolveBindingOutcome` is a cached local read (5-minute revalidation window), so
133+
* this stays cheap. Reads `Instance.directory` ITSELF, inside the same try/catch as
134+
* the resolve call — not as a caller-supplied argument evaluated at the call site.
135+
* `Instance.directory` is an `AsyncLocalStorage`-backed getter (`project/instance.ts`)
136+
* that throws `Context.NotFound` outside an established instance context (some test
137+
* harnesses, or an edge case in a future call path); evaluating it as an argument to
138+
* this function — `systemSection(Instance.directory)` — would throw synchronously at
139+
* the CALLER, before this function's own try/catch ever runs, defeating it entirely.
140+
* Mirrors how `precedence.ts`'s `currentBinding()` reads `Instance.directory` inside
141+
* its own try/catch for the same reason. Any failure — a missing instance context, a
142+
* binding-cache read error — degrades to the "unknown" copy rather than breaking
143+
* prompt assembly. */
144+
export async function systemSection(): Promise<string> {
145+
// Behind the same opt-in as everything else about workspaces. A user outside
146+
// the pilot has no Altimate Workspace to be linked to, and must not be told
147+
// every turn that none is linked and how to link one.
148+
if (!isEnabled()) return ""
149+
try {
150+
const outcome = await resolveBindingOutcome(Instance.directory)
151+
return render(outcome)
152+
} catch {
153+
return render({ status: "unknown" })
154+
}
155+
}
156+
// altimate_change end

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import * as WorkspaceEngine from "../altimate/workspace/engine-overlay"
3434
import { DATAMATE_KEY } from "../altimate/datamate-transport"
3535
import * as Precedence from "../altimate/workspace/precedence"
3636
import * as Awareness from "../altimate/workspace/awareness"
37+
import * as WorkspaceIdentity from "../altimate/workspace/identity"
3738
// altimate_change end
3839
import { Plugin } from "../plugin"
3940
import PROMPT_PLAN from "../session/prompt/plan.txt"
@@ -1451,6 +1452,17 @@ export namespace SessionPrompt {
14511452
sessionID,
14521453
})
14531454
// altimate_change end
1455+
// altimate_change start — workspace identity.
1456+
// Unconditional, unlike the routing section below: "which Altimate Workspace (if
1457+
// any) is this project linked to" deserves a real, deterministic answer even on a
1458+
// session with no served warehouse integration. Independent read from `state.ts`
1459+
// — deliberately not derived from `Precedence.forSession`, which is gated behind
1460+
// the workspace pilot flag and short-circuits to empty for states unrelated to
1461+
// pure link identity. `systemSection()` reads `Instance.directory` itself, inside
1462+
// its own try/catch — NOT passed as an argument here — so a missing instance
1463+
// context can't throw synchronously at this call site.
1464+
const workspaceIdentity = await WorkspaceIdentity.systemSection()
1465+
// altimate_change end
14541466
// altimate_change start — workspace tool awareness.
14551467
// Reads the snapshot `Precedence.refresh` stored for this turn during tool
14561468
// resolution, so the section, the tool descriptions and the mid-turn `check()`
@@ -1462,6 +1474,11 @@ export namespace SessionPrompt {
14621474
// altimate_change end
14631475
const system = [
14641476
...(await SystemPrompt.environment(model)),
1477+
// altimate_change start — workspace identity directive. Placed early (not
1478+
// trailing) per the placement finding in session/system.ts: content near the
1479+
// front of a section is treated as binding, trailing content as background.
1480+
...(workspaceIdentity ? [workspaceIdentity] : []),
1481+
// altimate_change end
14651482
...(skills ? [skills] : []),
14661483
...(knowledgeInjection ? [knowledgeInjection] : []),
14671484
// altimate_change start — workspace routing directive

0 commit comments

Comments
 (0)