Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(docs): steady doc rows in Cmd+K and `multica doc move` (MUL-8370) (#10978)

Multica Eve078163c90eed
diff --git a/packages/views/search/merge-doc-hits.test.ts b/packages/views/search/merge-doc-hits.test.ts
new file mode 100644
index 0000000000..f83b66e43e
--- /dev/null
+++ b/packages/views/search/merge-doc-hits.test.ts
@@ -0,0 +1,35 @@
+// @vitest-environment node
+import { describe, expect, it } from "vitest";
+import type { DocSummary, SearchDocResult } from "@multica/core/types";
+import { mergeDocHits } from "./use-root-model";
+
+const summary = (id: string, title: string): DocSummary => ({
+ id, workspaceId: "ws", folderId: "eng", title, revision: 1, versionCount: 1,
+ createdByType: "member", createdById: "u", updatedByType: "member", updatedById: "u",
+ createdAt: "2026-11-19T00:00:00Z", updatedAt: "2026-11-19T00:00:00Z",
+});
+const hit = (id: string, title: string, snippet: string | null): SearchDocResult => ({
+ ...summary(id, title), matchSource: snippet ? "content" : "title", matchedSnippet: snippet,
+});
+const folders = new Map([["eng", "Engineering"]]);
+const local = [{ item: { doc: summary("title-hit", "Key rotation"), folder: "Engineering" }, score: 90 }];
+const server = [hit("title-hit", "Key rotation", "...rotation steps..."), hit("body-hit", "Runbook", "...rotate keys...")];
+
+describe("mergeDocHits", () => {
+ it("adds server content hits after the instant title hits, lending excerpts", () => {
+ const merged = mergeDocHits(local, server, folders, "rotat");
+ expect(merged.map((m) => [m.item.doc.id, m.item.snippet, m.item.stale])).toEqual([
+ ["title-hit", "...rotation steps...", undefined],
+ ["body-hit", "...rotate keys...", undefined],
+ ]);
+ expect(merged[1]!.item.folder).toBe("Engineering");
+ });
+
+ it("keeps an earlier query's server rows painted but disabled, without lending excerpts", () => {
+ const merged = mergeDocHits(local, server, folders, "rotati", true);
+ expect(merged.map((m) => [m.item.doc.id, m.item.snippet, m.item.stale])).toEqual([
+ ["title-hit", undefined, undefined],
+ ["body-hit", "...rotate keys...", true],
+ ]);
+ });
+});
diff --git a/packages/views/search/root-view.tsx b/packages/views/search/root-view.tsx
index b4af757b5a..f9132fcf4b 100644
--- a/packages/views/search/root-view.tsx
+++ b/packages/views/search/root-view.tsx
@@ -350,9 +350,10 @@ export function RootView({ model, rawQuery }: { model: RootModel; rawQuery: stri
score: objects.docs[0]!.score,
node: (
<PaletteGroup key="docs" heading={t(($) => $.groups.docs)}>
- {objects.docs.map(({ item: { doc, folder, snippet } }) => (
+ {objects.docs.map(({ item: { doc, folder, snippet, stale } }) => (
<ObjectRow
key={doc.id}
+ disabled={stale}
value={`doc:${doc.id}`}
icon={<FileText className={ROW_ICON_CLASS} />}
title={doc.title || t(($) => $.untitled_doc)}
diff --git a/packages/views/search/use-object-search.ts b/packages/views/search/use-object-search.ts
index 3d044da065..eef66225bb 100644
--- a/packages/views/search/use-object-search.ts
+++ b/packages/views/search/use-object-search.ts
@@ -52,6 +52,11 @@ export interface PaletteDoc {
folder: string | null;
/** Excerpt around a content match, from server search. */
snippet?: string;
+ /**
+ * A server row answering an earlier query: still painted so the list does
+ * not flicker while the next request is in flight, but not selectable.
+ */
+ stale?: boolean;
}
const EMPTY_AUTOPILOTS: Autopilot[] = [];
diff --git a/packages/views/search/use-root-model.ts b/packages/views/search/use-root-model.ts
index c3a4aae50d..669523e308 100644
--- a/packages/views/search/use-root-model.ts
+++ b/packages/views/search/use-root-model.ts
@@ -111,16 +111,20 @@ export function issueScore(issue: SearchIssueResult, q: string): number {
* Title hits from the cached doc tree answer on every keystroke; the server
* adds what only it can find, content matches with an excerpt. A doc found
* both ways keeps its instant row, picking up the server's excerpt if any.
+ * While the server is still answering an earlier query (`stale`), its rows
+ * stay painted but disabled, the way stale issue rows are, and lend no
+ * excerpts to the fresh title hits.
*/
export function mergeDocHits(
local: Scored<PaletteDoc>[],
server: SearchDocResult[],
folders: ReadonlyMap<string, string>,
q: string,
+ stale = false,
): Scored<PaletteDoc>[] {
const fromServer = new Map(server.map((doc) => [doc.id, doc]));
const merged = local.map((hit) => {
- const snippet = fromServer.get(hit.item.doc.id)?.matchedSnippet;
+ const snippet = stale ? null : fromServer.get(hit.item.doc.id)?.matchedSnippet;
return snippet ? { ...hit, item: { ...hit.item, snippet } } : hit;
});
const listed = new Set(local.map((hit) => hit.item.doc.id));
@@ -131,6 +135,7 @@ export function mergeDocHits(
doc,
folder: doc.folderId ? (folders.get(doc.folderId) ?? null) : null,
...(doc.matchedSnippet ? { snippet: doc.matchedSnippet } : {}),
+ ...(stale ? { stale: true } : {}),
},
score: Math.max(scoreText(doc.title, q), SERVER_ONLY_SCORE),
});
@@ -270,15 +275,14 @@ export function useRootModel(
autopilots: scope === "all" ? objects.autopilots : [],
chats: scope === "all" ? objects.chats : [],
skills: scope === "all" ? objects.skills : [],
- // Server doc rows answering an earlier query are dropped rather than
- // shown stale; the instant title hits cover the gap until they land.
docs:
scope === "all"
? mergeDocHits(
objects.docs,
- docSearch.query === searching.trim() ? docSearch.docs : [],
+ docSearch.docs,
objects.docFolders,
q,
+ docSearch.query !== searching.trim(),
)
: [],
workspaces: scope === "all" ? objects.workspaces : [],
diff --git a/server/cmd/multica/cmd_doc.go b/server/cmd/multica/cmd_doc.go
index 87203f854c..8968afd721 100644
--- a/server/cmd/multica/cmd_doc.go
+++ b/server/cmd/multica/cmd_doc.go
@@ -49,6 +49,16 @@ var docSearchCmd = &cobra.Command{
RunE: runDocSearch,
}
+var docMoveCmd = &cobra.Command{
+ Use: "move <doc-id>",
+ Short: "Move a doc into a folder, or to the top level",
+ Long: "Move a doc into another folder of the workspace knowledge base.\n\n" +
+ "--folder takes a folder id (or a unique prefix of one from `multica doc list`), " +
+ "or `root` for the top level. Moving does not change the doc's content or revision.",
+ Args: exactArgs(1),
+ RunE: runDocMove,
+}
+
var docGetCmd = &cobra.Command{
Use: "get <doc-id>",
Short: "Get a doc with its content and current revision",
@@ -70,7 +80,9 @@ var docUpdateCmd = &cobra.Command{
}
func init() {
- docCmd.AddCommand(docListCmd, docSearchCmd, docGetCmd, docCreateCmd, docUpdateCmd)
+ docCmd.AddCommand(docListCmd, docSearchCmd, docGetCmd, docCreateCmd, docUpdateCmd, docMoveCmd)
+ docMoveCmd.Flags().String("folder", "", "Destination folder id, or `root` for the top level (required)")
+ docMoveCmd.Flags().String("output", "json", "Output format: table or json")
docListCmd.Flags().String("output", "table", "Output format: table or json")
docSearchCmd.Flags().Int("limit", 20, "Maximum results (at most 50)")
docSearchCmd.Flags().String("output", "table", "Output format: table or json")
@@ -272,6 +284,34 @@ func runDocSearch(cmd *cobra.Command, args []string) error {
return nil
}
+func runDocMove(cmd *cobra.Command, args []string) error {
+ destination, _ := cmd.Flags().GetString("folder")
+ if strings.TrimSpace(destination) == "" {
+ return fmt.Errorf("--folder is required: a folder id, or `root` for the top level")
+ }
+ client, err := newAPIClient(cmd)
+ if err != nil {
+ return err
+ }
+ ctx, cancel := cli.APIContext(context.Background())
+ defer cancel()
+
+ id, err := resolveDocRef(ctx, client, args[0], false)
+ if err != nil {
+ return err
+ }
+ folder, err := resolveDocFolderTarget(ctx, client, destination)
+ if err != nil {
+ return err
+ }
+ var doc map[string]any
+ if err := client.PostJSON(ctx, "/api/docs/"+id+"/move", map[string]any{"folder_id": folder}, &doc); err != nil {
+ return fmt.Errorf("move doc: %w", err)
+ }
+ output, _ := cmd.Flags().GetString("output")
+ return printDocSummary(doc, output)
+}
+
func runDocGet(cmd *cobra.Command, args []string) error {
client, err := newAPIClient(cmd)
if err != nil {
diff --git a/server/cmd/multica/cmd_doc_test.go b/server/cmd/multica/cmd_doc_test.go
index a855bc3193..29732da22e 100644
--- a/server/cmd/multica/cmd_doc_test.go
+++ b/server/cmd/multica/cmd_doc_test.go
@@ -13,7 +13,7 @@ import (
)
func TestDocCommandsExposeOnlyAgentReadWrite(t *testing.T) {
- expected := map[string]bool{"list": true, "search": true, "get": true, "create": true, "update": true}
+ expected := map[string]bool{"list": true, "search": true, "get": true, "create": true, "update": true, "move": true}
for _, command := range docCmd.Commands() {
if !expected[command.Name()] {
t.Fatalf("unexpected doc command: %s", command.Name())
@@ -66,3 +66,37 @@ func TestRunDocSearchQueriesServerSearch(t *testing.T) {
t.Fatalf("table output missing the hit: %q", out)
}
}
+
+func TestRunDocMoveSendsDestination(t *testing.T) {
+ const docID = "11111111-2222-3333-4444-555555555555"
+ const folderID = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
+ var gotPath string
+ var gotBody map[string]any
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ gotPath = r.URL.Path
+ _ = json.NewDecoder(r.Body).Decode(&gotBody)
+ w.Header().Set("Content-Type", "application/json")
+ _ = json.NewEncoder(w).Encode(map[string]any{"id": docID, "title": "Runbook", "folder_id": gotBody["folder_id"]})
+ }))
+ defer srv.Close()
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "mat_test-token")
+
+ for _, tc := range []struct {
+ folder string
+ want any
+ }{{folderID, folderID}, {"root", nil}} {
+ _ = docMoveCmd.Flags().Set("folder", tc.folder)
+ if _, err := captureStdout(t, func() error { return runDocMove(docMoveCmd, []string{docID}) }); err != nil {
+ t.Fatalf("runDocMove(%s): %v", tc.folder, err)
+ }
+ if gotPath != "/api/docs/"+docID+"/move" || gotBody["folder_id"] != tc.want {
+ t.Fatalf("--folder %s sent %s %v", tc.folder, gotPath, gotBody)
+ }
+ }
+ _ = docMoveCmd.Flags().Set("folder", "")
+ if err := runDocMove(docMoveCmd, []string{docID}); err == nil || !strings.Contains(err.Error(), "--folder is required") {
+ t.Fatalf("missing --folder must explain itself: %v", err)
+ }
+}
diff --git a/server/internal/daemon/execenv/runtime_config_kind_test.go b/server/internal/daemon/execenv/runtime_config_kind_test.go
index dd3fdf28c8..78e88575e2 100644
--- a/server/internal/daemon/execenv/runtime_config_kind_test.go
+++ b/server/internal/daemon/execenv/runtime_config_kind_test.go
@@ -84,7 +84,7 @@ func TestBuildMetaSkillContentDocsFollowFlag(t *testing.T) {
for _, enabled := range []bool{false, true} {
out := buildMetaSkillContent("claude", TaskContextForEnv{IssueID: "issue-1", DocsEnabled: enabled})
- for _, line := range []string{"`multica doc list|search|get|create|update`", "mention://doc/<doc-id>"} {
+ for _, line := range []string{"`multica doc list|search|get|create|update|move`", "mention://doc/<doc-id>"} {
if got := strings.Contains(out, line); got != enabled {
t.Errorf("DocsEnabled=%v: brief contains %q = %v\n---\n%s", enabled, line, got, out)
}
diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.go
index 31ba491971..6538c2c0ec 100644
--- a/server/internal/daemon/execenv/runtime_config_sections.go
+++ b/server/internal/daemon/execenv/runtime_config_sections.go
@@ -278,7 +278,7 @@ func writeAvailableCommands(b *strings.Builder, ctx TaskContextForEnv) {
b.WriteString("- `multica issue wakeup <create|list|get|update|disable|trigger|delete|runs|events>` — persist an event, condition or time wakeup on this issue, then finish the current run. When the platform can check the fact itself, use one `--until-*` condition so no run starts before it holds; check the rule's `last_error` for missing PR links or snapshots, which are retried automatically. Conditions, PR rules and actor filters: `multica issue wakeup create --help` and the multica-platform issues reference.\n")
b.WriteString("- `multica issue children <id> [--output json]` — list a parent's sub-issues grouped by stage.\n")
if ctx.DocsEnabled {
- b.WriteString("- `multica doc list|search|get|create|update` — workspace docs; `doc search <query>` matches titles and content; `doc update` needs `--base-revision` from `multica doc get` (details: `multica doc --help`).\n")
+ b.WriteString("- `multica doc list|search|get|create|update|move` — workspace docs; `doc search <query>` matches titles and content; `doc update` needs `--base-revision` from `multica doc get` (details: `multica doc --help`).\n")
}
b.WriteString("- `multica issue comment add <issue-id> [--content \"...\" | --content-file <path> | --content-stdin] [--parent <comment-id>] [--attachment <path>]` — post a comment. Agent-authored bodies MUST use `--content-file` with a file inside your working directory; full flags: `multica issue comment add --help`.\n")
b.WriteString("- `multica repo checkout <url> [--ref <branch-or-sha>] [--fresh]` — repository checkout on a dedicated branch; re-running it keeps a checkout that has uncommitted or unpushed work, or is already on this task's branch, and only fetches; a clean, fully pushed checkout on another branch starts over on a new branch. `--fresh` discards uncommitted and untracked files for a new branch; commits stay on the old branch, so push any you still need first.\n\n")