Skip to content

Commit 88af60f

Browse files
sahrizviclaude
andcommitted
feat(workspace): skill publish <name> and a "Publish to workspace" action
Retargeted onto main after #1280 merged; rebuilt as one commit carrying only this PR's change (the stacked history interleaved #1280's commits). The publish path from #1280 had no surface: nothing invoked it, so a locally authored skill still had no route to the workspace, and the CLI still did not say whether one existed. - `altimate-code skill publish <name>` resolves the skill the way `skill test` does, refuses a built-in (`skillSource`, which also knows the `~/.altimate/builtin` install), and prints one line on success. Every deliberate refusal — not linked, not the workspace's owner, workspace- owned, binary or linked file, empty, too large, name taken elsewhere, edited elsewhere mid-upload, uploaded but not attached — is printed as-is, since each already says what to do. - The Skills dialog gains "Publish to workspace" in the per-skill action picker, next to Show / Edit / Test / Remove — where a user who wonders whether publishing is possible will see it. Disabled for built-ins and for skills the workspace sent us; judged against `api.state.path .directory`, where the binding and the snapshot live. - `describePublish` and `explainPublishError` give both surfaces the same words; a `skill_published` telemetry event records the outcome with its source. Verified: 625 pass across the workspace, plugin and fork-guard suites on main; typecheck clean. `skill publish` exercised end to end against prod on a throwaway workspace (see #1280) — this command is what ran it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
1 parent 236e73c commit 88af60f

5 files changed

Lines changed: 177 additions & 0 deletions

File tree

‎packages/opencode/src/altimate/telemetry/index.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,15 @@ export namespace Telemetry {
716716
skill_name: string
717717
source: "cli" | "tui"
718718
}
719+
| {
720+
type: "skill_published"
721+
timestamp: number
722+
session_id: string
723+
skill_name: string
724+
action: "created" | "updated"
725+
file_count: number
726+
source: "cli" | "tui"
727+
}
719728
// altimate_change end
720729
// altimate_change start — plan refinement telemetry event
721730
| {

‎packages/opencode/src/altimate/workspace/skill-publish.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,34 @@ async function publishSkillUnlocked(input: {
721721
return { action: "created", publicId, name: input.name, files: files.length, bytes, datamateId: binding.datamateId }
722722
}
723723

724+
/** One line for a surface to show after a publish. Both the CLI and the TUI
725+
* say the same thing, so a user moving between them recognises the outcome. */
726+
export function describePublish(report: PublishReport): string {
727+
const verb = report.action === "created" ? "Published" : "Updated"
728+
const size = report.bytes >= 1024 ? `${Math.round(report.bytes / 1024)}KB` : `${report.bytes}B`
729+
return `${verb} "${report.name}" in the workspace (${report.files} file${report.files === 1 ? "" : "s"}, ${size}).`
730+
}
731+
732+
/** The message for an error this module raised on purpose, or null for one it
733+
* did not — a surface shows the former as-is (each already says what to do)
734+
* and wraps the latter as a failure. */
735+
export function explainPublishError(err: unknown): string | null {
736+
if (
737+
err instanceof NotLinkedError ||
738+
err instanceof ManagedSkillError ||
739+
err instanceof BinaryFileError ||
740+
err instanceof SymlinkError ||
741+
err instanceof EmptyBundleError ||
742+
err instanceof BundleTooLargeError ||
743+
err instanceof SkillNameConflictError ||
744+
err instanceof SkillChangedElsewhereError ||
745+
err instanceof NotWorkspaceOwnerError ||
746+
err instanceof AttachFailedError
747+
)
748+
return err.message
749+
return null
750+
}
751+
724752
/** Which of the update path's conflicts this is. The server distinguishes them
725753
* in its detail; this module's typed errors then carry advice that fits.
726754
* Anything unrecognised keeps the server's own words rather than being

‎packages/opencode/src/cli/cmd/skill.ts‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Global } from "@/global"
1111
import { detectToolReferences, skillSource, isToolOnPath } from "./skill-helpers"
1212
// altimate_change start — telemetry for skill operations
1313
import { Telemetry } from "@/altimate/telemetry"
14+
import { describePublish, explainPublishError, publishSkill } from "@/altimate/workspace/skill-publish"
1415
// altimate_change end
1516

1617
// ---------------------------------------------------------------------------
@@ -457,6 +458,61 @@ const SkillTestCommand = cmd({
457458
},
458459
})
459460

461+
const SkillPublishCommand = cmd({
462+
command: "publish <name>",
463+
describe: "publish a skill to the workspace this project is linked to",
464+
builder: (yargs) =>
465+
yargs.positional("name", {
466+
type: "string",
467+
describe: "name of the skill to publish",
468+
demandOption: true,
469+
}),
470+
async handler(args) {
471+
const name = args.name as string
472+
const cwd = process.cwd()
473+
await bootstrap(cwd, async () => {
474+
const skill = await Skill.get(name)
475+
if (!skill) {
476+
process.stderr.write(`Skill "${name}" not found. Check .opencode/skills/${name}/SKILL.md exists.` + EOL)
477+
process.exitCode = 1
478+
return
479+
}
480+
// Built-in skills ship with altimate-code — embedded, or installed under
481+
// `~/.altimate/builtin` — and are not the user's to publish; a skill the
482+
// workspace sent us is refused by `publishSkill` itself.
483+
if (skillSource(skill.location) === "builtin" || !path.isAbsolute(skill.location)) {
484+
process.stderr.write(`"${name}" is a built-in skill and cannot be published.` + EOL)
485+
process.exitCode = 1
486+
return
487+
}
488+
try {
489+
const report = await publishSkill({
490+
projectDirectory: Instance.directory,
491+
skillDirectory: path.dirname(skill.location),
492+
name: skill.name,
493+
description: skill.description ?? "",
494+
})
495+
process.stdout.write(describePublish(report) + EOL)
496+
try {
497+
Telemetry.track({
498+
type: "skill_published",
499+
timestamp: Date.now(),
500+
session_id: Telemetry.getContext().sessionId || "",
501+
skill_name: skill.name,
502+
action: report.action,
503+
file_count: report.files,
504+
source: "cli",
505+
})
506+
} catch {}
507+
} catch (err) {
508+
const known = explainPublishError(err)
509+
process.stderr.write((known ?? `Publish failed: ${err instanceof Error ? err.message : String(err)}`) + EOL)
510+
process.exitCode = 1
511+
}
512+
})
513+
},
514+
})
515+
460516
const SkillShowCommand = cmd({
461517
command: "show <name>",
462518
describe: "display the full content of a skill",
@@ -738,6 +794,7 @@ export const SkillCommand = cmd({
738794
.command(SkillListCommand)
739795
.command(SkillCreateCommand)
740796
.command(SkillTestCommand)
797+
.command(SkillPublishCommand)
741798
.command(SkillShowCommand)
742799
.command(SkillInstallCommand)
743800
.command(SkillRemoveCommand)

‎packages/opencode/src/plugin/tui/altimate/skill-ops.tsx‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import type { TuiPlugin, TuiPluginApi, TuiDialogSelectOption } from "@opencode-a
2727
import type { BuiltinTuiPlugin } from "@opencode-ai/tui/builtins"
2828
import { createMemo, createResource, createSignal, Show } from "solid-js"
2929
import { detectToolReferences } from "@/cli/cmd/skill-helpers"
30+
import { describePublish, explainPublishError, isManagedSkill, publishSkill } from "@/altimate/workspace/skill-publish"
31+
import { Telemetry } from "@/altimate/telemetry"
3032
import { spawn } from "child_process"
3133
import os from "os"
3234
import path from "path"
@@ -503,12 +505,24 @@ function isRemovable(info: SkillInfo): boolean {
503505
function openActionPicker(api: TuiPluginApi, info: SkillInfo | undefined, skillName: string, reopen: () => void) {
504506
const isBuiltin = !info || info.location.startsWith("builtin:") || !path.isAbsolute(info.location)
505507
const removable = !!info && isRemovable(info)
508+
// A skill the workspace sent us is not ours to publish back to it. Judged
509+
// against the project directory workspace sync uses — the binding and the
510+
// managed snapshot live under `api.state.path.directory`, not the git root
511+
// `workdir` resolves to, and the two differ in a worktree subdirectory.
512+
const projectDirectory = api.state.path.directory || workdir(api)
513+
const managed = !isBuiltin && isManagedSkill(projectDirectory, path.dirname(info!.location))
506514

507515
const actions: TuiDialogSelectOption<string>[] = (
508516
[
509517
{ title: "Show details", value: "show", description: "View skill info, tools, and location" },
510518
{ title: "Edit", value: "edit", description: "Open SKILL.md in your default editor", disabled: isBuiltin },
511519
{ title: "Test", value: "test", description: "Validate the paired CLI tool works" },
520+
{
521+
title: "Publish to workspace",
522+
value: "publish",
523+
description: "Upload this skill to the linked workspace so your team gets it",
524+
disabled: isBuiltin || managed,
525+
},
512526
{ title: "Remove", value: "remove", description: "Delete this skill and its paired tool", disabled: !removable },
513527
] as TuiDialogSelectOption<string>[]
514528
).filter((a) => !a.disabled)
@@ -559,6 +573,39 @@ function openActionPicker(api: TuiPluginApi, info: SkillInfo | undefined, skillN
559573
reopen()
560574
break
561575
}
576+
case "publish": {
577+
if (!info) return
578+
api.ui.toast({ message: `Publishing ${skillName}...`, variant: "info", duration: 120_000 })
579+
try {
580+
const report = await publishSkill({
581+
projectDirectory,
582+
skillDirectory: path.dirname(info.location),
583+
name: skillName,
584+
description: info.description ?? "",
585+
})
586+
api.ui.toast({ message: describePublish(report), variant: "success", duration: 6000 })
587+
try {
588+
Telemetry.track({
589+
type: "skill_published",
590+
timestamp: Date.now(),
591+
session_id: Telemetry.getContext().sessionId || "",
592+
skill_name: skillName,
593+
action: report.action,
594+
file_count: report.files,
595+
source: "tui",
596+
})
597+
} catch {}
598+
} catch (err) {
599+
const known = explainPublishError(err)
600+
api.ui.toast({
601+
message: known ?? `Publish failed: ${(err instanceof Error ? err.message : String(err)).slice(0, 150)}`,
602+
variant: known ? "warning" : "error",
603+
duration: 8000,
604+
})
605+
}
606+
reopen()
607+
break
608+
}
562609
case "remove": {
563610
if (!info) return
564611
try {

‎packages/opencode/test/altimate/workspace/skill-publish.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const {
4949
SkillNameConflictError,
5050
SymlinkError,
5151
collectBundle,
52+
describePublish,
53+
explainPublishError,
5254
isManagedSkill,
5355
ledgerPathForTests,
5456
publishSkill,
@@ -803,3 +805,37 @@ describe("attaching to the workspace", () => {
803805
expect(requests.filter((r) => r.method === "POST")).toHaveLength(0)
804806
})
805807
})
808+
809+
describe("what a surface says", () => {
810+
// The CLI and the TUI share these lines so a user moving between them
811+
// recognises the outcome.
812+
test("names the outcome, the skill, and the size", () => {
813+
const line = describePublish({ action: "created", publicId: "p", name: "deploy", files: 3, bytes: 2048, datamateId: 1 })
814+
expect(line).toContain("Published")
815+
expect(line).toContain('"deploy"')
816+
expect(line).toContain("3 files")
817+
expect(line).toContain("2KB")
818+
expect(describePublish({ action: "updated", publicId: "p", name: "d", files: 1, bytes: 12, datamateId: 1 })).toContain(
819+
"Updated",
820+
)
821+
expect(describePublish({ action: "updated", publicId: "p", name: "d", files: 1, bytes: 12, datamateId: 1 })).toContain(
822+
"1 file,",
823+
)
824+
})
825+
826+
test("passes a deliberate error through and wraps nothing else", async () => {
827+
// Each typed error already says what to do; an unexpected one must not be
828+
// shown as if it were advice.
829+
const unlinked = mkdtempSync(path.join(SANDBOX, "unlinked-"))
830+
const dir = path.join(unlinked, "skills", "x")
831+
mkdirSync(dir, { recursive: true })
832+
writeFileSync(path.join(dir, "SKILL.md"), "---\nname: x\n---\n")
833+
const err = await publishSkill({ projectDirectory: unlinked, skillDirectory: dir, name: "x", description: "d" }).catch(
834+
(e) => e,
835+
)
836+
expect(err).toBeInstanceOf(NotLinkedError)
837+
expect(explainPublishError(err)).toContain("altimate-code link")
838+
expect(explainPublishError(new SymlinkError("references"))).toContain("references")
839+
expect(explainPublishError(new Error("ECONNRESET"))).toBeNull()
840+
})
841+
})

0 commit comments

Comments
 (0)