@laoyuehanni/dsh-git-worktree 0.4.4 → 0.4.6-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,56 +1,74 @@
1
1
  /**
2
- * dsh-git-worktree host half. Owns the worktree storage-root settings section
3
- * (the `git-worktree` namespace in the dsh settings document, registered
4
- * through SettingsProvider.installSection with the composition entry as its
5
- * base layer) and — while a webServer service exists — the HTTP routes the browser
6
- * half fetches. A stored root edit takes effect live: the routes read the
7
- * section source per request, so no restart and no route re-registration.
8
- *
9
- * The legacy ~/.dsh/git-worktree/settings.json value migrates into the
10
- * namespace once, when a settings service first attaches and the user layer
11
- * has recorded no choice of its own; the renamed file stays behind as a
12
- * backup. Headless profiles lose only the routes: nothing else in the plugin
13
- * has a browser dependency.
2
+ * dsh-git-worktree host half. Exposes volatile configuration fields projected
3
+ * through the settings service (the `git-worktree` profile entry in the active
4
+ * dsh profile) and — while a webServer service exists — the HTTP routes the
5
+ * browser half fetches. Config edits persist into the profile patch and take
6
+ * effect live via the loader.
14
7
  */
15
- import type { Context } from '@deepseek-ai/cordis';
8
+ import type { Context, Volatile } from '@deepseek-ai/cordis';
16
9
  import z from '@deepseek-ai/schemastery';
17
10
  export declare const name = "dsh-git-worktree";
18
11
  export declare const inject: never[];
19
12
  export interface Config {
20
13
  /** Worktree storage root; defaults to `$DSH_HOME/gitworktree` (`~/.dsh/gitworktree`). */
21
- rootDir?: string;
14
+ rootDir?: Volatile<string | undefined> | string;
22
15
  /** Sidebar git grouping on/off; absent = on (the composition-entry layer's default). */
23
- groupSidebar?: boolean;
16
+ groupSidebar?: Volatile<boolean> | boolean;
17
+ /** Fetch every remote before creating a worktree; absent = off. A failed
18
+ * fetch never blocks the creation (see the /worktree route). */
19
+ fetchBeforeCreate?: Volatile<boolean> | boolean;
20
+ /** Prune stale worktrees lazily after each creation; absent = off. */
21
+ autoPruneWorktrees?: Volatile<boolean> | boolean;
22
+ /** Global cap the lazy prune trims down to (valid git worktrees only);
23
+ * absent = 30. */
24
+ keepWorktrees?: Volatile<number> | number;
25
+ /** Post-create configuration files to copy when .worktreeinclude is absent;
26
+ * absent = none. */
27
+ postCreateCopyFiles?: Volatile<string[]> | string[];
24
28
  }
29
+ /** The shipped prune cap (whole storage root, valid git worktrees only). */
30
+ export declare const KEEP_WORKTREES_DEFAULT = 30;
25
31
  /**
26
32
  * Cordis resolves the composition entry's config through this schema before
27
- * `apply` runs (official plugin-config convention: export the `Config` type
28
- * and a same-named Schemastery schema). It fills the `groupSidebar` default;
29
- * `rootDir` passes through untouched — its absence stays observable so the
30
- * settings section keeps spelling the resolved default. Constraints the
31
- * schema cannot express still fail loudly in validateConfig below (absolute
32
- * path; unknown keys — schemastery keeps extras instead of rejecting them).
33
+ * `apply` runs. In dsh 0.1.7+, fields marked with `.volatile()` are projected
34
+ * by the settings service into live configuration forms.
33
35
  */
34
- export declare const Config: z<Config>;
36
+ export declare const Config: z;
35
37
  /** Reject stale or misspelled config keys before defaults can hide them. */
36
38
  export declare function validateConfig(config: Config): void;
39
+ /**
40
+ * The prune cap must be an integer >= 1: 0 would read as "create then
41
+ * immediately self-delete" (the fresh worktree is excluded, but every other
42
+ * one dies on the next creation), a fraction cannot count directories.
43
+ * Absent = the shipped default, which passes.
44
+ */
45
+ export declare function validateKeepWorktrees(value: number | undefined): void;
37
46
  /** The settings namespace this plugin serves; its browser card spells the same string. */
38
47
  export declare const GIT_WORKTREE_NS = "git-worktree";
39
- /** The settings-facing subset of the config: the worktree storage root and the sidebar grouping switch. */
48
+ /** The settings-facing subset of the config: the worktree storage root, the
49
+ * sidebar grouping switch, and the create/prune behavior switches. */
40
50
  export interface SectionConfig {
41
51
  /** Worktree storage root; absent/blank selects `$DSH_HOME/gitworktree`. */
42
52
  rootDir?: string;
43
53
  /** Whether the sidebar groups same-repository workspaces; absent = on. */
44
54
  groupSidebar?: boolean;
55
+ /** Fetch every remote before creating a worktree; absent = off. */
56
+ fetchBeforeCreate?: boolean;
57
+ /** Prune stale worktrees lazily after each creation; absent = off. */
58
+ autoPruneWorktrees?: boolean;
59
+ /** Global cap the lazy prune trims down to; absent = 30. */
60
+ keepWorktrees?: number;
61
+ /** Post-create configuration files to copy when .worktreeinclude is absent. */
62
+ postCreateCopyFiles?: string[];
45
63
  }
46
- /** Schema resolving the `git-worktree` settings section. */
47
- export declare const sectionSchema: z<SectionConfig>;
48
- /** The section-shaped view of a config: absent keys stay absent (`exactOptionalPropertyTypes`). */
64
+ /** The section-shaped view of a config: absent keys stay absent
65
+ * (`exactOptionalPropertyTypes`) except the switches, which spell their
66
+ * shipped defaults so a user-layer unset can always fall back to them. */
49
67
  export declare function sectionOf(config: Config): SectionConfig;
50
68
  /**
51
- * Plugin apply: install the settings section, migrate any legacy stored root
52
- * into it, then mount routes on any webServer that comes and goes.
69
+ * Plugin apply: mount the settings presentation policy and HTTP routes on any
70
+ * webServer that comes and goes.
53
71
  * @param ctx - host cordis context.
54
- * @param config - the composition entry config (the section's base layer).
72
+ * @param config - the composition entry config.
55
73
  */
56
74
  export declare function apply(ctx: Context, config?: Config): void;
package/lib/index.js CHANGED
@@ -1,136 +1,132 @@
1
1
  /**
2
- * dsh-git-worktree host half. Owns the worktree storage-root settings section
3
- * (the `git-worktree` namespace in the dsh settings document, registered
4
- * through SettingsProvider.installSection with the composition entry as its
5
- * base layer) and — while a webServer service exists — the HTTP routes the browser
6
- * half fetches. A stored root edit takes effect live: the routes read the
7
- * section source per request, so no restart and no route re-registration.
8
- *
9
- * The legacy ~/.dsh/git-worktree/settings.json value migrates into the
10
- * namespace once, when a settings service first attaches and the user layer
11
- * has recorded no choice of its own; the renamed file stays behind as a
12
- * backup. Headless profiles lose only the routes: nothing else in the plugin
13
- * has a browser dependency.
2
+ * dsh-git-worktree host half. Exposes volatile configuration fields projected
3
+ * through the settings service (the `git-worktree` profile entry in the active
4
+ * dsh profile) and — while a webServer service exists — the HTTP routes the
5
+ * browser half fetches. Config edits persist into the profile patch and take
6
+ * effect live via the loader.
14
7
  */
15
8
  import { homedir } from 'node:os';
16
- import { rename } from 'node:fs/promises';
17
9
  import z from '@deepseek-ai/schemastery';
18
10
  import { childProcessExec } from './git.js';
19
- import { handleCreateBranch, handleCreateWorktree, handleEnsureDirectory, handleFetch, handleGroupWorktrees, handleInspectWorktree, handlePathExists, handleRemoveWorktree, handleStatus, handleSwitch, handleUpdate, } from './routes.js';
20
- import { loadLegacySettings, migratedFileOf, planLegacyMigration, settingsFileOf, validateRootDir, } from './settings.js';
21
- import { ROUTE_BRANCH, ROUTE_ENSURE_DIRECTORY, ROUTE_EXISTS, ROUTE_FETCH, ROUTE_GROUP, ROUTE_INSPECT, ROUTE_REMOVE, ROUTE_STATUS, ROUTE_SWITCH, ROUTE_UPDATE, ROUTE_WORKTREE } from './wire.js';
11
+ import { handleCreateBranch, handleCreateWorktree, handleDeleteBranch, handleEnsureDirectory, handleFetch, handleGroupWorktrees, handleInspectWorktree, handlePathExists, handlePurgeDirectory, handleRemoveWorktree, handleRenameBranch, handleStatus, handleSwitch, handleUpdate, handleWorktreesAll, } from './routes.js';
12
+ import { validateRootDir } from './settings.js';
13
+ import { ROUTE_BRANCH, ROUTE_BRANCH_DELETE, ROUTE_BRANCH_RENAME, ROUTE_ENSURE_DIRECTORY, ROUTE_EXISTS, ROUTE_FETCH, ROUTE_GROUP, ROUTE_INSPECT, ROUTE_PURGE, ROUTE_REMOVE, ROUTE_STATUS, ROUTE_SWITCH, ROUTE_UPDATE, ROUTE_WORKTREE, ROUTE_WORKTREES_ALL } from './wire.js';
22
14
  export const name = 'dsh-git-worktree';
23
15
  export const inject = [];
24
16
  /** Largest accepted request body (bytes) — these payloads are a few strings. */
25
17
  const BODY_LIMIT = 64 * 1024;
18
+ function readVolatile(value) {
19
+ if (value === undefined)
20
+ return undefined;
21
+ if (typeof value === 'object' && value !== null && 'get' in value && typeof value.get === 'function') {
22
+ return value.get();
23
+ }
24
+ return value;
25
+ }
26
+ /** The shipped prune cap (whole storage root, valid git worktrees only). */
27
+ export const KEEP_WORKTREES_DEFAULT = 30;
26
28
  /**
27
29
  * Cordis resolves the composition entry's config through this schema before
28
- * `apply` runs (official plugin-config convention: export the `Config` type
29
- * and a same-named Schemastery schema). It fills the `groupSidebar` default;
30
- * `rootDir` passes through untouched — its absence stays observable so the
31
- * settings section keeps spelling the resolved default. Constraints the
32
- * schema cannot express still fail loudly in validateConfig below (absolute
33
- * path; unknown keys — schemastery keeps extras instead of rejecting them).
30
+ * `apply` runs. In dsh 0.1.7+, fields marked with `.volatile()` are projected
31
+ * by the settings service into live configuration forms.
34
32
  */
35
33
  export const Config = z.object({
36
- rootDir: z.string(),
37
- groupSidebar: z.boolean().default(true),
34
+ rootDir: z.string().volatile(),
35
+ groupSidebar: z.boolean().default(true).volatile(),
36
+ fetchBeforeCreate: z.boolean().default(false).volatile(),
37
+ autoPruneWorktrees: z.boolean().default(false).volatile(),
38
+ keepWorktrees: z.number().default(KEEP_WORKTREES_DEFAULT).volatile(),
39
+ postCreateCopyFiles: z.array(z.string()).default([]).volatile(),
38
40
  });
39
41
  /** Reject stale or misspelled config keys before defaults can hide them. */
40
42
  export function validateConfig(config) {
41
- const unknown = Object.keys(config).find(key => key !== 'rootDir' && key !== 'groupSidebar');
43
+ const unknown = Object.keys(config).find(key => key !== 'rootDir' && key !== 'groupSidebar' && key !== 'fetchBeforeCreate' && key !== 'autoPruneWorktrees' && key !== 'keepWorktrees' && key !== 'postCreateCopyFiles');
42
44
  if (unknown !== undefined) {
43
45
  throw new Error(`GitWorktreeConfig: unknown key "${unknown}"`);
44
46
  }
45
- if (config.rootDir !== undefined && (typeof config.rootDir !== 'string' || config.rootDir.length === 0)) {
47
+ const root = readVolatile(config.rootDir);
48
+ if (root !== undefined && (typeof root !== 'string' || root.length === 0)) {
46
49
  throw new Error('GitWorktreeConfig: "rootDir" must be a non-empty string');
47
50
  }
48
- if (config.groupSidebar !== undefined && typeof config.groupSidebar !== 'boolean') {
51
+ const groupSidebar = readVolatile(config.groupSidebar);
52
+ if (groupSidebar !== undefined && typeof groupSidebar !== 'boolean') {
49
53
  throw new Error('GitWorktreeConfig: "groupSidebar" must be a boolean');
50
54
  }
51
- validateRootDir(config.rootDir);
55
+ const fetchBeforeCreate = readVolatile(config.fetchBeforeCreate);
56
+ if (fetchBeforeCreate !== undefined && typeof fetchBeforeCreate !== 'boolean') {
57
+ throw new Error('GitWorktreeConfig: "fetchBeforeCreate" must be a boolean');
58
+ }
59
+ const autoPruneWorktrees = readVolatile(config.autoPruneWorktrees);
60
+ if (autoPruneWorktrees !== undefined && typeof autoPruneWorktrees !== 'boolean') {
61
+ throw new Error('GitWorktreeConfig: "autoPruneWorktrees" must be a boolean');
62
+ }
63
+ const postCreateCopyFiles = readVolatile(config.postCreateCopyFiles);
64
+ if (postCreateCopyFiles !== undefined) {
65
+ if (!Array.isArray(postCreateCopyFiles) || !postCreateCopyFiles.every(item => typeof item === 'string')) {
66
+ throw new Error('GitWorktreeConfig: "postCreateCopyFiles" must be an array of strings');
67
+ }
68
+ }
69
+ validateKeepWorktrees(readVolatile(config.keepWorktrees));
70
+ validateRootDir(root);
71
+ }
72
+ /**
73
+ * The prune cap must be an integer >= 1: 0 would read as "create then
74
+ * immediately self-delete" (the fresh worktree is excluded, but every other
75
+ * one dies on the next creation), a fraction cannot count directories.
76
+ * Absent = the shipped default, which passes.
77
+ */
78
+ export function validateKeepWorktrees(value) {
79
+ if (value === undefined)
80
+ return;
81
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
82
+ throw new Error('GitWorktreeConfig: "keepWorktrees" must be an integer >= 1');
83
+ }
52
84
  }
53
85
  /** The settings namespace this plugin serves; its browser card spells the same string. */
54
86
  export const GIT_WORKTREE_NS = 'git-worktree';
55
- /** Schema resolving the `git-worktree` settings section. */
56
- export const sectionSchema = z.object({
57
- rootDir: z.string(),
58
- groupSidebar: z.boolean(),
59
- });
60
- /** The section-shaped view of a config: absent keys stay absent (`exactOptionalPropertyTypes`). */
87
+ /** The section-shaped view of a config: absent keys stay absent
88
+ * (`exactOptionalPropertyTypes`) except the switches, which spell their
89
+ * shipped defaults so a user-layer unset can always fall back to them. */
61
90
  export function sectionOf(config) {
91
+ const rootDir = readVolatile(config.rootDir);
92
+ const postCreateCopyFiles = readVolatile(config.postCreateCopyFiles);
93
+ const groupSidebar = readVolatile(config.groupSidebar);
94
+ const fetchBeforeCreate = readVolatile(config.fetchBeforeCreate);
95
+ const autoPruneWorktrees = readVolatile(config.autoPruneWorktrees);
96
+ const keepWorktrees = readVolatile(config.keepWorktrees);
62
97
  return {
63
- ...(config.rootDir === undefined ? {} : { rootDir: config.rootDir }),
64
- // The composition layer spells the shipped default (grouping ON) so a
65
- // user-layer unset can always fall back to it.
66
- groupSidebar: config.groupSidebar ?? true,
98
+ ...(rootDir === undefined ? {} : { rootDir }),
99
+ ...(postCreateCopyFiles === undefined ? {} : { postCreateCopyFiles }),
100
+ // The composition layer spells the shipped defaults so a user-layer
101
+ // unset can always fall back to them.
102
+ groupSidebar: groupSidebar ?? true,
103
+ fetchBeforeCreate: fetchBeforeCreate ?? false,
104
+ autoPruneWorktrees: autoPruneWorktrees ?? false,
105
+ keepWorktrees: keepWorktrees ?? KEEP_WORKTREES_DEFAULT,
67
106
  };
68
107
  }
69
108
  /**
70
- * Plugin apply: install the settings section, migrate any legacy stored root
71
- * into it, then mount routes on any webServer that comes and goes.
109
+ * Plugin apply: mount the settings presentation policy and HTTP routes on any
110
+ * webServer that comes and goes.
72
111
  * @param ctx - host cordis context.
73
- * @param config - the composition entry config (the section's base layer).
112
+ * @param config - the composition entry config.
74
113
  */
75
114
  export function apply(ctx, config = {}) {
76
115
  validateConfig(config);
77
- // The section source: the composition entry until a settings service
78
- // attaches, then `setSource` repoints it at the resolved settings scope.
79
- // A thunk, not a snapshot — reads see the current resolution at call time,
80
- // so the routes follow a stored edit without re-registering anything.
81
- let sectionSource = () => sectionOf(config);
116
+ const currentConfig = () => ctx.fiber?.config ?? config;
82
117
  const deps = () => ({
83
118
  exec: childProcessExec,
84
- sectionRootDir: () => sectionSource().rootDir,
119
+ sectionRootDir: () => readVolatile(currentConfig().rootDir),
120
+ sectionFetchBeforeCreate: () => readVolatile(currentConfig().fetchBeforeCreate),
121
+ sectionPostCreateCopyFiles: () => readVolatile(currentConfig().postCreateCopyFiles),
85
122
  home: () => homedir(),
86
123
  envHome: () => process.env.DSH_HOME,
87
124
  });
88
- // Host 0.1.2 hosts section installation on the provider itself: the same
89
- // composition-entry base, validate, setSource, and onChange hooks ride
90
- // `SettingsProvider.installSection`, reached through a settings injection.
91
- // The registration is an effect on this plugin's fiber either way, so a
92
- // late-attaching settings service is handled by the injection itself.
125
+ // In dsh 0.1.7+, the settings service projects volatile Config fields into forms.
126
+ // We configure auto: false to inform the host that this plugin provides its own
127
+ // dedicated configuration card (via `plugins.bundle.config`).
93
128
  ctx.inject(['settings'], (settingsCtx) => {
94
- settingsCtx.settings.installSection(ctx, GIT_WORKTREE_NS, sectionSchema, sectionOf(config), {
95
- validate: value => {
96
- validateRootDir(value.rootDir);
97
- if (value.groupSidebar !== undefined && typeof value.groupSidebar !== 'boolean') {
98
- throw new Error('groupSidebar must be a boolean');
99
- }
100
- },
101
- setSource: (source) => { sectionSource = source; },
102
- onChange: () => {
103
- // The storage root takes effect live: the routes read the section
104
- // source per request, so a committed edit needs no action here.
105
- },
106
- });
107
- });
108
- // One-shot legacy migration: the pre-0.3 plugin persisted its own
109
- // ~/.dsh/git-work-tree/settings.json. Registered after installSection
110
- // so the namespace is on the ledger by the time this fiber runs; a failure
111
- // (or a user layer that already chose) leaves both documents exactly as
112
- // they are, and the next startup retries.
113
- ctx.inject(['settings'], (sctx) => {
114
- const file = settingsFileOf(homedir());
115
- void (async () => {
116
- const legacy = await loadLegacySettings(file);
117
- const descriptor = sctx.settings.describe().find(d => d.ns === GIT_WORKTREE_NS);
118
- if (descriptor === undefined)
119
- return;
120
- const user = descriptor.user;
121
- const userLayer = typeof user === 'object' && user !== null ? user : undefined;
122
- const planned = planLegacyMigration(legacy, userLayer);
123
- if (planned === undefined)
124
- return;
125
- try {
126
- await sctx.settings.update(GIT_WORKTREE_NS, { rootDir: planned });
127
- await rename(file, migratedFileOf(file));
128
- console.log(`[git-worktree] legacy settings migrated to the settings document (${planned})`);
129
- }
130
- catch (error) {
131
- console.warn('[git-worktree] legacy settings migration failed:', error instanceof Error ? error.message : String(error));
132
- }
133
- })();
129
+ settingsCtx.effect(() => settingsCtx.settings.configure({ auto: false }, ctx.fiber), 'git-worktree: settings presentation policy');
134
130
  });
135
131
  ctx.inject(['webServer'], (webCtx) => {
136
132
  /** Send one outcome as JSON; no-store because repo facts are point-in-time. */
@@ -187,6 +183,8 @@ export function apply(ctx, config = {}) {
187
183
  postRoute(ROUTE_WORKTREE, 'worktree', handleCreateWorktree);
188
184
  postRoute(ROUTE_SWITCH, 'switch', handleSwitch);
189
185
  postRoute(ROUTE_BRANCH, 'branch', handleCreateBranch);
186
+ postRoute(ROUTE_BRANCH_RENAME, 'branch-rename', handleRenameBranch);
187
+ postRoute(ROUTE_BRANCH_DELETE, 'branch-delete', handleDeleteBranch);
190
188
  postRoute(ROUTE_FETCH, 'fetch', handleFetch);
191
189
  postRoute(ROUTE_GROUP, 'group', handleGroupWorktrees);
192
190
  postRoute(ROUTE_UPDATE, 'update', handleUpdate);
@@ -194,5 +192,7 @@ export function apply(ctx, config = {}) {
194
192
  postRoute(ROUTE_REMOVE, 'remove', handleRemoveWorktree);
195
193
  postRoute(ROUTE_EXISTS, 'exists', handlePathExists);
196
194
  postRoute(ROUTE_ENSURE_DIRECTORY, 'ensure-directory', handleEnsureDirectory);
195
+ postRoute(ROUTE_WORKTREES_ALL, 'worktrees-all', handleWorktreesAll);
196
+ postRoute(ROUTE_PURGE, 'purge', handlePurgeDirectory);
197
197
  });
198
198
  }
package/lib/routes.d.ts CHANGED
@@ -2,25 +2,43 @@
2
2
  * Route logic as pure functions: query/body in, status+body out. The HTTP
3
3
  * shell (index.ts) owns req/res mechanics; everything testable lives here.
4
4
  */
5
- import { type DirExists, type Exec } from './git.js';
6
- import type { CreateBranchResult, CreateWorktreeResult, EnsureDirectoryResult, FetchResult, GroupWorkspacesResult, InspectWorktreeResult, PathExistsResult, RemoveWorktreeResult, RepoStatus, RouteError, SwitchResult, UpdateResult } from './wire.js';
5
+ import { type CopyFilesSeams } from './copy-files.js';
6
+ import { type DirExists, type ExcludeSeams, type Exec } from './git.js';
7
+ import type { CreateBranchResult, CreateWorktreeResult, EnsureDirectoryResult, FetchResult, GroupWorkspacesResult, InspectWorktreeResult, PathExistsResult, PurgeDirectoryResult, RemoveWorktreeResult, RepoStatus, RouteError, SwitchResult, UpdateResult, WorktreesAllResult } from './wire.js';
7
8
  /** Everything the handlers need from the host half. */
8
9
  export interface RouteDeps {
9
10
  exec: Exec;
10
11
  /** The settings-resolved rootDir (absent/blank = the default location). */
11
12
  sectionRootDir: () => string | undefined;
13
+ /** Whether a worktree creation syncs the remotes first (absent = off). */
14
+ sectionFetchBeforeCreate: () => boolean | undefined;
15
+ /** Post-create configuration files to copy when .worktreeinclude is absent. */
16
+ sectionPostCreateCopyFiles?: () => string[] | undefined;
12
17
  /** User home directory seam. */
13
18
  home: () => string;
14
19
  /** `$DSH_HOME` environment value seam. */
15
20
  envHome: () => string | undefined;
16
21
  /** Worktree-registration existence seam (tests substitute). */
17
22
  dirExists?: DirExists;
23
+ /** Local-ignore write seams (tests substitute). */
24
+ excludeSeams?: ExcludeSeams;
25
+ /** Post-create file copy seams (tests substitute). */
26
+ copyFilesSeams?: CopyFilesSeams;
18
27
  /** Directory probe seam over fs.stat (true = exists AND is a directory);
19
28
  * tests substitute. */
20
29
  statDirectory?: (path: string) => Promise<boolean>;
21
30
  /** Recursive mkdir seam (fs.mkdir recursive); tests substitute. */
22
31
  mkdirRecursive?: (path: string) => Promise<void>;
32
+ /** One-level directory listing seam (fs.readdir with dirents); tests
33
+ * substitute. */
34
+ listDir?: (path: string) => Promise<string[]>;
35
+ /** Recursive force rm seam (fs.rm with retries); tests substitute. */
36
+ rmRecursive?: (path: string) => Promise<void>;
23
37
  }
38
+ /** Real fs-backed one-level directory listing (names only). Plain FILES are
39
+ * filtered out — the storage root can carry strays (a legacy settings.json
40
+ * was seen in the wild), and the scan lists worktree SLOTS, not entries. */
41
+ export declare function fsListDir(path: string): Promise<string[]>;
24
42
  /** Real fs-backed directory probe: exists and is a directory. */
25
43
  export declare function fsStatDirectory(path: string): Promise<boolean>;
26
44
  /** Real fs-backed recursive mkdir. */
@@ -28,7 +46,7 @@ export declare function fsMkdirRecursive(path: string): Promise<void>;
28
46
  /** One route outcome: HTTP status plus the JSON body. */
29
47
  export interface RouteOutcome {
30
48
  status: number;
31
- body: RepoStatus | CreateWorktreeResult | SwitchResult | CreateBranchResult | FetchResult | UpdateResult | GroupWorkspacesResult | InspectWorktreeResult | RemoveWorktreeResult | PathExistsResult | EnsureDirectoryResult | RouteError;
49
+ body: RepoStatus | CreateWorktreeResult | SwitchResult | CreateBranchResult | FetchResult | UpdateResult | GroupWorkspacesResult | InspectWorktreeResult | RemoveWorktreeResult | PathExistsResult | EnsureDirectoryResult | WorktreesAllResult | PurgeDirectoryResult | RouteError;
32
50
  }
33
51
  /**
34
52
  * POST /group — git belonging facts for a batch of workspace directories.
@@ -40,6 +58,46 @@ export interface RouteOutcome {
40
58
  * @param body - parsed request body: `{ paths }`.
41
59
  */
42
60
  export declare function handleGroupWorktrees(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
61
+ /**
62
+ * POST /worktrees-all — git facts for every DIRECT child directory of the two
63
+ * storage locations the plugin has ever used, merged:
64
+ *
65
+ * - legacy: the resolved central storage root (today a read-only historical
66
+ * location — existing worktrees stay put, `rootDir` still resolves it);
67
+ * - project: `<repo>/.dsh/gitworktree` under every DISTINCT repository root
68
+ * derived from the caller's registered workspace paths (the current
69
+ * layout — its path prefix is what the workspace tree nests under).
70
+ *
71
+ * The management dialog's data source (and, through it, the lazy prune's):
72
+ * one scan answers for all repositories at once, orphan directories included
73
+ * (a child that probes as no git repository comes back with null facts
74
+ * rather than being dropped — the dialog shows it as unrecognized). Missing
75
+ * locations answer their half as an empty list; per-child probe failures
76
+ * degrade to null facts, never a 500 — the dialog must render, not error
77
+ * out. Each location that holds more than {@link SCAN_CHILDREN_LIMIT}
78
+ * children answers its first slice, and any truncation marks the whole
79
+ * response `truncated`, so a misconfigured location cannot turn one dialog
80
+ * open into thousands of git spawns.
81
+ * @param deps - host dependencies.
82
+ * @param body - parsed request body: `{ workspaces? }`.
83
+ */
84
+ export declare function handleWorktreesAll(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
85
+ /** Real fs-backed recursive force rm (Windows file-lock retries included). */
86
+ export declare function fsRmRecursive(path: string): Promise<void>;
87
+ /**
88
+ * POST /purge — delete a NON-git directory sitting DIRECTLY inside one of the
89
+ * plugin's two storage layouts: the legacy central root or a repository's
90
+ * `.dsh/gitworktree`. The orphaned leftover a half-failed `worktree remove`
91
+ * can leave behind (git registration and the .git file already gone,
92
+ * contents stranded on disk). Triple-gated: one level below a storage
93
+ * location (resolved forms, same slot boundary as /ensure-directory), a real
94
+ * directory, and NOT a git repository — anything git still recognizes must
95
+ * go through /remove, where the removal carries the session-archive and
96
+ * unregistration half. Deletion is a plain recursive force rm.
97
+ * @param deps - host dependencies.
98
+ * @param body - parsed request body: `{ path }`.
99
+ */
100
+ export declare function handlePurgeDirectory(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
43
101
  /**
44
102
  * GET /status 鈥?repository facts for one directory.
45
103
  * @param deps - host dependencies.
@@ -47,9 +105,14 @@ export declare function handleGroupWorktrees(deps: RouteDeps, body: unknown): Pr
47
105
  */
48
106
  export declare function handleStatus(deps: RouteDeps, path: string | undefined): Promise<RouteOutcome>;
49
107
  /**
50
- * POST /worktree 鈥?create or reuse the worktree for a branch, then report the
51
- * directory so the client can register it as a workspace. With `cutout: true`
52
- * the branch is the CURRENT checkout (occupied by the main worktree, so git
108
+ * POST /worktree — create or reuse the worktree for a branch, then report the
109
+ * directory so the client can register it as a workspace. The worktree lands
110
+ * at `<repo>/.dsh/gitworktree/<branch>` (path prefix = repository, so the
111
+ * native workspace tree nests it under its repository automatically); an
112
+ * existing registration for the branch ANYWHERE is reused first (the
113
+ * repository-wide worktree list is location-independent — legacy-central
114
+ * worktrees keep being returned, never duplicated). With `cutout: true` the
115
+ * branch is the CURRENT checkout (occupied by the main worktree, so git
53
116
  * refuses to add it): a new branch is cut out of it (`<branch>-wt`, first
54
117
  * free `-wt<N>` suffix) and isolated in the fresh worktree instead.
55
118
  * @param deps - host dependencies.
@@ -63,14 +126,38 @@ export declare function handleCreateWorktree(deps: RouteDeps, body: unknown): Pr
63
126
  */
64
127
  export declare function handleSwitch(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
65
128
  /**
66
- * POST /branch 鈥?create a NEW branch from the queried directory's current
67
- * checkout (whatever its HEAD points at, detached included) and check it out
68
- * in place. Git validates the name; the client pre-flights the same rules
129
+ * POST /branch — create a NEW branch. Without `from`, from the queried
130
+ * directory's current checkout (whatever its HEAD points at, detached
131
+ * included), checked out in place. With `from` (a local branch or a remote
132
+ * tracking ref): checked out here too when `checkout` is set
133
+ * (`git switch -c <name> <from>`), created with no checkout touched
134
+ * otherwise (`git branch`) — a create aimed at another branch must not
135
+ * silently move the session's HEAD unless the caller asked for exactly
136
+ * that. Git validates both names; the client pre-flights the same rules
69
137
  * and only sends names it already accepts.
70
138
  * @param deps - host dependencies.
71
139
  * @param body - parsed request body.
72
140
  */
73
141
  export declare function handleCreateBranch(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
142
+ /**
143
+ * POST /branch-rename — rename a LOCAL branch (`git branch -m`). Runs at the
144
+ * repository root: branch refs are repository-wide and worktree HEADs
145
+ * pointing at the old name follow the ref. Git validates the new name and
146
+ * refuses a target that already exists; both map to 400 through
147
+ * {@link gitFailure}.
148
+ * @param deps - host dependencies.
149
+ * @param body - parsed request body.
150
+ */
151
+ export declare function handleRenameBranch(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
152
+ /**
153
+ * POST /branch-delete — delete a LOCAL branch with the SAFE form
154
+ * (`git branch -d`): git refuses unmerged commits and branches checked out
155
+ * in any worktree, both mapping to 400 through {@link gitFailure}. No
156
+ * force variant — a menu click must never discard commits.
157
+ * @param deps - host dependencies.
158
+ * @param body - parsed request body.
159
+ */
160
+ export declare function handleDeleteBranch(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
74
161
  /**
75
162
  * POST /fetch 鈥?sync remote-tracking refs for the repository: fetch every
76
163
  * remote and prune tracking branches the remotes no longer carry. Pure
@@ -122,8 +209,9 @@ export declare function handleRemoveWorktree(deps: RouteDeps, body: unknown): Pr
122
209
  export declare function handlePathExists(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
123
210
  /**
124
211
  * POST /ensure-directory — recreate a MISSING worktree storage slot
125
- * (`mkdir -p`). Strictly gated to paths sitting DIRECTLY inside the resolved
126
- * worktree storage root: those slots were planned and created by this plugin,
212
+ * (`mkdir -p`). Strictly gated to paths sitting DIRECTLY inside one of the
213
+ * plugin's two storage layouts (the legacy central root, or a repository's
214
+ * `.dsh/gitworktree`): those slots were planned and created by this plugin,
127
215
  * so rebuilding the empty folder is self-healing (historical sessions
128
216
  * reattach automatically once realpath matches again — DSH keeps the
129
217
  * workspace accounting and filters membership by the session header's cwd).