dsh-crate 0.0.0-stage → 0.5.0

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.
Files changed (132) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +288 -2
  3. package/README.zh.md +263 -0
  4. package/UPDATE-API-V1.md +207 -0
  5. package/assets/logo.svg +37 -0
  6. package/client/client.js +18964 -0
  7. package/cordis.patch.yml +4 -0
  8. package/lib/accelerate.js +194 -0
  9. package/lib/agents.js +67 -0
  10. package/lib/backup.js +688 -0
  11. package/lib/body-progress.js +173 -0
  12. package/lib/catalog-local-match.js +160 -0
  13. package/lib/catalog-npm.js +180 -0
  14. package/lib/changelog.js +462 -0
  15. package/lib/channels.js +64 -0
  16. package/lib/check.js +1557 -0
  17. package/lib/compatibility.js +243 -0
  18. package/lib/crate-catalog.js +179 -0
  19. package/lib/diagnostics.js +49 -0
  20. package/lib/discovery-compatibility.js +447 -0
  21. package/lib/drain-journal.js +164 -0
  22. package/lib/drain.js +1043 -0
  23. package/lib/dsh-cli.js +1373 -0
  24. package/lib/dsh-install.js +259 -0
  25. package/lib/entry-identity.js +85 -0
  26. package/lib/gist.js +369 -0
  27. package/lib/groups.js +108 -0
  28. package/lib/home-paths.js +29 -0
  29. package/lib/host-recovery.js +187 -0
  30. package/lib/hot.js +871 -0
  31. package/lib/http.js +252 -0
  32. package/lib/index.js +394 -0
  33. package/lib/install.js +1147 -0
  34. package/lib/lifecycle.js +37 -0
  35. package/lib/log-redaction.js +24 -0
  36. package/lib/log.js +204 -0
  37. package/lib/ndjson.js +154 -0
  38. package/lib/net.js +174 -0
  39. package/lib/official-desktop.js +619 -0
  40. package/lib/order.js +284 -0
  41. package/lib/patch.js +943 -0
  42. package/lib/pending-rows.js +142 -0
  43. package/lib/pending-updates.js +346 -0
  44. package/lib/pnpm-compat.js +972 -0
  45. package/lib/presets.js +282 -0
  46. package/lib/probe-context.js +20 -0
  47. package/lib/proc-text.js +69 -0
  48. package/lib/profile.js +1978 -0
  49. package/lib/recovery.js +1059 -0
  50. package/lib/region-probe.js +93 -0
  51. package/lib/regions.js +283 -0
  52. package/lib/registry.js +308 -0
  53. package/lib/release-candidates.js +115 -0
  54. package/lib/release-updates.js +70 -0
  55. package/lib/restart.js +688 -0
  56. package/lib/routes.js +7960 -0
  57. package/lib/settings.js +164 -0
  58. package/lib/shelfry-catalog.js +179 -0
  59. package/lib/snapshot.js +506 -0
  60. package/lib/source-migration.js +164 -0
  61. package/lib/sources.js +1005 -0
  62. package/lib/state.js +38 -0
  63. package/lib/store.js +163 -0
  64. package/lib/themes.js +350 -0
  65. package/lib/trial.js +125 -0
  66. package/lib/types/accelerate.d.ts +85 -0
  67. package/lib/types/agents.d.ts +52 -0
  68. package/lib/types/backup.d.ts +171 -0
  69. package/lib/types/body-progress.d.ts +94 -0
  70. package/lib/types/catalog-local-match.d.ts +39 -0
  71. package/lib/types/catalog-npm.d.ts +77 -0
  72. package/lib/types/changelog.d.ts +131 -0
  73. package/lib/types/channels.d.ts +56 -0
  74. package/lib/types/check.d.ts +353 -0
  75. package/lib/types/compatibility.d.ts +83 -0
  76. package/lib/types/crate-catalog.d.ts +48 -0
  77. package/lib/types/diagnostics.d.ts +29 -0
  78. package/lib/types/discovery-compatibility.d.ts +145 -0
  79. package/lib/types/drain-journal.d.ts +25 -0
  80. package/lib/types/drain.d.ts +306 -0
  81. package/lib/types/dsh-cli.d.ts +481 -0
  82. package/lib/types/dsh-install.d.ts +106 -0
  83. package/lib/types/entry-identity.d.ts +68 -0
  84. package/lib/types/gist.d.ts +79 -0
  85. package/lib/types/groups.d.ts +34 -0
  86. package/lib/types/home-paths.d.ts +13 -0
  87. package/lib/types/host-recovery.d.ts +95 -0
  88. package/lib/types/hot.d.ts +405 -0
  89. package/lib/types/http.d.ts +114 -0
  90. package/lib/types/index.d.ts +52 -0
  91. package/lib/types/install.d.ts +463 -0
  92. package/lib/types/lifecycle.d.ts +14 -0
  93. package/lib/types/log-redaction.d.ts +2 -0
  94. package/lib/types/log.d.ts +43 -0
  95. package/lib/types/ndjson.d.ts +52 -0
  96. package/lib/types/net.d.ts +94 -0
  97. package/lib/types/official-desktop.d.ts +59 -0
  98. package/lib/types/order.d.ts +100 -0
  99. package/lib/types/patch.d.ts +218 -0
  100. package/lib/types/pending-rows.d.ts +81 -0
  101. package/lib/types/pending-updates.d.ts +161 -0
  102. package/lib/types/pnpm-compat.d.ts +102 -0
  103. package/lib/types/presets.d.ts +94 -0
  104. package/lib/types/probe-context.d.ts +14 -0
  105. package/lib/types/proc-text.d.ts +29 -0
  106. package/lib/types/profile.d.ts +551 -0
  107. package/lib/types/recovery.d.ts +342 -0
  108. package/lib/types/region-probe.d.ts +50 -0
  109. package/lib/types/regions.d.ts +134 -0
  110. package/lib/types/registry.d.ts +160 -0
  111. package/lib/types/release-candidates.d.ts +42 -0
  112. package/lib/types/release-updates.d.ts +15 -0
  113. package/lib/types/restart.d.ts +279 -0
  114. package/lib/types/routes.d.ts +130 -0
  115. package/lib/types/settings.d.ts +112 -0
  116. package/lib/types/shelfry-catalog.d.ts +48 -0
  117. package/lib/types/snapshot.d.ts +93 -0
  118. package/lib/types/source-migration.d.ts +100 -0
  119. package/lib/types/sources.d.ts +391 -0
  120. package/lib/types/state.d.ts +20 -0
  121. package/lib/types/store.d.ts +47 -0
  122. package/lib/types/themes.d.ts +46 -0
  123. package/lib/types/trial.d.ts +61 -0
  124. package/lib/types/update-api-v1.d.ts +83 -0
  125. package/lib/types/updates.d.ts +273 -0
  126. package/lib/types/verify.d.ts +277 -0
  127. package/lib/update-api-v1.js +273 -0
  128. package/lib/updates.js +981 -0
  129. package/lib/verify.js +904 -0
  130. package/locale/en.json +5 -0
  131. package/locale/zh.json +6 -0
  132. package/package.json +113 -4
@@ -0,0 +1,79 @@
1
+ import { type ProfileBackup } from './backup.ts';
2
+ /** The single file every dsh-crate backup Gist carries. */
3
+ export declare const GIST_FILENAME = "dsh-profile-backup.json";
4
+ /** GitHub hard limit for one Gist file (1 MB); enforced before upload. */
5
+ export declare const GIST_MAX_BYTES: number;
6
+ /** Environment variable for a host-configured token (never read from disk). */
7
+ export declare const GIST_TOKEN_ENV = "DSH_GITHUB_TOKEN";
8
+ /** Machine-readable error codes the client maps to localized messages. */
9
+ export type GistErrorCode = 'auth' | 'notfound' | 'rate-limit' | 'invalid' | 'timeout' | 'network' | 'other';
10
+ /** Error with a code for the UI; the message stays human-readable. */
11
+ export declare class GistError extends Error {
12
+ readonly code: GistErrorCode;
13
+ constructor(message: string, code?: GistErrorCode);
14
+ }
15
+ /** Classify any thrown value into a stable GistErrorCode. */
16
+ export declare function gistErrorCode(error: unknown): GistErrorCode;
17
+ export interface GistRef {
18
+ id: string;
19
+ htmlUrl: string;
20
+ }
21
+ /** Where the token used for a request came from (shown in the UI). */
22
+ export type GistTokenSource = 'token' | 'env' | 'gh';
23
+ /**
24
+ * Normalize a Gist id or a gist.github.com URL to a bare id.
25
+ * Anything else (paths, embedded slashes, oversize input) is rejected.
26
+ */
27
+ export declare function parseGistId(input: string): string;
28
+ /**
29
+ * Resolve the token for one request, in order of preference:
30
+ * 1. an explicitly supplied token (session memory only);
31
+ * 2. the host-configured DSH_GITHUB_TOKEN environment variable;
32
+ * 3. an already-logged-in GitHub CLI (`gh auth token`) — the token is used
33
+ * for this request only and never written to disk.
34
+ */
35
+ export declare function resolveGistTokenSource(bodyToken: unknown): Promise<{
36
+ token: string;
37
+ source: GistTokenSource;
38
+ }>;
39
+ /** Resolve just the token (kept for callers that do not need the source). */
40
+ export declare function resolveGistToken(bodyToken: unknown): Promise<string>;
41
+ /** Test hook: drop the gh token cache between tests. */
42
+ export declare function resetGhTokenCache(): void;
43
+ /**
44
+ * Run `gh auth token` in a child the parent does not wait on, and give up
45
+ * after 8 s no matter what. The parent never waits on the child (unref), so even if gh.exe
46
+ * wedges under WSL interop the host event loop stays free and the request
47
+ * returns a definite answer. 8 s because a Windows gh.exe cold start through
48
+ * WSL interop is routinely slower than a native binary.
49
+ */
50
+ /**
51
+ * Spawn options for `gh auth token`, kept in one place because the Windows
52
+ * answer is not the obvious one (#1094).
53
+ *
54
+ * `detached: true` becomes DETACHED_PROCESS on Windows, which strips the
55
+ * parent's console and gives the child a NEW visible one — `windowsHide`'s
56
+ * CREATE_NO_WINDOW loses to it. With a console-less host (DSH Desktop, a
57
+ * wscript/task-scheduler launch) every 验证 / 导出 / 导入 on the backup page
58
+ * flashed a terminal window titled `gh.exe`. Measured on Windows 11, two
59
+ * variants, three runs each: detached visible 3/3, non-detached 0/3.
60
+ *
61
+ * What detached was here for — the parent never waiting on the child — is
62
+ * already the `unref()` and the 8 s watchdog below, so POSIX keeps it and
63
+ * Windows drops it.
64
+ */
65
+ export declare function ghAuthSpawnOptions(platform?: NodeJS.Platform): {
66
+ stdio: ['ignore', 'pipe', 'ignore'];
67
+ detached: boolean;
68
+ windowsHide: boolean;
69
+ };
70
+ /** Create a new private Gist carrying one backup file. */
71
+ export declare function createGist(token: string, content: string, signal?: AbortSignal): Promise<GistRef>;
72
+ /** Overwrite the backup file inside an existing Gist (other files kept). */
73
+ export declare function updateGist(token: string, gistId: string, content: string, signal?: AbortSignal): Promise<GistRef>;
74
+ /** Download and strictly validate the backup file inside a Gist. */
75
+ export declare function readGist(token: string, gistId: string, signal?: AbortSignal): Promise<ProfileBackup>;
76
+ /** Confirm the token is usable (GET /user). */
77
+ export declare function verifyGistToken(token: string, signal?: AbortSignal): Promise<void>;
78
+ /** True when the serialized backup fits inside a Gist file. */
79
+ export declare function fitsGistLimit(content: string): boolean;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Custom plugin groups (Roadmap #60): user-defined named collections of
3
+ * installed plugins whose enable/disable state can be switched as a unit —
4
+ * borrowing the "group by capability, toggle as one" idea from Claude
5
+ * Desktop's skill management. Membership lives in state.json and is the
6
+ * only durable truth: a group's switch state is always derived from its
7
+ * members and never persisted itself.
8
+ *
9
+ * Pure CRUD over the caller-owned state objects; routes.ts persists after
10
+ * each mutation and applies the live toggles for the batch action.
11
+ */
12
+ export type GroupAction = 'create' | 'rename' | 'delete' | 'set-members' | 'toggle';
13
+ /** The slices of market state group CRUD touches (routes.ts owns the rest). */
14
+ export interface GroupState {
15
+ groups: Record<string, string[]>;
16
+ groupOrder: string[];
17
+ }
18
+ export interface GroupMutationResult {
19
+ ok: boolean;
20
+ error?: string;
21
+ }
22
+ export declare function createGroup(state: GroupState, name: unknown): GroupMutationResult;
23
+ export declare function renameGroup(state: GroupState, name: unknown, newName: unknown): GroupMutationResult;
24
+ export declare function deleteGroup(state: GroupState, name: unknown): GroupMutationResult;
25
+ /**
26
+ * Replace a group's membership. Only currently installed plugins can be
27
+ * members — ghost names (uninstalled meanwhile) are dropped and duplicates
28
+ * collapse, so the persisted list stays clean. Themes are exclusive: a group
29
+ * may hold at most one theme plugin, mirroring the global one-active-theme
30
+ * rule (only one theme can be enabled at a time).
31
+ */
32
+ export declare function setGroupMembers(state: GroupState, name: unknown, members: unknown, installed: ReadonlySet<string>, themes: ReadonlySet<string>): GroupMutationResult;
33
+ /** Drop `name` from every group (called after a successful uninstall). */
34
+ export declare function removeFromGroups(state: GroupState, name: string): void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Resolve the Harness home with the same semantics as the current
3
+ * `@deepseek-ai/dsh-home-paths` package.
4
+ */
5
+ /** Default single-root Harness home. */
6
+ export declare function defaultDshHome(): string;
7
+ /** Expand the tilde forms supported by DSH configuration. */
8
+ export declare function expandHomePath(path: string): string;
9
+ /**
10
+ * Resolve an explicit home, `DSH_HOME`, or the default to one normalized
11
+ * absolute path. Blank environment values are unset, matching DSH alpha.
12
+ */
13
+ export declare function resolveDshHome(configured?: string, env?: Record<string, string | undefined>): string;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * What DSH's own fatal recovery leaves behind (#875).
3
+ *
4
+ * When a boot fails, the desktop shell offers a recovery prompt. Using it
5
+ * runs `sanitizeProfile` in `@deepseek-ai/dsh-app-boot`, and that does not
6
+ * edit the profile patch — it renames `cordis.patch.yml` to a
7
+ * `<patch>.bak-<epoch ms>` sibling, writes a small default stub in its place,
8
+ * and restores the bundle list it was handed. The app then comes up normally,
9
+ * so from the outside there is no error at all: the stub looks exactly like a
10
+ * patch that never had content, and the backup is an unlabelled file sitting
11
+ * next to it with no timestamp a person would read. In the report that found
12
+ * this, 22 KB of providers, models, model defaults and permission presets
13
+ * vanished that way and nothing on screen said so.
14
+ *
15
+ * DSH core is the one destroying data, and the fix for that belongs upstream
16
+ * (never overwrite a patch that has content; keep an unticked entry as a
17
+ * disabled row instead of dropping it from `dsh.profile.bundles`). But the
18
+ * promise the user was acting on is this page's — the market's own recovery
19
+ * surface is the documented way back to a booting app — so the market carries
20
+ * the detection and the way back.
21
+ *
22
+ * The shape this looks for is deliberately narrow: a sibling named exactly
23
+ * `<patch name>.bak-<digits>`, holding rows, LARGER than the live patch, and
24
+ * naming rows the live patch no longer has. A hand-edited file, the market's
25
+ * own `.bak` shapes (`package.json.bak-asm` and friends), an older backup, or
26
+ * a patch that simply lost a row are all outside this surface — the point is
27
+ * to speak up only when the evidence is unambiguous, because a false alarm
28
+ * here trains the user to ignore the one that matters.
29
+ */
30
+ /** One `.bak-<epoch ms>` sibling of the profile patch. */
31
+ export interface HostRecoveryBackup {
32
+ /** File name as it sits next to the patch. */
33
+ name: string;
34
+ /** Epoch ms parsed out of the name, or null when the name is not the host's shape. */
35
+ stamp: number | null;
36
+ bytes: number;
37
+ /** Row ids the backup carries (insert titles and toggled rows). */
38
+ rowIds: string[];
39
+ }
40
+ /** What the profile patch looks like now, next to what the backups still hold. */
41
+ export interface HostRecoveryView {
42
+ /** The live patch's file name, for the wording. */
43
+ patchName: string;
44
+ currentBytes: number;
45
+ currentRowIds: string[];
46
+ /** Newest first, and only backups that carry rows — a stub is not a restore point. */
47
+ backups: HostRecoveryBackup[];
48
+ /** Row ids the newest backup carries and the live patch no longer does. */
49
+ lostRowIds: string[];
50
+ /**
51
+ * True only for the wipe shape: a backup with rows exists, the live patch is
52
+ * the smaller file, and rows it used to have are gone. Everything the UI
53
+ * says hangs off this, so it stays conservative.
54
+ */
55
+ offerRestore: boolean;
56
+ }
57
+ /**
58
+ * Read the profile's recovery state. Never throws: a profile the market
59
+ * cannot read is a profile with nothing to offer, not a broken request.
60
+ */
61
+ export declare function readHostRecoveryView(patchPath: string): HostRecoveryView;
62
+ /** The outcome of putting one backup back. */
63
+ export type HostRecoveryRestoreResult = {
64
+ ok: true;
65
+ /** The snapshot taken before the write, so this is undoable from the UI. */
66
+ snapshot: string | null;
67
+ restored: {
68
+ name: string;
69
+ bytes: number;
70
+ rows: number;
71
+ };
72
+ } | {
73
+ ok: false;
74
+ error: string;
75
+ };
76
+ /**
77
+ * Put one backup back in place of the live patch.
78
+ *
79
+ * Three things happen in order, and each one is there for a reason:
80
+ *
81
+ * 1. a profile snapshot, so the restore is undoable the same way every other
82
+ * write on this page is (issue #98);
83
+ * 2. the backup's bytes are written to a temp file first, so a write that
84
+ * fails leaves the live patch where it was, and an interrupted one cannot
85
+ * leave a half patch behind, which is the one outcome that would not boot;
86
+ * 3. the live patch is RENAMED, never deleted — it is what the app is running
87
+ * with right now, and a user who restores the wrong backup must still find
88
+ * it there — and the temp file is renamed into its place. If that last
89
+ * rename fails, the live patch is moved back.
90
+ *
91
+ * The backup file itself is left where it is: it is the other copy of the
92
+ * user's configuration, and this function has no business being the last
93
+ * thing that ever held it.
94
+ */
95
+ export declare function restoreHostRecoveryBackup(patchPath: string, profileDir: string, name: string, maxSnapshots?: number): HostRecoveryRestoreResult;
@@ -0,0 +1,405 @@
1
+ /**
2
+ * Restart-free installs: mount a freshly installed plugin into the running
3
+ * composition through a market-owned Include subtree.
4
+ *
5
+ * Durable state stays with the profile's `dsh.profile.bundles` (reconciled by
6
+ * the dsh CLI at install time), so the next boot loads the plugin through the
7
+ * normal bundle layer. The subtree here exists only for the current process:
8
+ * its input files live under `<profile>/.dsh-crate/` and are wiped on every
9
+ * boot, so a crash can never leave a file that collides with the bundle layer
10
+ * (inserting an id the bundle layer also inserts is a hard boot failure).
11
+ * `state.json` in the same directory is the market's own durable state
12
+ * (disable list + custom groups) and deliberately survives the wipe.
13
+ *
14
+ * The Include subclass suppresses `write()` — the loader otherwise persists
15
+ * tree changes back to the file it read (see dsh's agent-presets PresetTree
16
+ * for the in-tree precedent).
17
+ */
18
+ import { type Channel } from './channels.ts';
19
+ import { type Region } from './regions.ts';
20
+ interface HotRow {
21
+ id: string;
22
+ name: string;
23
+ }
24
+ interface PluginHandle {
25
+ await(): Promise<unknown>;
26
+ dispose(): Promise<unknown> | void;
27
+ }
28
+ interface HotContext {
29
+ plugin(plugin: unknown, config: unknown): PluginHandle;
30
+ logger?: {
31
+ info?(message: string): void;
32
+ warn(message: string): void;
33
+ };
34
+ }
35
+ /**
36
+ * Profile-scoped resolution for hot-mount rows: turn a bare package name into
37
+ * the absolute `file://` entry URL of the package just installed into
38
+ * `profileDir`.
39
+ *
40
+ * Include-tree rows reach `Include.import` as BARE names (`name:
41
+ * '@scope/pkg'`), and the base class resolves them against the LOADER's own
42
+ * location — the host closure
43
+ * (`closures/<fp>/node_modules/…/cordis-plugin-loader`), whose parent walk
44
+ * can never reach `home/profiles/<profile>/node_modules/`. Under a host whose
45
+ * loader sits in an immutable dependency closure, EVERY market hot mount dies
46
+ * with `Cannot find module '<pkg>' from '…/cordis-plugin-loader/…'` and falls
47
+ * back to "restart required", blaming the plugin for what is a resolution
48
+ * anchor problem.
49
+ *
50
+ * Resolving the row name HERE, against the profile the package was actually
51
+ * installed into, is anchor-independent: `require.resolve` walks
52
+ * `profileDir/node_modules` natively, so the tree hands the loader a
53
+ * `file://` URL needing no further resolution. Non-bare specifiers (relative
54
+ * paths, `file://`, `cordis:` builtins) and names that do not resolve under
55
+ * the profile pass through unchanged, preserving base-class semantics for
56
+ * every shape this fix does not own.
57
+ *
58
+ * The fallback keeps the name bare rather than synthesising a URL: a package
59
+ * whose entry cannot be located via `require.resolve` (no `main`/exports —
60
+ * the market's own `entryArtifactExists` heuristic covers those shapes before
61
+ * an install is accepted) is not something this resolver should guess about.
62
+ * Client-only shims never reach this function (their rows are replaced by a
63
+ * no-op host module before the file is written).
64
+ */
65
+ export declare function resolveProfileEntry(profileDir: string, name: string): string;
66
+ /**
67
+ * Insert rows of a plugin's bundle patch, or null when the patch contains
68
+ * anything beyond plain `id`/`name` insert rows (config blocks, disables,
69
+ * expressions) — those compositions fall back to restart activation.
70
+ */
71
+ export declare function parseSimplePatch(patchText: string): HotRow[] | null;
72
+ /**
73
+ * Wipe leftover hot-mount inputs; call once when the market host starts.
74
+ * `state.json` (disable choices + groups) deliberately survives.
75
+ */
76
+ export declare function cleanHotDir(profileDir: string): void;
77
+ /** Persisted market state: the generic disable list plus custom groups. */
78
+ export interface MarketState {
79
+ /** Plugins the user switched off; replayed at every boot. */
80
+ disabled: Set<string>;
81
+ /** User-defined plugin groups: group name → member package names. */
82
+ groups: Record<string, string[]>;
83
+ /** Display order of group names; "ungrouped" is implicit and never listed. */
84
+ groupOrder: string[];
85
+ /**
86
+ * The user's own one-line note per installed plugin (#347).
87
+ *
88
+ * A catalog description answers "what is this", written by its author for
89
+ * strangers and often in a language the reader did not pick. It cannot
90
+ * answer "why did I install this" — which is the question someone with
91
+ * forty plugins is actually asking. So a note REPLACES the description on
92
+ * that row, and the original stays one click away.
93
+ *
94
+ * Local state like the disable list and the groups beside it: never sent
95
+ * anywhere, and carried by a backup because it is part of how this profile
96
+ * is set up.
97
+ *
98
+ * Optional on the way IN: several callers build a state object from the
99
+ * few fields they own and hand it to writeMarketState. Requiring this one
100
+ * would make every such call a silent way to erase every note — the exact
101
+ * shape of #339, where a partial snapshot dropped a field nobody was
102
+ * thinking about. Omitting it means "leave them alone" instead.
103
+ */
104
+ notes?: Record<string, string>;
105
+ /**
106
+ * The release channel the user PICKED, absent until they pick one.
107
+ *
108
+ * Absent is not the same as 'stable': with no choice on record the channel
109
+ * is derived from the running build, so installing a prerelease by hand
110
+ * puts you on the beta channel without a second step. Once chosen, the
111
+ * choice is the answer — including "stable" while a beta is running, which
112
+ * is how someone gets back off the channel.
113
+ */
114
+ channel?: Channel;
115
+ /**
116
+ * The download region in force, absent until something has decided one.
117
+ *
118
+ * Absent means "nobody has decided yet", which is what triggers the
119
+ * one-time network probe. Once a value is here — whether the probe wrote
120
+ * it or the user picked it — no further probing happens, so the market
121
+ * does not silently change routes between runs.
122
+ */
123
+ region?: Region;
124
+ /**
125
+ * Whether `region` was chosen by the probe rather than by the user.
126
+ *
127
+ * Only drives a one-time notice explaining why the market picked what it
128
+ * picked. A user who never learns a route was chosen for them has no way
129
+ * to know the setting exists, and no reason to look for it when something
130
+ * downloads oddly.
131
+ */
132
+ regionAuto?: boolean;
133
+ /**
134
+ * Catalog entry URLs the user bookmarked for later install (#414).
135
+ * Keys are registry `url` strings, not package names — favorites are a
136
+ * pre-install list, unlike groups/notes which target installed packages.
137
+ */
138
+ favorites?: string[];
139
+ /**
140
+ * Package names the user hid from Discover and Themes (#657).
141
+ *
142
+ * Local, per-profile, reversible. The Hidden tab lists the same names so
143
+ * the choice can be undone. Independent of `disabled` (the plugin can keep
144
+ * running) and of the session-only update ignore (that one dies on restart).
145
+ * A stored name may be the installed package name or the catalog package
146
+ * name; the client treats both as one plugin when it can match them.
147
+ *
148
+ * Optional on the way in, like `notes` / `favorites`: several callers
149
+ * build a state object from the few fields they own, and requiring this
150
+ * one would make every such call a silent way to erase the list (#339).
151
+ */
152
+ blocked?: string[];
153
+ /**
154
+ * Installed package names the user asked not to be reminded about (#728).
155
+ *
156
+ * This is not {@link blocked}. Hiding a plugin takes it off Discover.
157
+ * This list leaves the plugin where it is, and leaves the update itself
158
+ * on the installed row. It only stops the reminder: the badge, the
159
+ * "update all" count, the sort-to-top, and the reminder bar. A new
160
+ * version is still listed, and the row's own Update button still works.
161
+ *
162
+ * Optional on the way in, for the same reason as `blocked` (#339).
163
+ * An empty array is how the last name is removed.
164
+ */
165
+ updateExempt?: string[];
166
+ /** User-supplied HTTPS prefix used when the built-in GitHub routes fail. */
167
+ githubProxy?: string;
168
+ /**
169
+ * Whether the market also opens from its own row in the sidebar (#846).
170
+ *
171
+ * Off unless the user turned it on: the sidebar's global rows are the
172
+ * host's own pages, and installing plugins is occasional, so a row nobody
173
+ * asked for would be a permanent fixture for an occasional task. The page
174
+ * entries are the defaults, and the last-door rule (#1015) — enforced by
175
+ * the route — is what keeps turning this off from leaving the market
176
+ * unreachable.
177
+ *
178
+ * Omission preserves, an explicit value wins — the githubProxy contract,
179
+ * because turning it off has to be expressible.
180
+ */
181
+ sidebarEntry?: boolean;
182
+ /**
183
+ * Whether the market still lists its own page in Settings (#1015).
184
+ *
185
+ * Absent means shown. Only an explicit `false` is stored, unlike
186
+ * `sidebarEntry`: this entry has always been on, and every host before
187
+ * 0.2.1 offers it as the only door, so an absent field is the ordinary
188
+ * case rather than an unanswered question. Turning it back on clears the
189
+ * field so a later default change still reaches users who never touched it.
190
+ */
191
+ settingsSection?: boolean;
192
+ /**
193
+ * Whether the market still adds its tab to the host's Plugins page
194
+ * (#1015). Absent means shown, on the same contract as
195
+ * {@link settingsSection}.
196
+ *
197
+ * A host that never declares the slot has no tab to hide; the saved
198
+ * answer is kept for the hosts that do.
199
+ */
200
+ pluginsTab?: boolean;
201
+ /**
202
+ * Packages the market removed from the profile's own declarations because
203
+ * the build on disk can no longer compose (#663).
204
+ *
205
+ * The case this exists for: an update blocked by open files leaves the
206
+ * target directory incomplete, `keepLockedBuild` cannot keep the previous
207
+ * build, and the profile goes on declaring a package whose `package.json`
208
+ * is missing. The next start dies in composition — on Desktop the window
209
+ * never opens — and the only way out was uninstalling the plugin by hand.
210
+ * So the declaration is dropped instead (a rename or a delete of the
211
+ * directory itself cannot be attempted: the same lock that stopped pnpm
212
+ * refuses the market's move too), and this map is what keeps that from
213
+ * being silent. The plugin disappears from the installed list; this is the
214
+ * record saying why, and what spec to reinstall.
215
+ *
216
+ * Optional on the way in, like `notes`: several callers write a state
217
+ * object built from the few fields they own, and requiring this one would
218
+ * make every such call a way to erase every entry (#339's shape).
219
+ */
220
+ brokenPlugins?: Record<string, BrokenPlugin>;
221
+ /**
222
+ * The operator's pinned build environment (issue #336) as saved from the
223
+ * market's own settings card. Absent means "the composition says" — the
224
+ * entry's `config.buildEnv`, or nothing at all. Present (non-empty) means
225
+ * a saved editor state REPLACES the composition map, so clearing the
226
+ * field on the card inherits the composition again rather than freezing
227
+ * an earlier save. Read live into `config.buildEnv` by the routes; see
228
+ * src/dsh-cli.ts spawnEnv for the precedence once it reaches a child.
229
+ */
230
+ buildEnv?: Record<string, string>;
231
+ }
232
+ /** Why a package is no longer declared, and what to put back. */
233
+ export interface BrokenPlugin {
234
+ /** The dependency spec it had before removal — the reinstall target. */
235
+ spec: string;
236
+ /**
237
+ * Machine-readable cause; the UI owns the wording. `locked`: pnpm reported
238
+ * the open-file refusal. `cancelled`: the user cancelled while pnpm was
239
+ * replacing the directory — the result is the same empty shell, but no cause
240
+ * was observed, so the notice must not name one (#663).
241
+ */
242
+ reason: BrokenReason;
243
+ /** When the market removed the declaration (ISO 8601). */
244
+ at: string;
245
+ }
246
+ export type BrokenReason = 'incomplete-build-locked' | 'incomplete-build-cancelled';
247
+ /** Upper bound on bookmarked catalog URLs kept in state.json (#414). */
248
+ export declare const MAX_FAVORITES = 500;
249
+ /** Upper bound on blocked package names kept in state.json (#657). */
250
+ export declare const MAX_BLOCKED = 500;
251
+ /** Upper bound on the persistent do-not-remind list (#728). */
252
+ export declare const MAX_UPDATE_EXEMPT = 500;
253
+ /** npm package names are at most 214 characters. Longer values are not names. */
254
+ export declare const MAX_BLOCKED_NAME = 214;
255
+ /**
256
+ * Sanitize an untrusted build-env map (state.json, or the card route's body)
257
+ * into the shape spawnEnv can merge.
258
+ *
259
+ * An empty map and a non-object both read as undefined: clearing the card
260
+ * must inherit the composition, and a blank line in state.json must not
261
+ * disable every pinned variable. Only the merge precedence in
262
+ * src/dsh-cli.ts spawnEnv — never this — protects PATH and CI, but a value
263
+ * a user typed for them would silently do nothing there, so it is rejected
264
+ * here with a reason instead.
265
+ *
266
+ * `GIT_ASKPASS` and `SSH_ASKPASS` are deliberately NOT rejected, though they
267
+ * are the two names that can re-open a credential prompt: pointing them at a
268
+ * program is the supported non-interactive way to answer one, and #587/#596
269
+ * close the *terminal* fallback (GIT_TERMINAL_PROMPT, BatchMode) rather than
270
+ * the program one. A user who pins these has already said where the answer
271
+ * comes from; a user who does not still gets the closed prompt.
272
+ */
273
+ export declare function buildEnvFromUnknown(value: unknown): Record<string, string> | undefined;
274
+ /**
275
+ * Read the whole market state. Legacy `disabledSkins` (the pre-#60
276
+ * theme-only key) still loads; every new write uses the generic `disabled`
277
+ * key (#60).
278
+ */
279
+ /** A note is a label, not a document: one line, bounded so state.json cannot
280
+ * grow without limit from a paste. */
281
+ export declare const MAX_NOTE = 200;
282
+ export declare function readMarketState(profileDir: string): MarketState;
283
+ /**
284
+ * Persist the whole market state.
285
+ *
286
+ * Every field a caller does not carry forward is taken from disk rather than
287
+ * dropped. Several callers legitimately know about only one part of the
288
+ * state — `writeMarketState(dir, { disabled, groups, groupOrder })` appears
289
+ * at five call sites in routes.ts — and before #435 that shape silently
290
+ * erased whatever else the user had chosen:
291
+ *
292
+ * - `channel` and `region` had no fallback at all, so toggling any plugin
293
+ * threw away the user's update channel and download region. Both are
294
+ * deliberate choices made through the settings card, and neither has a
295
+ * "clear it" path: once picked they only ever move to another value. So
296
+ * an absent one always means "the caller has nothing to say", never
297
+ * "the user unchose it".
298
+ * `notes` keeps its original rule — an explicit object wins, including an
299
+ * empty one, because deleting the last note has to be expressible. What made
300
+ * #435 lose notes was not this function but a caller: the note route wrote
301
+ * through a fresh read while the long-lived `marketState` in routes.ts still
302
+ * carried `notes: {}` from boot, and the next write from that object put the
303
+ * empty one back. The fix for that belongs at the call site, where the two
304
+ * copies are, not here — see the note route.
305
+ *
306
+ * Reading before writing costs one small JSON parse on an operation that is
307
+ * already doing filesystem work, and it is what makes "this function writes
308
+ * the whole document" safe for callers that only hold part of it.
309
+ */
310
+ export declare function writeMarketState(profileDir: string, state: MarketState): void;
311
+ /** Plugins the user switched off; skipped by the boot re-mount. */
312
+ export declare function readDisabled(profileDir: string): Set<string>;
313
+ /** Persist just the disable list, preserving groups and order. */
314
+ export declare function writeDisabled(profileDir: string, disabled: Set<string>): void;
315
+ /** @deprecated theme-specific alias — kept for pre-#60 callers. */
316
+ export declare function readDisabledThemes(profileDir: string): Set<string>;
317
+ /** @deprecated theme-specific alias — kept for pre-#60 callers. */
318
+ export declare function writeDisabledThemes(profileDir: string, disabled: Set<string>): void;
319
+ /** Package names currently live through a market hot mount (patch or shim). */
320
+ export declare function listHotMounts(): string[];
321
+ /** Outcome of one hot-mount attempt; `reason` explains non-`ok` results. */
322
+ export interface HotMountResult {
323
+ ok: boolean;
324
+ /** Bilingual reason shown to the user instead of a bare restart banner. */
325
+ reason: string | null;
326
+ /**
327
+ * Set when nothing was attempted because this package can only come up on a
328
+ * start — its patch holds more than plain inserts. That is a verdict about
329
+ * the package, not a mount that crashed: the durable switch can still be
330
+ * written, where a crash must not be persisted (#575, #1010).
331
+ */
332
+ deferred?: true;
333
+ }
334
+ /**
335
+ * Dispose a plugin hot-mounted earlier in this session, removing it from the
336
+ * running composition immediately.
337
+ * @param packageName - package to unmount.
338
+ * @returns true when a live hot mount was found and disposed.
339
+ */
340
+ export declare function hotUnmount(packageName: string): Promise<boolean>;
341
+ /**
342
+ * Mount `packageName` (just installed into the profile) into the running
343
+ * composition.
344
+ * @param ctx - market host context; the subtree unwinds with the market's fiber.
345
+ * @param profileDir - profile the package was installed into.
346
+ * @param packageName - installed package to activate.
347
+ * @returns whether the plugin is live without a restart, plus the reason
348
+ * when it is not (P0-2: the UI must distinguish "restart will fix it" from
349
+ * "this package can never hot-mount").
350
+ */
351
+ export declare function hotMount(ctx: HotContext, profileDir: string, packageName: string): Promise<HotMountResult>;
352
+ /**
353
+ * Mount every installed client-only package (`dsh.client` without
354
+ * `dsh.bundle`) at market startup. The bundle reconcile skips these packages
355
+ * entirely, so without the market's shim their client bundles are unreachable
356
+ * in every boot — this is what makes them behave like normal plugins.
357
+ * @returns names that were mounted.
358
+ */
359
+ export declare function mountClientOnlyDeps(ctx: HotContext, profileDir: string): Promise<string[]>;
360
+ /**
361
+ * Package names the profile's OWN bundle layer already mounts.
362
+ *
363
+ * The shim predicate reads the profile manifest, so it can only see a package
364
+ * as a dependency; it cannot see that an in-box bundle mounts the same package
365
+ * under a row id of its own — `@deepseek-ai/dsh-web-app` ships
366
+ * `- id: connection` / `name: '@deepseek-ai/dsh-client-connection'` (#1137).
367
+ * Those packages also declare `dsh.client` and no `dsh.bundle`, so every
368
+ * existing predicate says "shim it". Only the row NAMES link the two, and a
369
+ * clean profile's bundles are the only place they are written down.
370
+ *
371
+ * A bundle whose declaration cannot be read contributes nothing, which keeps
372
+ * today's behaviour (shim, possibly duplicated) rather than silently dropping
373
+ * a client bundle that the bundle layer never mounts.
374
+ */
375
+ export declare function bundleLayerTargets(profileDir: string, bundles: Iterable<string>): Set<string>;
376
+ /**
377
+ * Row ids and package names the user's own patch layer (cordis.patch.yml)
378
+ * already contains. Line-wise scan on purpose: the file may hold structures
379
+ * the market's strict patch parser rejects, but any mention of a row id or
380
+ * package name is enough to know the user manages it (#58).
381
+ */
382
+ export declare function readUserPatchControls(profileDir: string): {
383
+ ids: Set<string>;
384
+ names: Set<string>;
385
+ };
386
+ /**
387
+ * Whether the user patch layer manages `name` — matched by exact package
388
+ * name or by the plugin-manager row-id convention (strip the leading @,
389
+ * non-alphanumerics to '-', lowercase).
390
+ */
391
+ export declare function patchLayerManages(controls: {
392
+ ids: Set<string>;
393
+ names: Set<string>;
394
+ }, name: string): boolean;
395
+ /**
396
+ * Delete the market's own state directory.
397
+ *
398
+ * `cleanHotDir` wipes the ephemeral hot-mount inputs on every boot but
399
+ * deliberately preserves `state.json` — the disable list and custom groups
400
+ * are the user's durable choices. Uninstalling the market is the one moment
401
+ * where removing them is the right thing, and only when the user asked.
402
+ * @returns true when a directory was there to remove.
403
+ */
404
+ export declare function purgeMarketState(profileDir: string): boolean;
405
+ export {};