Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/plugin-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ open, delete what it settles.
| Chat fork follow-ups | Not yet: a full-session fork from the sidebar or a tab; pre-filling the composer with the forked prompt; forking into a new work session or worktree (`WorkSessions.forkChat`); carrying the source's `agent`; persisted fork lineage. |
| `GitActionsControl` branch coverage | 56% branches (the default-branch confirm's Cancel and "branch changed" paths). |
| One Kilo sign-in gate | kilo.environments, kilo.notebook and kilo.local-inference each have a copy. |
| Generic conda transaction failures | kilo.environments maps the bridge's `execution_failed` and `internal_error` (and clone failures) to `SOLVE_FAILED`, so Settings still titles them "Dependency conflict"; give them their own code. |
| Signing out of Anaconda outside the model catalog | kilo.environments offers "Sign in to Anaconda" for policy channels, but signing out or switching accounts is only in kilo.anaconda's account panel, behind `local-model-catalog`. |
| Workspace sources follow-ups | The New workspace dialog's sources can't yet show clone progress or cancel a clone (git-client's `exec` takes a signal but no progress); self-hosted GitHub Enterprise isn't listed (the GitHub CLI's default host only). |
| Panes and work sessions | Choosing among several openers ("Open with"); a pane status contract so a Browser pane's loading feeds work session status; a dirty indicator for Files and Notebook tabs; clicking a notification to open its work session; a dock badge. |
| Pane tab menu | Opening it from the keyboard (Shift+F10) and showing keybindings in its items. Close others / to the right / all close one `Panes.close` at a time (so close guards ask in turn); a `Panes.closeMany` would save the broadcasts. |
Expand Down
1 change: 1 addition & 0 deletions docs/plugins/dependency-graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ <h1>Plugin dependency graph</h1>
["chat", "shell", 3],
["chat", "work-sessions", 9],
["developer", "shell", 2],
["environments", "anaconda", 1],
["environments", "chat", 1],
["environments", "core", 3],
["environments", "local-inference", 1],
Expand Down
36 changes: 18 additions & 18 deletions docs/plugins/schema.md

Large diffs are not rendered by default.

66 changes: 34 additions & 32 deletions docs/security-architecture-overview.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/pane-layout/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,9 @@ export function parseLayoutJson(value: unknown): PaneLayout | null {

const sizes: Record<string, number> = {};
if (record.sizes && typeof record.sizes === "object" && !Array.isArray(record.sizes)) {
const knownGroupIds = new Set(groupIds);
for (const [id, width] of Object.entries(record.sizes as Record<string, unknown>)) {
if (groupIds.includes(id) && isFiniteNumber(width)) sizes[id] = width;
if (knownGroupIds.has(id) && isFiniteNumber(width)) sizes[id] = width;
}
}
return {
Expand Down
11 changes: 6 additions & 5 deletions plugins/environments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"dependencies": {
"@kilo-desktop/kernel": "workspace:*",
"@kilo-desktop/plugin-anaconda": "workspace:*",
"@kilo-desktop/plugin-chat": "workspace:*",
"@kilo-desktop/plugin-core": "workspace:*",
"@kilo-desktop/plugin-local-inference": "workspace:*",
Expand All @@ -37,11 +38,11 @@
"zod": "catalog:"
},
"optionalDependencies": {
"@anaconda/desktop-bridge-payload-darwin-arm64": "npmjs:0.1.22",
"@anaconda/desktop-bridge-payload-linux-arm64": "npmjs:0.1.22",
"@anaconda/desktop-bridge-payload-linux-x64": "npmjs:0.1.22",
"@anaconda/desktop-bridge-payload-win32-arm64": "npmjs:0.1.22",
"@anaconda/desktop-bridge-payload-win32-x64": "npmjs:0.1.22"
"@anaconda/desktop-bridge-payload-darwin-arm64": "npmjs:0.1.23",
"@anaconda/desktop-bridge-payload-linux-arm64": "npmjs:0.1.23",
"@anaconda/desktop-bridge-payload-linux-x64": "npmjs:0.1.23",
"@anaconda/desktop-bridge-payload-win32-arm64": "npmjs:0.1.23",
"@anaconda/desktop-bridge-payload-win32-x64": "npmjs:0.1.23"
},
"devDependencies": {
"@kilo-desktop/plugin-work-sessions": "workspace:*",
Expand Down
5 changes: 5 additions & 0 deletions plugins/environments/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"kilo.core/tool": "optional",
"kilo.core/chat-config": "optional",
"kilo.core/account": "optional",
"kilo.anaconda/account": "optional",
"kilo.local-inference/llama-runtime": "optional",
"kilo.chat/permission-renderer": "optional",
"kilo.shell/navigation": "optional",
Expand Down Expand Up @@ -279,6 +280,10 @@
{
"id": "package-install-link-rejected",
"name": "Package Install Link Rejected"
},
{
"id": "environment-policy-blocked",
"name": "Environment Policy Blocked"
}
]
}
Expand Down
120 changes: 118 additions & 2 deletions plugins/environments/src/contracts/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import {
environmentsErrorCodeSchema,
environmentsErrorCodeToKernelErrorCode,
formatEnvironmentsErrorMessage,
jobErrorSchema,
jobIdSchema,
jobKindSchema,
jobProgressEventSchema,
parseEnvironmentsErrorMessage,
POLICY_NOTICE_LINE_PREFIX,
policyBlockedPackageSchema,
policyNoticeSchema,
providerSchema,
} from "./common";

Expand Down Expand Up @@ -153,13 +157,17 @@ describe("environmentsErrorCodeSchema", () => {
"INVALID_MATCHSPEC",
"INVALID_CHANNEL",
"PROVIDER_NOT_READY",
"POLICY_BLOCKED",
"NOT_SIGNED_IN",
"CHANNEL_ACCESS_DENIED",
] as const;

it("includes every documented v1 code", () => {
it("includes every documented code", () => {
for (const code of codes) expect(environmentsErrorCodeSchema.parse(code)).toBe(code);
});

it("has no accidental extras — freezes the vocabulary at exactly the v1 set", () => {
it("has no accidental extras — freezes the vocabulary at exactly these 18 codes", () => {
expect(environmentsErrorCodeSchema.options).toHaveLength(18);
expect(environmentsErrorCodeSchema.options.slice().sort()).toEqual([...codes].sort());
});

Expand Down Expand Up @@ -243,6 +251,108 @@ describe("formatEnvironmentsErrorMessage / parseEnvironmentsErrorMessage", () =>
});
});

describe("the policy notice line", () => {
const blocked = {
package: "pillow",
version: "8.4.0",
channel: "https://repo.anaconda.cloud/repo/acme/main",
org: "acme",
policy: "No critical CVEs",
policyId: "0b7c3c1e-2f4e-4a5b-9a51-3f6c9e1d2a10",
reason: "CVE-2022-22817 (critical)",
};
const summary = "pillow 8.4.0 is blocked by your organization's policy 'No critical CVEs'";

it("appends the notice as one final `[policy] {json}` line the agent reads verbatim", () => {
const wire = formatEnvironmentsErrorMessage("POLICY_BLOCKED", summary, { blocked: [blocked] });
const lines = wire.split("\n");
expect(lines[0]).toBe(`POLICY_BLOCKED: ${summary}`);
expect(lines.at(-1)).toBe(
`${POLICY_NOTICE_LINE_PREFIX}${JSON.stringify({ blocked: [blocked] })}`,
);
});

it("round-trips code, detail and notice", () => {
const wire = formatEnvironmentsErrorMessage("POLICY_BLOCKED", summary, { blocked: [blocked] });
expect(parseEnvironmentsErrorMessage(wire)).toEqual({
code: "POLICY_BLOCKED",
detail: summary,
policy: { blocked: [blocked] },
});
});

it("round-trips a notice without a detail", () => {
const policy = { refused: { org: null, channel: "acme/main" } };
const wire = formatEnvironmentsErrorMessage("NOT_SIGNED_IN", undefined, policy);
expect(wire).toBe(`NOT_SIGNED_IN\n${POLICY_NOTICE_LINE_PREFIX}${JSON.stringify(policy)}`);
expect(parseEnvironmentsErrorMessage(wire)).toEqual({ code: "NOT_SIGNED_IN", policy });
});

it("keeps a multi-line solver report intact above the notice", () => {
const report = "Could not solve.\n\nThe following packages are incompatible\n└─ holoviews";
const wire = formatEnvironmentsErrorMessage("SOLVE_FAILED", report, { policyNote: true });
expect(parseEnvironmentsErrorMessage(wire)).toEqual({
code: "SOLVE_FAILED",
detail: report,
policy: { policyNote: true },
});
});

it("adds no line for an empty notice", () => {
expect(formatEnvironmentsErrorMessage("SOLVE_FAILED", "conflict", {})).toBe(
"SOLVE_FAILED: conflict",
);
});

it("leaves a malformed trailing line in the detail", () => {
for (const trailer of ["[policy] {not json", '[policy] {"blocked": "pillow"}']) {
expect(parseEnvironmentsErrorMessage(`SOLVE_FAILED: conflict\n${trailer}`)).toEqual({
code: "SOLVE_FAILED",
detail: `conflict\n${trailer}`,
});
}
});

it("only reads the notice from the final line", () => {
const wire = `SOLVE_FAILED: [policy] {"policyNote":true}\nmore text`;
expect(parseEnvironmentsErrorMessage(wire)).toEqual({
code: "SOLVE_FAILED",
detail: `[policy] {"policyNote":true}\nmore text`,
});
});

it("accepts the optional and nullable fields of a blocked package", () => {
const sparse = {
package: "pillow",
version: null,
channel: null,
org: null,
policy: null,
policyId: null,
reason: null,
};
expect(policyNoticeSchema.parse({ blocked: [sparse] })).toEqual({ blocked: [sparse] });
expect(policyBlockedPackageSchema.safeParse({ ...sparse, package: undefined }).success).toBe(
false,
);
});
});

describe("jobErrorSchema", () => {
it("carries an optional policy notice", () => {
const error = {
code: "NOT_SIGNED_IN",
message: "Sign in to Anaconda",
policy: { refused: { org: "acme", channel: "acme/main" } },
};
expect(jobErrorSchema.parse(error)).toEqual(error);
expect(jobErrorSchema.parse({ code: "SOLVE_FAILED", message: "x" })).toEqual({
code: "SOLVE_FAILED",
message: "x",
});
});
});

describe("environmentsErrorCodeToKernelErrorCode", () => {
it("maps validation-shaped reasons to VALIDATION", () => {
expect(environmentsErrorCodeToKernelErrorCode("INVALID_MATCHSPEC")).toBe("VALIDATION");
Expand All @@ -266,4 +376,10 @@ describe("environmentsErrorCodeToKernelErrorCode", () => {
expect(environmentsErrorCodeToKernelErrorCode("JOB_CANCELLED")).toBe("BUSINESS");
expect(environmentsErrorCodeToKernelErrorCode("PROVIDER_NOT_READY")).toBe("BUSINESS");
});

it("maps policy and Anaconda sign-in failures to BUSINESS", () => {
expect(environmentsErrorCodeToKernelErrorCode("POLICY_BLOCKED")).toBe("BUSINESS");
expect(environmentsErrorCodeToKernelErrorCode("NOT_SIGNED_IN")).toBe("BUSINESS");
expect(environmentsErrorCodeToKernelErrorCode("CHANNEL_ACCESS_DENIED")).toBe("BUSINESS");
});
});
110 changes: 98 additions & 12 deletions plugins/environments/src/contracts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ export type Provider = z.infer<typeof providerSchema>;
* unchanged, and {@link parseEnvironmentsErrorMessage} recovers the code
* and detail on the renderer side from the same shape.
*
* All codes are uppercase, colon-space separated, single-line.
* All codes are uppercase and colon-space separated. A message may carry one
* extra final line, the {@link POLICY_NOTICE_LINE_PREFIX policy notice}.
*
* `POLICY_BLOCKED` is an organization's package policy blocking a requested
* package. `NOT_SIGNED_IN` and `CHANNEL_ACCESS_DENIED` always mean the
* **Anaconda** account (repo.anaconda.cloud refused a channel because no API
* key is stored, or refused the key), never the Kilo account.
*/
export const environmentsErrorCodeSchema = z.enum([
"PREFIX_NOT_STAGED",
Expand All @@ -61,9 +67,53 @@ export const environmentsErrorCodeSchema = z.enum([
"INVALID_MATCHSPEC",
"INVALID_CHANNEL",
"PROVIDER_NOT_READY",
"POLICY_BLOCKED",
"NOT_SIGNED_IN",
"CHANNEL_ACCESS_DENIED",
]);
export type EnvironmentsErrorCode = z.infer<typeof environmentsErrorCodeSchema>;

/**
* A requested package an organization's package policy removed from a
* channel, as the bridge reports it (`details.blocked[]`, a stable bridge
* contract). `reason` is the platform's explanation, shown verbatim.
*/
export const policyBlockedPackageSchema = z.object({
package: z.string().min(1),
version: z.string().nullable(),
channel: z.string().nullable(),
org: z.string().nullable(),
policy: z.string().nullable(),
/** A UUID; the only policy field telemetry may carry. */
policyId: z.string().nullable(),
reason: z.string().nullable(),
});
export type PolicyBlockedPackage = z.infer<typeof policyBlockedPackageSchema>;

/**
* Package-policy and Anaconda sign-in context of a failure:
*
* - `blocked`: the requested packages a policy removed (`POLICY_BLOCKED`);
* - `policyNote`: the solve failed on a policy channel and no requested
* package was blocked, so a dependency may have been;
* - `refused`: the org and channel repo.anaconda.cloud refused
* (`NOT_SIGNED_IN` / `CHANNEL_ACCESS_DENIED`), each null when unknown.
*/
export const policyNoticeSchema = z.object({
blocked: z.array(policyBlockedPackageSchema).optional(),
policyNote: z.boolean().optional(),
refused: z.object({ org: z.string().nullable(), channel: z.string().nullable() }).optional(),
});
export type PolicyNotice = z.infer<typeof policyNoticeSchema>;

/**
* Prefix of the final message line that carries a {@link PolicyNotice} as
* JSON. `KernelError` crosses processes as a code and a message only, so
* the structured context rides on its own line: the agent reads it as is,
* and {@link parseEnvironmentsErrorMessage} strips it from `detail`.
*/
export const POLICY_NOTICE_LINE_PREFIX = "[policy] ";

/**
* Regex used by {@link parseEnvironmentsErrorMessage} to peel a granular
* environments error code off the front of a KernelError message.
Expand Down Expand Up @@ -93,10 +143,14 @@ const ANSI_ESCAPE_PATTERN = /\u001b\[[0-9;?]*[ -/]*[@-~]/g;
* and UI surfaces render the detail inside `whitespace-pre-wrap` blocks.
* Multi-line details stay parseable because
* {@link ENVIRONMENTS_ERROR_MESSAGE_PATTERN} matches across lines.
*
* A non-empty `policy` is appended as one final
* {@link POLICY_NOTICE_LINE_PREFIX} line.
*/
export function formatEnvironmentsErrorMessage(
code: EnvironmentsErrorCode,
detail?: string,
policy?: PolicyNotice,
): string {
const trimmed = detail
?.replace(ANSI_ESCAPE_PATTERN, "")
Expand All @@ -105,24 +159,51 @@ export function formatEnvironmentsErrorMessage(
.map((line) => line.trimEnd())
.join("\n")
.trim();
return trimmed ? `${code}: ${trimmed}` : code;
const message = trimmed ? `${code}: ${trimmed}` : code;
const hasNotice = policy !== undefined && Object.keys(policy).length > 0;
return hasNotice ? `${message}\n${POLICY_NOTICE_LINE_PREFIX}${JSON.stringify(policy)}` : message;
}

export interface ParsedEnvironmentsError {
code: EnvironmentsErrorCode;
detail?: string;
policy?: PolicyNotice;
}

/**
* Extract the granular reason encoded in a KernelError message
* (`"CODE: detail"` — the shape {@link formatEnvironmentsErrorMessage}
* produces). Returns `null` for messages that do not follow the convention
* (they may still be legitimate KernelErrors — e.g. a kernel-level
* VALIDATION from the router — just not ones this plugin authored).
* (`"CODE: detail"` plus an optional policy-notice line — the shape
* {@link formatEnvironmentsErrorMessage} produces). Returns `null` for
* messages that do not follow the convention (they may still be legitimate
* KernelErrors — e.g. a kernel-level VALIDATION from the router — just not
* ones this plugin authored). A malformed notice line stays in `detail`.
*/
export function parseEnvironmentsErrorMessage(
message: string,
): { code: EnvironmentsErrorCode; detail?: string } | null {
const match = ENVIRONMENTS_ERROR_MESSAGE_PATTERN.exec(message);
export function parseEnvironmentsErrorMessage(message: string): ParsedEnvironmentsError | null {
const { body, policy } = splitPolicyNotice(message);
const match = ENVIRONMENTS_ERROR_MESSAGE_PATTERN.exec(body);
if (!match) return null;
const parsed = environmentsErrorCodeSchema.safeParse(match[1]);
if (!parsed.success) return null;
return match[2] ? { code: parsed.data, detail: match[2] } : { code: parsed.data };
return {
code: parsed.data,
...(match[2] ? { detail: match[2] } : {}),
...(policy ? { policy } : {}),
};
}

function splitPolicyNotice(message: string): { body: string; policy?: PolicyNotice } {
const lineStart = message.lastIndexOf("\n") + 1;
const lastLine = message.slice(lineStart);
if (lineStart === 0 || !lastLine.startsWith(POLICY_NOTICE_LINE_PREFIX)) return { body: message };
let json: unknown;
try {
json = JSON.parse(lastLine.slice(POLICY_NOTICE_LINE_PREFIX.length));
} catch {
return { body: message };
}
const policy = policyNoticeSchema.safeParse(json);
if (!policy.success) return { body: message };
return { body: message.slice(0, lineStart - 1), policy: policy.data };
}

/**
Expand All @@ -149,6 +230,9 @@ const kernelErrorCodeByEnvironmentsErrorCode: Record<
INVALID_MATCHSPEC: "VALIDATION",
INVALID_CHANNEL: "VALIDATION",
PROVIDER_NOT_READY: "BUSINESS",
POLICY_BLOCKED: "BUSINESS",
NOT_SIGNED_IN: "BUSINESS",
CHANNEL_ACCESS_DENIED: "BUSINESS",
};

/**
Expand Down Expand Up @@ -206,11 +290,13 @@ export type JobKind = z.infer<typeof jobKindSchema>;
* Structured error payload attached to terminal `failed` progress events.
* `code` is one of the granular {@link environmentsErrorCodeSchema} values
* (enforced at parse time); `message` is a human-readable detail suitable
* for UI display.
* for UI display. `policy` is the failure's {@link PolicyNotice}, when it
* carried one.
*/
export const jobErrorSchema = z.object({
code: environmentsErrorCodeSchema,
message: z.string().min(1),
policy: policyNoticeSchema.optional(),
});
export type JobError = z.infer<typeof jobErrorSchema>;

Expand Down
Loading