You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "Colafornia (via GitHub)" <gi...@apache.org> on 2026/10/04 17:30:04 UTC
[PR] fix(desktop): use dedicated directories for projectless tasks [maka]
Colafornia opened a new pull request, #5966:
URL: https://github.com/apache/maka/pull/5966
<details open>
<summary>English</summary>
## Summary
A new top-level local task with no explicit directory inherited the startup cwd or the app install path — often `/` — so task output could land in the filesystem root or inside application state. Projectless tasks now get a dedicated, persistent `~/Maka/tasks/task-<id>` directory allocated by a managed-task-directory authority that validates root ownership and refuses symlink redirection into application state, credentials, or install files.
Allocation is wired into every top-level task creation path — `sessions:create`, bot sessions, external session import, WorkHub `create_new`, and offline session-local creation — behind the existing precedence: explicit `cwd`/`projectId`, configured default project/directory, then the selected project; only an implicit projectless path allocates. The `pathSource` field on the current selection reserves the seam for the configured-default-directory setting (#2998). The directory is stable across turns, restarts, and continuation via the persisted session cwd, shows in the titlebar, opens via the existing folder action, and child sessions inherit it.
Existing sessions are not rewritten. `app:sessionProjectInfo` reports the bound directory's class (`managed` / `suspicious` / `other`); a suspicious binding surfaces a repair banner, and every non-managed binding gets a titlebar menu item. Both call the new `sessions:moveToDedicatedDirectory` IPC, which allocates a fresh directory and rebinds the session through the same revision-check relocate as `moveToProject`, releasing the directory when the commit is refused. Remote Runtime Host semantics and CLI/TUI behavior are unchanged.
Fixes #5939
## Verification
- `apps/desktop`: `npm run build:main`, `npm run typecheck`, `npm run check:architecture`, `npm run test:dist` — 3264 tests pass, 0 failures
- `npx biome check` on all 26 changed files — clean
- New unit coverage: managed-directory authority (allocation, uniqueness, owner/symlink/reserved-root guards, classification, empty-only release); workspace resolution precedence (explicit directory, configured default, managed allocation); dedicated-directory IPC (single CAS commit, project-bound refusal, release-on-refusal, missing-authority refusal)
- Not run: `npm run e2e` — the allocation policy is covered at the main-process integration layer, and the e2e fixture redirects the managed root under the isolated fixture workspace
- Not run: packaged GUI launch — the code path is launch-mode independent, but a packaged build was not exercised locally
</details>
<details>
<summary>中文</summary>
## 摘要
此前新建一个没有显式目录的顶层本地任务,会继承启动时的工作目录或应用安装路径——常常是 `/`——导致任务输出落进文件系统根目录或应用状态目录里。现在无项目任务会由托管任务目录权威在 `~/Maka/tasks/task-<id>` 下分配一个专属且持久的目录;该权威校验根目录属主,并拒绝符号链接重定向到应用状态、凭据或安装文件。
分配逻辑接入了所有顶层任务创建路径——`sessions:create`、bot 会话、外部会话导入、WorkHub `create_new` 和离线 session-local 创建——且排在既有优先级之后:显式 `cwd`/`projectId`、配置的默认项目/目录、当前选中项目,最后才对隐式无项目路径做分配。当前选择上的 `pathSource` 字段为「配置的默认目录」设置(#2998)预留了接缝。目录经由会话持久化的 cwd 在跨轮次、重启和续聊中保持稳定,显示在标题栏,可通过现有的「打开文件夹」操作打开,子会话会继承它。
既有会话不会被改写。`app:sessionProjectInfo` 上报绑定目录的分类(`managed` / `suspicious` / `other`);可疑绑定会出现修复提示条,所有非托管绑定都会在标题栏菜单中提供迁移项。两者都调用新的 `sessions:moveToDedicatedDirectory` IPC:分配新目录后,通过与 `moveToProject` 相同的带 revision 校验的 relocate 完成重绑,提交被拒绝时回收新目录。远程 Runtime Host 语义与 CLI/TUI 行为保持不变。
Fixes #5939
## 验证
- `apps/desktop`:`npm run build:main`、`npm run typecheck`、`npm run check:architecture`、`npm run test:dist`——3264 个测试全部通过
- 对全部 26 个变更文件执行 `npx biome check`——无问题
- 新增单元覆盖:托管目录权威(分配、唯一性、属主/符号链接/保留根防护、分类、仅空目录回收);workspace 解析优先级(显式目录、配置的默认值、托管分配);专属目录 IPC(单次 CAS 提交、项目绑定拒绝、拒绝时回收、缺少权威时拒绝)
- 未运行:`npm run e2e`——分配策略已在 main 进程集成层覆盖,且 e2e fixture 会把托管根重定向到隔离的 fixture workspace 下
- 未运行:打包版 GUI 启动——代码路径与启动方式无关,但本地未实际验证打包构建
</details>
## AI use
Select exactly one:
- [ ] No generative tool made a substantive contribution
- [x] Generative tooling made a substantive contribution
Tool(s) and scope: Devin (Cognition) authored the implementation and tests end to end; the commit carries the Generated-with trailer.
## Checklist
- [x] Tests cover the change and fail without it
- [x] Lint, format, typecheck and the affected suites pass locally
Does this PR entail a change in behavior?
- [x] Yes — described under Summary above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(desktop): use dedicated directories for projectless tasks [maka]
Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on PR #5966:
URL: https://github.com/apache/maka/pull/5966#issuecomment-6135547006
Thanks for the contribution! Merging now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(desktop): use dedicated directories for projectless tasks [maka]
Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #5966:
URL: https://github.com/apache/maka/pull/5966#discussion_r4193545375
##########
apps/desktop/src/main/runtime-host-session-catalog-ipc-main.ts:
##########
@@ -328,6 +338,55 @@ async function moveSessionToProject(
return { ok: true, session: toDesktopHostSessionSummary(session) };
}
+/**
+ * The explicit correction for a Session bound to an unintended implicit
+ * directory: allocate a dedicated task directory, then rebind through the
+ * same `session.workspace.relocate` authority `moveToProject` uses — one
+ * revision read, one compare-and-set commit, and no project re-pointing.
+ *
+ * The directory is created only once the Session proves eligible, and before
+ * the relocate because the Host requires the target to already exist. Keep
+ * the directory on failure: the Host may have committed the binding before
+ * its response failed.
+ */
+async function moveSessionToDedicatedDirectory(
+ deps: RuntimeHostSessionCatalogIpcDeps,
+ sessionId: string,
+): Promise<DesktopSessionUpdateResult<DesktopHostSessionSummary>> {
+ const authority = deps.dedicatedTaskDirectory;
+ if (!authority) {
+ throw new Error('Dedicated task directories are unavailable on this Runtime Host');
+ }
+ let session: SessionCatalogProjection;
+ try {
+ const current = await deps.client.getSession(sessionId);
+ if (!current) {
+ throw new DesktopRuntimeHostClientError(
+ 'session_not_found',
+ `No such Session: ${sessionId}`,
+ );
+ }
+ // A Project-bound Session relocates through `moveToProject` — this
+ // correction is only for a projectless Host-path binding, so dropping a
+ // Project association here can never be an accident.
+ if (current.workspace.target.kind !== 'host_path') {
+ return { ok: false, code: 'operation_unavailable' };
+ }
+ const directory = await authority.allocate();
Review Comment:
**P3: the move is not idempotent, and directories leak on failures that definitely did not commit.**
1. The only eligibility check is `kind === 'host_path'`, so a task that is already `managed` can be moved again. With a double-click on the banner or menu item, the second call reads the post-commit revision, so CAS does not stop it. It allocates and relocates a second time and orphans the first directory. Suggest returning `{ ok: false, code: 'operation_unavailable' }` when `await authority.classify(current.workspace.hostCwd) === 'managed'`, and/or disabling the action while the request is pending.
2. Keeping the directory is right for `commit_outcome_unknown`. For `operation_conflict`, validation errors, or `not_dispatched`, the Host definitely did not bind it. A non-recursive `rmdir(directory)` is data-safe there because it fails on anything non-empty. Without it, `~/Maka/tasks` accumulates empty `task-*` directories. The same applies to `sessions:create` and WorkHub refusals after `allocate()`. If this is intentional, a comment saying so would help.
##########
apps/desktop/src/main/new-session-project.ts:
##########
@@ -71,7 +81,7 @@ export async function resolveDesktopSessionWorkspace(
return { kind: 'project', projectId: current.projectId };
}
if (options.allowHostPath === false) throw remoteProjectRequired();
- return { kind: 'host_path', path: current.path };
+ return { kind: 'host_path', path: await options.allocateDedicatedDirectory() };
Review Comment:
**P2: this bypasses the seam #2998 uses for its configured default directory.**
#2998 ("add a default working directory") resolves the configured default inside `project-root-controller.ts` (`resolveUnassociatedRoot`) and exposes it through `projectManagement.current().path`. That is the exact value this PR drops from `DesktopSessionWorkspaceSelection.current()`. The same applies to the `projectId: null` branch above and to `currentDesktopWorkspaceTarget` in `runtime-host-boot.ts`. Whichever PR merges second will silently drop the other's behavior. Text conflicts appear only in `runtime-host-boot.ts`, not at the point where the semantics collide.
#5939 requires that "usable configured default directories retain their precedence" and says this should "reuse the same directory-resolution policy". Suggest a single `resolveProjectlessDirectory()` dependency that tries a usable configured default first and calls `allocate()` otherwise, used here and in `currentDesktopWorkspaceTarget`. At minimum, note on #2998 and #5939 which hook #2998 must target once this lands.
##########
apps/desktop/src/preload/bridge-contract.d.ts:
##########
@@ -352,6 +352,17 @@ export type DesktopSessionStopResult =
| { kind: 'interrupted'; retractedMessageIds: string[] }
| undefined;
+/**
+ * How a projectless Session's bound directory relates to the Client's
+ * dedicated task-directory root:
+ * - `managed`: inside the dedicated root — the policy's steady state.
+ * - `suspicious`: `reserved` or `symlink_redirect` — a binding that cannot be
Review Comment:
**P3: stale doc.** `classify()` has no `reserved`/`symlink_redirect` sub-classes and does no symlink-redirect detection. `suspicious` means "filesystem root, or inside a reserved root". This looks left over from the "drop speculative abstractions" commit. Please align it with the doc on `ManagedTaskDirectoryClass`.
##########
apps/desktop/src/main/managed-task-directory.ts:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { lstat, mkdir, mkdtemp, realpath } from 'node:fs/promises';
+import { basename, dirname, join, resolve } from 'node:path';
+import { isPathInside } from '@maka/runtime/path-containment';
+
+/**
+ * How a Session cwd relates to the managed task-directory root:
+ * - `managed`: inside the root — a directory this authority allocated.
+ * - `suspicious`: a binding that cannot plausibly be deliberate — the
+ * filesystem root itself, or inside a reserved location (application state,
+ * install files). Such sessions are offered a one-click correction.
+ * - `other`: any other user-owned directory, including explicit picks.
+ */
+export type ManagedTaskDirectoryClass = 'managed' | 'suspicious' | 'other';
+
+export interface ManagedTaskDirectoryAuthority {
+ /**
+ * Creates a fresh, empty task directory under the managed root and returns
+ * its canonical path. Each call is a distinct directory — separate tasks
+ * never share an output root. Throws when the root cannot be provisioned or
+ * validated; the caller must not fall back to an implicit directory.
+ */
+ allocate(): Promise<string>;
+ classify(path: string): Promise<ManagedTaskDirectoryClass>;
+}
+
+export interface ManagedTaskDirectoryDeps {
+ /** The managed root, e.g. `~/Maka/tasks`. */
+ readonly root: string;
+ /**
+ * Locations the managed root must not resolve into: application state,
+ * credentials, and installation files.
+ */
+ readonly reservedRoots?: readonly string[];
+ /** Owner check; defaults to `process.getuid()` on POSIX. */
+ readonly ownerUid?: () => number | undefined;
+}
+
+export function createManagedTaskDirectoryAuthority(
+ deps: ManagedTaskDirectoryDeps,
+): ManagedTaskDirectoryAuthority {
+ const ownerUid =
+ deps.ownerUid ?? (() => (typeof process.getuid === 'function' ? process.getuid() : undefined));
+
+ async function prepareRoot(): Promise<string> {
+ const root = resolve(deps.root);
+ await mkdir(root, { recursive: true });
+ const rootStat = await lstat(root);
+ if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
Review Comment:
**P3: the symlink policy is inconsistent, and failure is a hard, unlocalized error.**
A symlinked `~/Maka` is accepted: it is canonicalized and checked against `reservedRoots`. A symlinked `~/Maka/tasks` is refused outright, even when it points at an ordinary user-owned directory on another disk. In that case, or when `~/Maka` is a regular file, every new projectless task fails with the raw English `Refusing to use a managed task directory: ...` (line 113). No shell copy covers it.
The threat model in #5939 is redirection into app state or install files, which the canonical-root reserved check already covers. Suggest validating the canonical target (directory, owner, not inside reserved roots) instead of rejecting every final-component symlink. Also map allocation failure to localized copy that tells the user to pick a folder.
##########
apps/desktop/src/main/app-ipc-main.ts:
##########
@@ -182,6 +189,7 @@ export function registerAppIpc(
return {
projectPath,
projectGit: await resolveProjectGitInfo(projectPath),
+ taskDirectory: await deps.getSessionTaskDirectoryBinding?.(sessionId),
Review Comment:
**P3:** this adds a second `client.getSession()` round trip to `app:sessionProjectInfo`. If it throws (for example during a Host reconnect), the whole read rejects and the renderer loses the git and branch info it showed before. The field is already optional, so suggest `await deps.getSessionTaskDirectoryBinding?.(sessionId).catch(() => undefined)`.
##########
apps/desktop/src/main/runtime-host-boot.ts:
##########
@@ -442,6 +444,25 @@ mainWindowDelegates.onMainWindowClose = () => {
native.computerUsePip.destroyAll();
};
const attachmentApprovals = createAttachmentApprovalRegistry();
+/**
+ * Dedicated task directories live in the user-owned `~/Maka/tasks` root —
+ * deliberately separate from `userData` (settings, credentials, session
+ * state) and from the install location. Isolated e2e profiles redirect both
+ * `userData` and the fake home into one sandbox, so the root moves under
+ * the isolated workspace instead — `~` there resolves inside `userData`
+ * itself and would trip the reserved-location guard; inside the sandbox the
+ * Client-data reserved roots no longer apply.
+ */
+const managedTaskDirectories = createManagedTaskDirectoryAuthority({
+ root:
+ e2eFixture || hasIsolatedE2eProfile
+ ? join(workspaceRoot, 'task-directories')
+ : join(app.getPath('home'), app.getName(), 'tasks'),
Review Comment:
**P3 (doc/UX):** `main.ts:64` sets `app.setName(app.isPackaged ? 'Maka' : 'Maka Dev')`. Source runs therefore allocate under `~/Maka Dev/tasks`, which contains a space, not the `~/Maka/tasks` the PR body describes.
Also, `app.getAppPath()` is `apps/desktop` in dev and sits in `reservedRoots` below. A developer's explicit projectless cwd inside `apps/desktop` will therefore get the "suspicious" banner. Both are acceptable, but worth a comment or a line in the PR body.
##########
apps/desktop/src/renderer/use-project-context.ts:
##########
@@ -212,12 +251,84 @@ export function useAppShellProjectContext(options: {
const refreshProjects = async (): Promise<ProjectRecord[]> =>
(await runOnDefaultRuntimeHost((host) => refreshDefaultProjectState(host))).value;
+ const {
+ sharedSessionActive,
+ activeSession,
+ sharedSessionDialog,
+ moveToDedicatedDirectory,
+ openProjectFolder,
+ copy,
+ toastApi,
+ } = titlebar;
+ // The titlebar names the directory the ACTIVE session runs in, so it reads
+ // the same projected project state the picker does — `projectInfo` already
+ // resolves to the session's own cwd once a session owns it. Mirrors
+ // @maka/ui's deriveTitlebarProjectName: importing it would add a value
+ // dependency edge the renderer architecture budget forbids here.
+ const titlebarProjectName = sharedSessionActive
+ ? undefined
+ : currentProject?.name ||
+ projectInfo?.projectPath.replace(/[/\\]+$/, '').split(/[/\\]/).pop() ||
Review Comment:
**P3 (nit):** this duplicates `@maka/ui`'s `deriveTitlebarProjectName` only to stay under the renderer-architecture budget, so the two can drift. Consider deriving the name in `app-shell.tsx` (which already imported it) and passing it in through `titlebar`, or adjusting the budget.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(desktop): use dedicated directories for projectless tasks [maka]
Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han merged PR #5966:
URL: https://github.com/apache/maka/pull/5966
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org