CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
workspace-memory.d.ts78 linesDownload Raw Back to serve
1/**2 * @license3 * Copyright 2025 Qwen Team4 * SPDX-License-Identifier: Apache-2.05 */6import type { Application, Request, RequestHandler, Response } from 'express';7import type { AcpSessionBridge } from './acp-session-bridge.js';8import { type ServeWorkspaceMemoryStatus } from '@qwen-code/acp-bridge/status';9/**10 * Issue #4175 PR 16: workspace memory CRUD routes.11 *12 * `GET /workspace/memory` returns the daemon's snapshot of explicit13 * `QWEN.md` / `AGENTS.md` files reachable from the bound workspace14 * plus the user's `~/.qwen/` global. Read-only; returns15 * `initialized: false` and an empty `files` list when no files exist16 * (no synthetic 500s, mirroring PR 12's read-only routes).17 *18 * `POST /workspace/memory` accepts `{ scope, content, mode }` and19 * forwards to `writeWorkspaceContextFile`. Strict mutation gate; on20 * success, fans out a `memory_changed` event onto every active21 * session's bus so adapters can refresh cached snapshots.22 *23 * Both routes are filesystem-only — neither spawns the ACP child.24 *25 * **Absolute filePath disclosure note**: success / 413 / GET-list26 * responses include absolute on-disk paths (`/work/<x>/QWEN.md`,27 * `/Users/<x>/.qwen/QWEN.md`). This is by design for a daemon28 * contract: clients pre-flight `caps.workspaceCwd` to learn the29 * bound workspace root and can compute relative paths if they30 * prefer; the global scope (`~/.qwen/QWEN.md`) is NOT under the31 * workspace root, so rewriting to a workspace-relative form would32 * lose information. The bearer-token gate + the daemon's loopback-33 * default binding already restrict who can see these paths. If a34 * future deployment shape needs path redaction (e.g. multi-tenant35 * over a shared host), it should land as a `--redact-paths`36 * deployment toggle rather than a per-route default flip — tracked37 * with PR 24's `--redact-errors` policy work, not in PR 16.38 */39export interface WorkspaceMemoryRouteDeps {40    bridge: AcpSessionBridge;41    boundWorkspace: string;42    collectStatus?: typeof collectWorkspaceMemoryStatus;43    /**44     * `mutate({ strict: true })`-style middleware factory from PR 15.45     * Passed in so `server.ts` stays the single composition root for46     * the mutation-gate decisions.47     */48    mutate: (opts?: {49        strict?: boolean;50    }) => RequestHandler;51    /**52     * Pre-validated client id parser. Returns `undefined` for absent53     * headers, the parsed id for valid ones, and `null` after sending54     * its own 400 response (so the route handler must short-circuit).55     * Re-uses `parseClientIdHeader` from `server.ts`.56     */57    parseClientId: (req: Request, res: Response) => string | undefined | null;58    /** `safeBody` from `server.ts` — strips prototype-pollution keys. */59    safeBody: (req: Request) => Record<string, unknown>;60}61/** Mount the two memory routes on the supplied Express app. */62export declare function mountWorkspaceMemoryRoutes(app: Application, deps: WorkspaceMemoryRouteDeps): void;63/**64 * Filesystem-only discovery of explicit `QWEN.md` / `AGENTS.md`65 * files reachable from the daemon's bound workspace plus the user's66 * `~/.qwen/` global directory.67 *68 * Discovers the bound-workspace-root file(s) (no parent-directory69 * walk in this version) plus the global dir. `walkWorkspaceForMemory`70 * keeps a guarded upward-walk loop body for a future hierarchical71 * mode but breaks after iteration 1 today; callers should treat the72 * surface as "workspace root + global". Auto-memory (the `MEMORY.md`73 * index + per-type files) is intentionally NOT included; that's PR74 * 16.5's responsibility per scope decision in issue #4175. Path-75 * based rules (`.qwen/rules/`) are also out of scope for v1.76 */77export declare function collectWorkspaceMemoryStatus(boundWorkspace: string): Promise<ServeWorkspaceMemoryStatus>;78 
basant307/AI_Governance_Project · CoolFace