Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(cli): allow task-scoped daemon status and disk-usage (MUL-5742) (#6684)
Bohan Jiang90b3c2cc5258
diff --git a/apps/docs/content/docs/cli.mdx b/apps/docs/content/docs/cli.mdxindex 12512ee497..5ab2f7c9bd 100644--- a/apps/docs/content/docs/cli.mdx+++ b/apps/docs/content/docs/cli.mdx@@ -212,7 +212,9 @@ multica config showmultica config show --profile staging```-When the CLI runs inside a daemon-managed agent task, it does not load or modify these human-owned profile files. Multica API commands authenticate with the task-scoped credential injected by the daemon. `config show` and `config set` use private task-local state; human/local commands such as `login`, `logout`, `setup`, `workspace switch`, local runtime profile path changes, and `daemon` lifecycle or diagnostic commands are unavailable. `auth status` does not print token material in this context.+When the CLI runs inside a daemon-managed agent task, it does not load or modify these human-owned profile files. Multica API commands authenticate with the task-scoped credential injected by the daemon. `config show` and `config set` use private task-local state; human/local commands such as `login`, `logout`, `setup`, `workspace switch`, local runtime profile path changes, `daemon start` / `stop` / `restart`, `daemon logs`, and `daemon probe-runtimes` are unavailable. `auth status` does not print token material in this context.++`daemon status` and `daemon disk-usage` stay available so an agent can inspect the runtime hosting it, scoped to that runtime: `status` probes the health port the daemon injected, and `disk-usage` scans the workspaces root the daemon injected. Neither accepts `--profile`, `disk-usage` also rejects `--all-profiles` and `--workspaces-root`, and its STATUS column is blank because resolving it would require the human's stored token. Use `du` and `df` for anything outside that scope.This protects implicit Multica CLI profile resolution while preserving the normal `HOME` and XDG variables used by other provider tools. It is not an OS filesystem boundary: processes running as the same system user may still open an explicitly known path. Use a dedicated user, container, VM, or equivalent isolation when that stronger guarantee is required.diff --git a/server/cmd/multica/cmd_daemon.go b/server/cmd/multica/cmd_daemon.goindex 0dfa065405..798fb6ef21 100644--- a/server/cmd/multica/cmd_daemon.go+++ b/server/cmd/multica/cmd_daemon.go@@ -1087,11 +1087,11 @@ func requestDaemonShutdown(healthPort int) error {// --- daemon status ---func runDaemonStatus(cmd *cobra.Command, _ []string) error {- if err := requireHumanLocalCommand("daemon status"); err != nil {+ profile := resolveProfile(cmd)+ healthPort, err := daemonStatusHealthPort(cmd)+ if err != nil {return err}- profile := resolveProfile(cmd)- healthPort := healthPortForProfile(profile)ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)defer cancel()@@ -1119,6 +1119,32 @@ func runDaemonStatus(cmd *cobra.Command, _ []string) error {return nil}+// daemonStatusHealthPort resolves which daemon `status` should probe. Outside a+// task that is the --profile-derived port. Inside a managed task it is the+// daemon-injected MULTICA_DAEMON_PORT and nothing else: healthPortForProfile+// hashes whatever profile name the caller passes, so deriving the port there+// would let a task report on a daemon that is not the one hosting it — and for+// a task hosted by a named-profile daemon it would silently probe the default+// daemon instead. A missing port fails closed rather than guessing.+func daemonStatusHealthPort(cmd *cobra.Command) (int, error) {+ profile := resolveProfile(cmd)+ if !inDaemonManagedExecutionContext() {+ return healthPortForProfile(profile), nil+ }+ if profile != "" {+ return 0, fmt.Errorf("daemon status --profile is not available inside a daemon-managed task")+ }+ raw := strings.TrimSpace(os.Getenv("MULTICA_DAEMON_PORT"))+ if raw == "" {+ return 0, fmt.Errorf("daemon status inside a daemon-managed task requires the daemon-injected MULTICA_DAEMON_PORT")+ }+ port, err := strconv.Atoi(raw)+ if err != nil || port <= 0 {+ return 0, fmt.Errorf("invalid MULTICA_DAEMON_PORT %q inside a daemon-managed task", raw)+ }+ return port, nil+}+// printDaemonStatusReport renders a key/value summary of the daemon health// response. The value column is aligned to the widest label so the dynamic// "Daemon [profile]" row stays in step with the static rows below it.@@ -1356,9 +1382,7 @@ func resolveDaemonDisableSignal(flagValue bool, envName string, cfgValue bool) b// --- daemon disk-usage ---func runDaemonDiskUsage(cmd *cobra.Command, _ []string) error {- if err := requireHumanLocalCommand("daemon disk-usage"); err != nil {- return err- }+ taskContext := inDaemonManagedExecutionContext()profile := resolveProfile(cmd)rootOverride, _ := cmd.Flags().GetString("workspaces-root")byWorkspace, _ := cmd.Flags().GetBool("by-workspace")@@ -1367,6 +1391,11 @@ func runDaemonDiskUsage(cmd *cobra.Command, _ []string) error {output, _ := cmd.Flags().GetString("output")allProfiles, _ := cmd.Flags().GetBool("all-profiles")+ if taskContext {+ if err := checkTaskDiskUsageScope(profile, rootOverride, allProfiles); err != nil {+ return err+ }+ }if byWorkspace && byTask {return fmt.Errorf("--by-workspace and --by-task are mutually exclusive")}@@ -1381,7 +1410,7 @@ func runDaemonDiskUsage(cmd *cobra.Command, _ []string) error {return runDaemonDiskUsageAggregate(cmd, byWorkspace, top, output)}- workspacesRoot, err := daemon.ResolveWorkspacesRoot(profile, rootOverride)+ workspacesRoot, err := resolveDiskUsageRoot(taskContext, profile, rootOverride)if err != nil {return fmt.Errorf("resolve workspaces root: %w", err)}@@ -1392,7 +1421,9 @@ func runDaemonDiskUsage(cmd *cobra.Command, _ []string) error {}// Resolve before --top trims the slice: the batch endpoint costs the same// either way, and the JSON consumer sees statuses for everything it gets.- if diskUsageNeedsParentStatus(byWorkspace, output) {+ // Skipped in a task: the fetcher authenticates with the Owner profile's+ // stored token, which a task must not borrow, so the column stays blank.+ if !taskContext && diskUsageNeedsParentStatus(byWorkspace, output) {fillDiskUsageParentStatuses(cmd, profile, &report)}@@ -1412,14 +1443,50 @@ func runDaemonDiskUsage(cmd *cobra.Command, _ []string) error {if byWorkspace {printDiskUsageWorkspaceTable(os.Stdout, report)- printDiskUsageOtherRootsHint(os.Stdout, report, profile, rootOverride)+ printDiskUsageOtherRootsHint(os.Stdout, report, profile, rootOverride, taskContext)return nil}printDiskUsageTaskTable(os.Stdout, report)- printDiskUsageOtherRootsHint(os.Stdout, report, profile, rootOverride)+ printDiskUsageOtherRootsHint(os.Stdout, report, profile, rootOverride, taskContext)+ return nil+}++// checkTaskDiskUsageScope keeps a managed task's disk-usage view inside the+// daemon root that hosts it. Each rejected input widens the report past that+// boundary: --all-profiles enumerates ~/.multica/profiles and discloses the+// Owner's profile names, while --workspaces-root and --profile aim the scan at+// a directory this daemon does not manage.+func checkTaskDiskUsageScope(profile, rootOverride string, allProfiles bool) error {+ switch {+ case allProfiles:+ return fmt.Errorf("daemon disk-usage --all-profiles is not available inside a daemon-managed task")+ case rootOverride != "":+ return fmt.Errorf("daemon disk-usage --workspaces-root is not available inside a daemon-managed task")+ case profile != "":+ return fmt.Errorf("daemon disk-usage --profile is not available inside a daemon-managed task")+ }return nil}+// resolveDiskUsageRoot picks the directory to scan. A managed task reads the+// daemon-injected root only: ResolveWorkspacesRoot falls back to a $HOME- and+// profile-derived default, which for a task hosted by a named-profile daemon+// resolves to the default root and reports a tree the task has nothing to do+// with. Failing closed on a missing value keeps that guess out of the output.+func resolveDiskUsageRoot(taskContext bool, profile, rootOverride string) (string, error) {+ if !taskContext {+ return daemon.ResolveWorkspacesRoot(profile, rootOverride)+ }+ root := strings.TrimSpace(os.Getenv(daemon.TaskWorkspacesRootEnv))+ if root == "" {+ return "", fmt.Errorf("daemon-managed task requires the daemon-injected workspaces root in %s", daemon.TaskWorkspacesRootEnv)+ }+ if !filepath.IsAbs(root) {+ return "", fmt.Errorf("%s must be an absolute path", daemon.TaskWorkspacesRootEnv)+ }+ return filepath.Clean(root), nil+}+// diskUsageNeedsParentStatus reports whether this invocation renders per-task// rows at all. The --by-workspace table has no STATUS column, so resolving// statuses for it would spend a network round trip — and, against an@@ -1698,10 +1765,17 @@ func printDiskUsageWorkspaceTable(w io.Writer, report daemon.DiskUsageReport) {// app's `desktop-<host>` root behind a non-empty default root. It fires// whenever such roots exist (empty current root or not); the only opt-out is an// explicit --workspaces-root, where the user already chose exactly what to scan.-func printDiskUsageOtherRootsHint(w io.Writer, report daemon.DiskUsageReport, profile, rootOverride string) {+func printDiskUsageOtherRootsHint(w io.Writer, report daemon.DiskUsageReport, profile, rootOverride string, taskContext bool) {if rootOverride != "" {return}+ // The suggestions are built by listing ~/.multica/profiles, so printing+ // them inside a task would disclose the Owner's profile names — exactly+ // what rejecting --all-profiles prevents — and every command they suggest+ // is rejected there anyway.+ if taskContext {+ return+ }suggestions := diskUsageProfileSuggestions(profile, report.WorkspacesRoot)if len(suggestions) == 0 {returndiff --git a/server/cmd/multica/cmd_daemon_diskusage_status_test.go b/server/cmd/multica/cmd_daemon_diskusage_status_test.goindex 132dc658ae..4018bc7adf 100644--- a/server/cmd/multica/cmd_daemon_diskusage_status_test.go+++ b/server/cmd/multica/cmd_daemon_diskusage_status_test.go@@ -136,6 +136,16 @@ func setupDiskUsageProfile(t *testing.T, home, profile, token, serverURL, wsID,}}+// pinHumanCLIContext puts a test on the human side of the task boundary. The+// CLI infers task context partly from a daemon marker in an ancestor directory,+// so a checkout that happens to live under a daemon workspaces root would+// otherwise make these human-path tests exercise the task path instead.+func pinHumanCLIContext(t *testing.T) {+ t.Helper()+ t.Chdir(t.TempDir())+ clearDaemonTaskEnv(t)+}+// TestDiskUsageNeedsParentStatus pins the gate itself: the per-task table and// any JSON output need statuses; the --by-workspace table has no STATUS column// and must not trigger a request.@@ -163,6 +173,7 @@ func TestDiskUsageNeedsParentStatus(t *testing.T) {// guard: with valid credentials on disk, the --by-workspace table must still// resolve nothing, so an unreachable server cannot make a local diagnostic hang.func TestRunDaemonDiskUsageByWorkspaceTableMakesNoRequest(t *testing.T) {+ pinHumanCLIContext(t)home := t.TempDir()t.Setenv("HOME", home)t.Setenv("MULTICA_WORKSPACES_ROOT", "")@@ -193,6 +204,7 @@ func TestRunDaemonDiskUsageByWorkspaceTableMakesNoRequest(t *testing.T) {// TestRunDaemonDiskUsageTaskTableResolvesStatus is the positive half: the// default per-task view does resolve, and the status reaches the rendered table.func TestRunDaemonDiskUsageTaskTableResolvesStatus(t *testing.T) {+ pinHumanCLIContext(t)home := t.TempDir()t.Setenv("HOME", home)t.Setenv("MULTICA_WORKSPACES_ROOT", "")@@ -219,6 +231,7 @@ func TestRunDaemonDiskUsageTaskTableResolvesStatus(t *testing.T) {// contract: a failing server must not fail the command or corrupt stdout, so// scripts consuming --output json keep working when the API is down.func TestRunDaemonDiskUsageJSONSurvivesServerFailure(t *testing.T) {+ pinHumanCLIContext(t)home := t.TempDir()t.Setenv("HOME", home)t.Setenv("MULTICA_WORKSPACES_ROOT", "")@@ -263,6 +276,7 @@ func TestRunDaemonDiskUsageJSONSurvivesServerFailure(t *testing.T) {// wiring in aggregate mode: each root must be resolved with its own profile's// token, not whichever one happened to be loaded first.func TestRunDaemonDiskUsageAllProfilesUsesPerProfileToken(t *testing.T) {+ pinHumanCLIContext(t)home := t.TempDir()t.Setenv("HOME", home)t.Setenv("MULTICA_WORKSPACES_ROOT", "")@@ -355,3 +369,129 @@ func TestPrintRepoCacheLineSilentWhenEmpty(t *testing.T) {t.Errorf("empty repo cache must not print a line:\n%s", buf.String())}}++// setupTaskDiskUsageContext puts the caller inside a managed task whose daemon+// injected workspacesRoot, and seeds an Owner profile (token + its own task+// tree under HOME) that the task must not touch. It returns the injected root.+func setupTaskDiskUsageContext(t *testing.T, home, ownerServerURL string) string {+ t.Helper()+ t.Chdir(t.TempDir())+ t.Setenv("HOME", home)+ t.Setenv("MULTICA_WORKSPACES_ROOT", "")+ t.Setenv("MULTICA_SERVER_URL", "")++ // Owner profile: a real token plus a task dir under the HOME-derived root.+ setupDiskUsageProfile(t, home, "", "token-owner", ownerServerURL,+ "11111111-1111-1111-1111-111111111111", "0wner000", "issue-owner")++ injectedRoot := filepath.Join(t.TempDir(), "daemon-workspaces")+ writeDiskUsageIssueTask(t, injectedRoot,+ "22222222-2222-2222-2222-222222222222", "7a5c0000", "issue-task")++ t.Setenv("MULTICA_AGENT_ID", "agent-test")+ t.Setenv("MULTICA_TASK_ID", "task-test")+ t.Setenv("MULTICA_TASK_CONFIG_ROOT", filepath.Join(t.TempDir(), "task-multica"))+ t.Setenv(daemon.TaskWorkspacesRootEnv, injectedRoot)+ return injectedRoot+}++// A task may see its own daemon's disk usage, but the report must come from the+// daemon-injected root and must never be enriched with the Owner's credential:+// fillDiskUsageParentStatuses authenticates with the Owner profile token, which+// is precisely the implicit identity reuse the task boundary exists to stop.+func TestRunDaemonDiskUsageTaskContextScansInjectedRootWithoutOwnerToken(t *testing.T) {+ home := t.TempDir()+ rec := &gcCheckRecorder{}+ srv := newGCCheckServer(t, rec)+ injectedRoot := setupTaskDiskUsageContext(t, home, srv.URL)++ out, err := captureStdout(t, func() error { return runDaemonDiskUsage(newDiskUsageTestCmd(t), nil) })+ if err != nil {+ t.Fatalf("runDaemonDiskUsage: %v", err)+ }+ if rec.callCount() != 0 {+ t.Errorf("gc-check calls = %d, want 0: a task must not spend the Owner token", rec.callCount())+ }+ if !strings.Contains(out, "7a5c0000") {+ t.Errorf("report missing the injected root's task, got:\n%s", out)+ }+ if strings.Contains(out, "0wner000") {+ t.Errorf("report leaked a task from the Owner's workspaces root, got:\n%s", out)+ }+ if !strings.Contains(out, injectedRoot) {+ t.Errorf("report did not name the injected root %q, got:\n%s", injectedRoot, out)+ }+ // The hint enumerates ~/.multica/profiles, so it must stay out of a task.+ if strings.Contains(out, "Other workspace roots") {+ t.Errorf("report disclosed other workspace roots inside a task, got:\n%s", out)+ }+}++// Every flag rejected here would move the scan outside the daemon root that+// hosts this task: --all-profiles enumerates the Owner's profiles, and the two+// overrides aim the scan at a tree this daemon does not manage.+func TestRunDaemonDiskUsageTaskContextRejectsWideningFlags(t *testing.T) {+ for name, flag := range map[string]struct{ key, value string }{+ "all-profiles": {"all-profiles", "true"},+ "workspaces-root": {"workspaces-root", "/somewhere/else"},+ "profile": {"profile", "staging"},+ } {+ t.Run(name, func(t *testing.T) {+ home := t.TempDir()+ rec := &gcCheckRecorder{}+ srv := newGCCheckServer(t, rec)+ setupTaskDiskUsageContext(t, home, srv.URL)++ cmd := newDiskUsageTestCmd(t)+ if err := cmd.Flags().Set(flag.key, flag.value); err != nil {+ t.Fatalf("set --%s: %v", flag.key, err)+ }+ err := runDaemonDiskUsage(cmd, nil)+ if err == nil || !strings.Contains(err.Error(), "not available inside a daemon-managed task") {+ t.Fatalf("--%s error = %v, want a task-scope rejection", flag.key, err)+ }+ })+ }+}++// Without the injected root the command has no way to know which tree belongs+// to this task: ResolveWorkspacesRoot would fall back to $HOME and report the+// default root, which for a named-profile daemon is somebody else's tree.+func TestResolveDiskUsageRootTaskContext(t *testing.T) {+ t.Run("uses the injected root", func(t *testing.T) {+ injected := filepath.Join(t.TempDir(), "daemon-workspaces")+ t.Setenv(daemon.TaskWorkspacesRootEnv, injected+string(filepath.Separator))++ got, err := resolveDiskUsageRoot(true, "", "")+ if err != nil {+ t.Fatalf("resolveDiskUsageRoot: %v", err)+ }+ if got != injected {+ t.Fatalf("root = %q, want the cleaned injected root %q", got, injected)+ }+ })++ for name, value := range map[string]string{"missing": "", "relative": "relative/workspaces"} {+ t.Run("fails closed on a "+name+" root", func(t *testing.T) {+ t.Setenv(daemon.TaskWorkspacesRootEnv, value)+ if _, err := resolveDiskUsageRoot(true, "", ""); err == nil {+ t.Fatalf("%s=%q resolved a root, want fail closed", daemon.TaskWorkspacesRootEnv, value)+ }+ })+ }++ t.Run("outside a task keeps profile resolution", func(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)+ t.Setenv("MULTICA_WORKSPACES_ROOT", "")+ t.Setenv(daemon.TaskWorkspacesRootEnv, filepath.Join(t.TempDir(), "ignored"))++ got, err := resolveDiskUsageRoot(false, "staging", "")+ if err != nil {+ t.Fatalf("resolveDiskUsageRoot: %v", err)+ }+ if want := filepath.Join(home, "multica_workspaces_staging"); got != want {+ t.Fatalf("root = %q, want %q", got, want)+ }+ })+}diff --git a/server/cmd/multica/cmd_daemon_test.go b/server/cmd/multica/cmd_daemon_test.goindex a46c7e12e7..68e602e65f 100644--- a/server/cmd/multica/cmd_daemon_test.go+++ b/server/cmd/multica/cmd_daemon_test.go@@ -9,6 +9,7 @@ import ("os""os/exec""path/filepath"+ "strconv""strings""testing""text/template"@@ -59,9 +60,7 @@ func TestDaemonLocalCommandsFailClosedInTaskContext(t *testing.T) {"start": func() error { return runDaemonStart(daemonStartCmd, nil) },"restart": func() error { return runDaemonRestart(daemonRestartCmd, nil) },"stop": func() error { return runDaemonStop(daemonStopCmd, nil) },- "status": func() error { return runDaemonStatus(daemonStatusCmd, nil) },"logs": func() error { return runDaemonLogs(daemonLogsCmd, nil) },- "disk-usage": func() error { return runDaemonDiskUsage(daemonDiskUsageCmd, nil) },}for name, run := range cases {err := run()@@ -626,7 +625,7 @@ func TestPrintDiskUsageOtherRootsHintSuggestsProfilesWithTasks(t *testing.T) {var out bytes.BufferprintDiskUsageOtherRootsHint(&out, daemon.DiskUsageReport{WorkspacesRoot: filepath.Join(home, "multica_workspaces"),- }, "", "")+ }, "", "", false)got := out.String()if !strings.Contains(got, "Other workspace roots contain task directories:") {@@ -668,7 +667,7 @@ func TestPrintDiskUsageOtherRootsHintFiresWhenCurrentRootNonEmpty(t *testing.T)printDiskUsageOtherRootsHint(&out, daemon.DiskUsageReport{WorkspacesRoot: filepath.Join(home, "multica_workspaces"),TotalTaskCount: 7, // current root is NOT empty- }, "", "")+ }, "", "", false)got := out.String()if !strings.Contains(got, "multica --profile desktop-host daemon disk-usage") {@@ -686,7 +685,7 @@ func TestPrintDiskUsageOtherRootsHintSuggestsDefaultFromNamedProfile(t *testing.var out bytes.BufferprintDiskUsageOtherRootsHint(&out, daemon.DiskUsageReport{WorkspacesRoot: filepath.Join(home, "multica_workspaces_named"),- }, "named", "")+ }, "named", "", false)got := out.String()if !strings.Contains(got, "multica daemon disk-usage #") {@@ -705,7 +704,7 @@ func TestPrintDiskUsageOtherRootsHintSkipsExplicitRootOverride(t *testing.T) {var out bytes.BufferprintDiskUsageOtherRootsHint(&out, daemon.DiskUsageReport{WorkspacesRoot: filepath.Join(home, "custom-root"),- }, "", filepath.Join(home, "custom-root"))+ }, "", filepath.Join(home, "custom-root"), false)if got := out.String(); got != "" {t.Fatalf("hint output = %q, want no hint for explicit root override", got)@@ -847,3 +846,90 @@ func TestVersionTemplateMatchesDaemonProbe(t *testing.T) {rendered.String(), got, version)}}++// `daemon status` is allowed inside a task, but only against the daemon that+// hosts it. healthPortForProfile hashes whatever --profile it is handed, so a+// task must take the port the daemon injected instead of re-deriving one:+// re-deriving reports the default daemon when the task is actually hosted by a+// named-profile daemon, and lets a task probe an unrelated one on purpose.+func TestDaemonStatusHealthPortInTaskContext(t *testing.T) {+ const injectedPort = 19601++ t.Run("outside a task derives the port from the profile", func(t *testing.T) {+ t.Chdir(t.TempDir())+ clearDaemonTaskEnv(t)++ got, err := daemonStatusHealthPort(testCmd())+ if err != nil {+ t.Fatalf("daemonStatusHealthPort: %v", err)+ }+ if want := healthPortForProfile(""); got != want {+ t.Fatalf("health port = %d, want %d", got, want)+ }+ })++ t.Run("inside a task uses the injected port", func(t *testing.T) {+ t.Chdir(t.TempDir())+ clearDaemonTaskEnv(t)+ t.Setenv("MULTICA_TASK_ID", "task-test")+ t.Setenv("MULTICA_DAEMON_PORT", strconv.Itoa(injectedPort))++ got, err := daemonStatusHealthPort(testCmd())+ if err != nil {+ t.Fatalf("daemonStatusHealthPort: %v", err)+ }+ if got != injectedPort {+ t.Fatalf("health port = %d, want the injected %d", got, injectedPort)+ }+ if got == healthPortForProfile("") {+ t.Fatal("injected port collided with the profile-derived port; the test proves nothing")+ }+ })++ t.Run("inside a task rejects --profile", func(t *testing.T) {+ t.Chdir(t.TempDir())+ clearDaemonTaskEnv(t)+ t.Setenv("MULTICA_TASK_ID", "task-test")+ t.Setenv("MULTICA_DAEMON_PORT", strconv.Itoa(injectedPort))++ cmd := &cobra.Command{}+ cmd.Flags().String("profile", "", "")+ if err := cmd.Flags().Set("profile", "staging"); err != nil {+ t.Fatalf("set profile flag: %v", err)+ }+ _, err := daemonStatusHealthPort(cmd)+ if err == nil || !strings.Contains(err.Error(), "not available inside a daemon-managed task") {+ t.Fatalf("error = %v, want a --profile rejection", err)+ }+ })++ t.Run("inside a task fails closed on a missing or invalid port", func(t *testing.T) {+ for name, value := range map[string]string{"missing": "", "invalid": "not-a-port", "zero": "0"} {+ t.Run(name, func(t *testing.T) {+ t.Chdir(t.TempDir())+ clearDaemonTaskEnv(t)+ t.Setenv("MULTICA_TASK_ID", "task-test")+ t.Setenv("MULTICA_DAEMON_PORT", value)++ if _, err := daemonStatusHealthPort(testCmd()); err == nil {+ t.Fatalf("MULTICA_DAEMON_PORT=%q resolved a port, want fail closed", value)+ }+ })+ }+ })+}++// clearDaemonTaskEnv drops every daemon-injected marker so a subtest starts+// from a known context and can opt back in to exactly the ones it needs.+func clearDaemonTaskEnv(t *testing.T) {+ t.Helper()+ for _, key := range []string{+ "MULTICA_AGENT_ID",+ "MULTICA_TASK_ID",+ "MULTICA_DAEMON_PORT",+ "MULTICA_TASK_CONFIG_ROOT",+ daemon.TaskWorkspacesRootEnv,+ } {+ t.Setenv(key, "")+ }+}diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.goindex a6be8c3945..cea2df9030 100644--- a/server/internal/daemon/config.go+++ b/server/internal/daemon/config.go@@ -541,12 +541,20 @@ func NormalizeServerBaseURL(raw string) (string, error) {return strings.TrimRight(u.String(), "/"), nil}+// TaskWorkspacesRootEnv carries the workspaces root of the daemon that owns a+// managed task into that task's environment. Task-mode `daemon disk-usage`+// reads this and nothing else: ResolveWorkspacesRoot derives its default from+// $HOME and the --profile name, so a task hosted by a named-profile daemon+// would otherwise scan the default root and silently report the wrong tree.+const TaskWorkspacesRootEnv = "MULTICA_TASK_WORKSPACES_ROOT"+// ResolveWorkspacesRoot returns the absolute path that the daemon and CLI// should treat as the workspaces root. Resolution order: explicit override >// MULTICA_WORKSPACES_ROOT env > default ($HOME/multica_workspaces, or// $HOME/multica_workspaces_<profile> for a named profile). Read-only callers// (e.g. `multica daemon disk-usage`) use this directly so they pick the same-// directory the running daemon would have picked.+// directory the running daemon would have picked. Inside a managed task use+// TaskWorkspacesRootEnv instead — see resolveDiskUsageRoot.func ResolveWorkspacesRoot(profile, override string) (string, error) {root := strings.TrimSpace(os.Getenv("MULTICA_WORKSPACES_ROOT"))if override != "" {diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex df0985cb30..39e1848872 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -133,10 +133,11 @@ func taskScopedAuthToken(task Task) (string, error) {return token, nil}-func taskMulticaEnvironment(task Task, agentName, token, configRoot, serverURL string, healthPort, slot int, tempDir string) map[string]string {+func taskMulticaEnvironment(task Task, agentName, token, configRoot, workspacesRoot, serverURL string, healthPort, slot int, tempDir string) map[string]string {return map[string]string{"MULTICA_TOKEN": token,cli.TaskConfigRootEnv: configRoot,+ TaskWorkspacesRootEnv: workspacesRoot,"MULTICA_SERVER_URL": serverURL,"MULTICA_DAEMON_PORT": strconv.Itoa(healthPort),"MULTICA_WORKSPACE_ID": task.WorkspaceID,@@ -6007,7 +6008,7 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, slot itaskLog.Error("task auth token invalid; refusing to start agent", "error", err)return TaskResult{}, err}- agentEnv := taskMulticaEnvironment(task, agentName, agentToken, env.MulticaConfigRoot, d.cfg.ServerBaseURL, d.cfg.HealthPort, slot, taskTempDir)+ agentEnv := taskMulticaEnvironment(task, agentName, agentToken, env.MulticaConfigRoot, d.cfg.WorkspacesRoot, d.cfg.ServerBaseURL, d.cfg.HealthPort, slot, taskTempDir)if checkoutMode := repoCheckoutModeFor(provider, runtime.GOOS); checkoutMode != "" {agentEnv[repoCheckoutModeEnv] = checkoutMode}diff --git a/server/internal/daemon/daemon_test.go b/server/internal/daemon/daemon_test.goindex 7fc42c9af8..e569f700e2 100644--- a/server/internal/daemon/daemon_test.go+++ b/server/internal/daemon/daemon_test.go@@ -515,41 +515,47 @@ func TestTaskMulticaEnvironmentIncludesPrivateConfigRoot(t *testing.T) {t.Parallel()const (- fakeToken = "mat_task_environment_sentinel"- taskRoot = "/task/private-multica-config"+ fakeToken = "mat_task_environment_sentinel"+ taskRoot = "/task/private-multica-config"+ workspacesRoot = "/daemon/multica_workspaces_staging")task := Task{ID: "task-test",AgentID: "agent-test",WorkspaceID: "workspace-test",}- env := taskMulticaEnvironment(task, "agent-name", fakeToken, taskRoot, "https://task.example", 19514, 3, "/task/tmp")+ env := taskMulticaEnvironment(task, "agent-name", fakeToken, taskRoot, workspacesRoot, "https://task.example", 19514, 3, "/task/tmp")want := map[string]string{- "MULTICA_TOKEN": fakeToken,- "MULTICA_TASK_CONFIG_ROOT": taskRoot,- "MULTICA_SERVER_URL": "https://task.example",- "MULTICA_DAEMON_PORT": "19514",- "MULTICA_WORKSPACE_ID": "workspace-test",- "MULTICA_AGENT_NAME": "agent-name",- "MULTICA_AGENT_ID": "agent-test",- "MULTICA_TASK_ID": "task-test",- "MULTICA_TASK_SLOT": "3",- "TMPDIR": "/task/tmp",- "TMP": "/task/tmp",- "TEMP": "/task/tmp",+ "MULTICA_TOKEN": fakeToken,+ "MULTICA_TASK_CONFIG_ROOT": taskRoot,+ "MULTICA_TASK_WORKSPACES_ROOT": workspacesRoot,+ "MULTICA_SERVER_URL": "https://task.example",+ "MULTICA_DAEMON_PORT": "19514",+ "MULTICA_WORKSPACE_ID": "workspace-test",+ "MULTICA_AGENT_NAME": "agent-name",+ "MULTICA_AGENT_ID": "agent-test",+ "MULTICA_TASK_ID": "task-test",+ "MULTICA_TASK_SLOT": "3",+ "TMPDIR": "/task/tmp",+ "TMP": "/task/tmp",+ "TEMP": "/task/tmp",}if !maps.Equal(env, want) {t.Fatalf("taskMulticaEnvironment() = %#v, want %#v", env, want)}layerCustomEnvAndHermesHome(env, map[string]string{- "MULTICA_TASK_CONFIG_ROOT": "/owner/config",- "MULTICA_TOKEN": "mul_owner_sentinel",+ "MULTICA_TASK_CONFIG_ROOT": "/owner/config",+ "MULTICA_TASK_WORKSPACES_ROOT": "/owner/multica_workspaces",+ "MULTICA_TOKEN": "mul_owner_sentinel",}, "", nil)if env["MULTICA_TASK_CONFIG_ROOT"] != taskRoot {t.Fatalf("custom env replaced task config root: %q", env["MULTICA_TASK_CONFIG_ROOT"])}+ if env[TaskWorkspacesRootEnv] != workspacesRoot {+ t.Fatalf("custom env replaced task workspaces root: %q", env[TaskWorkspacesRootEnv])+ }if env["MULTICA_TOKEN"] != fakeToken {t.Fatal("custom env replaced task-scoped token")}diff --git a/server/internal/service/builtin_skills/multica-runtimes-and-repos/SKILL.md b/server/internal/service/builtin_skills/multica-runtimes-and-repos/SKILL.mdindex b0c6984f53..975f472728 100644--- a/server/internal/service/builtin_skills/multica-runtimes-and-repos/SKILL.md+++ b/server/internal/service/builtin_skills/multica-runtimes-and-repos/SKILL.md@@ -56,7 +56,8 @@ The daemon injects a task-scoped `mat_` credential for Multica API commands and- API commands such as `issue list`, `issue get`, and `issue runs` use the injected task identity and never fall back to the daemon Owner's saved Multica profile.- `config show` and `config set` operate only on task-local Multica state. A missing task config root fails closed.- `auth status` may verify the task identity but omits all token material from its output.-- Human/local profile and daemon commands — including `login`, `logout`, `setup`, `workspace switch`, local runtime profile path mutation, and daemon lifecycle/diagnostic commands — are unavailable.+- `daemon status` and `daemon disk-usage` report on the runtime hosting this task: `status` probes the daemon-injected health port, and `disk-usage` scans the daemon-injected workspaces root. Both refuse `--profile`, `disk-usage` also refuses `--all-profiles` and `--workspaces-root`, and its STATUS column stays blank because filling it would spend the Owner's credential.+- Human/local profile and daemon commands — including `login`, `logout`, `setup`, `workspace switch`, local runtime profile path mutation, `daemon start` / `stop` / `restart`, `daemon logs`, and `daemon probe-runtimes` — are unavailable. `daemon stop` in particular would terminate the daemon running this task and every sibling task on it.The daemon still preserves the real `HOME` and XDG variables for provider tools such as `gh`, `aws`, `kubectl`, and npm. This is CLI resolution hardening, not hard filesystem confidentiality: a process under the same OS user can still open an explicitly known Owner path. Dedicated Unix users, containers, VMs, or an equivalent OS boundary are required for that stronger isolation.diff --git a/server/internal/service/builtin_skills/multica-runtimes-and-repos/references/runtimes-and-repos-source-map.md b/server/internal/service/builtin_skills/multica-runtimes-and-repos/references/runtimes-and-repos-source-map.mdindex 83518dee95..efdbe0af4b 100644--- a/server/internal/service/builtin_skills/multica-runtimes-and-repos/references/runtimes-and-repos-source-map.md+++ b/server/internal/service/builtin_skills/multica-runtimes-and-repos/references/runtimes-and-repos-source-map.md@@ -14,4 +14,5 @@- `server/internal/daemon/execenv/execenv.go` creates and restores the private per-task `multica-config` directory with mode `0700`; it does not copy the daemon Owner's Multica profile into the directory.- `server/internal/cli/config.go` resolves Multica CLI profiles below `MULTICA_TASK_CONFIG_ROOT` when present while leaving ordinary `HOME`-based resolution unchanged outside tasks.- `server/cmd/multica/cmd_agent.go`, `cmd_config.go`, `cmd_auth.go`, `cmd_login.go`, `cmd_setup.go`, `cmd_workspace.go`, `cmd_runtime_profile.go`, and `cmd_daemon.go` enforce the task boundary: API calls require task authentication, task-local config commands fail closed without their root, auth status hides credential material, and human/local profile or daemon commands reject managed task context.+- `cmd_daemon.go` scopes the two read-only diagnostics instead of rejecting them: `daemonStatusHealthPort` takes the injected `MULTICA_DAEMON_PORT` (never the `--profile` hash, which would report an unrelated daemon), `resolveDiskUsageRoot` takes `daemon.TaskWorkspacesRootEnv` (never the `$HOME`-derived default), `checkTaskDiskUsageScope` rejects the flags that widen the scan past this daemon, and the STATUS column plus the other-roots hint are skipped because both reach for Owner profile state.- `server/internal/daemon/execenv/runtime_config.go` injects task/project/repo context into agent workdirs.