dsh-agent-team-presets 0.3.0 → 0.3.2

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.
@@ -19017,7 +19017,9 @@ const dsh_agent_team_presets_teamPresets_cardPatches_result$schema = () => dsh_a
19017
19017
  "id": string$1().readonly().describe("Stable identity."),
19018
19018
  "packageName": string$1().readonly().describe("Package the row is about."),
19019
19019
  "source": string$1().readonly().describe("Upstream revision the prebuilt replacement came from."),
19020
- "supportedVersion": string$1().readonly().describe("The version this build ships a replacement for."),
19020
+ "service": string$1().readonly().describe("Service a patched target registers; the page reads it to tell \"active\" from \"installed\"."),
19021
+ "supportedVersion": string$1().readonly().describe("The version whose replacement applies to this row (the newest supported one when none matches)."),
19022
+ "supportedVersions": array(string$1()).readonly().describe("Every upstream version this build ships a replacement for."),
19021
19023
  "installedVersion": string$1().readonly().optional().describe("Installed version, when the package is present."),
19022
19024
  "state": union([
19023
19025
  literal("absent"),
@@ -19825,9 +19827,18 @@ const TYPERT_REMOTE = createTypertRemoteInfo({
19825
19827
  "type": "string",
19826
19828
  "description": "Upstream revision the prebuilt replacement came from."
19827
19829
  },
19830
+ "service": {
19831
+ "type": "string",
19832
+ "description": "Service a patched target registers; the page reads it to tell \"active\" from \"installed\"."
19833
+ },
19828
19834
  "supportedVersion": {
19829
19835
  "type": "string",
19830
- "description": "The version this build ships a replacement for."
19836
+ "description": "The version whose replacement applies to this row (the newest supported one when none matches)."
19837
+ },
19838
+ "supportedVersions": {
19839
+ "type": "array",
19840
+ "items": { "type": "string" },
19841
+ "description": "Every upstream version this build ships a replacement for."
19831
19842
  },
19832
19843
  "installedVersion": {
19833
19844
  "type": "string",
@@ -19853,7 +19864,9 @@ const TYPERT_REMOTE = createTypertRemoteInfo({
19853
19864
  "id",
19854
19865
  "packageName",
19855
19866
  "source",
19867
+ "service",
19856
19868
  "supportedVersion",
19869
+ "supportedVersions",
19857
19870
  "state"
19858
19871
  ],
19859
19872
  "additionalProperties": true
@@ -20061,7 +20074,7 @@ const TYPERT_REMOTE = createTypertRemoteInfo({
20061
20074
  },
20062
20075
  sourceLocation: {
20063
20076
  "file": "packages/experimental/agent-team-presets/src/tool-catalog.ts",
20064
- "line": 272,
20077
+ "line": 274,
20065
20078
  "column": 9
20066
20079
  }
20067
20080
  },
@@ -139,7 +139,7 @@ Team Skill 排查:
139
139
 
140
140
  ## 9. 安装 / 升级 / 版本
141
141
 
142
- - 本版本要求 DSH >=0.2.2-rc.1 <0.3.0;旧宿主请保留 0.1.8。安装前核对 engines.dsh。
142
+ - 本版本要求 DSH >=0.2.2-rc.3 <0.3.0;更旧的宿主请保留 0.1.8。安装前核对 engines.dsh。
143
143
  - 通过官方插件管理器安装/升级;仓库包含预构建产物,通常无需构建。
144
144
  - 安装失败时不要只看版本号:核对 application 结果、warnings、保存的 package source、已安装文件哈希、是否需要重启。
145
145
  - 失败的安装可能让 node_modules 比保存的依赖规格更新;这是未完成状态,不要据此宣称升级成功。解决包管理器策略后重试,并再次核对保存的 source 与运行版本。
@@ -113,6 +113,20 @@ export interface BuiltinSeedResult {
113
113
  * @returns the next Team list, the next marker, and whether either changed.
114
114
  */
115
115
  export declare function seedBuiltinTeams(teams: readonly TeamPreset[], seeded: readonly string[]): BuiltinSeedResult;
116
+ /**
117
+ * The shipped presets a deployment was offered but no longer holds.
118
+ *
119
+ * The marker exists so a deleted preset stays deleted, which also means a Team
120
+ * list that lost its shipped presets for any other reason — a hand edit, a
121
+ * restored settings file, a rollback — never gets them back on its own. This
122
+ * reads that state instead of changing it: the caller warns, and the reader can
123
+ * decide to restore. A preset the deployment was never offered is not reported,
124
+ * because the install pass will add it on this same startup.
125
+ * @param teams - the stored Team list.
126
+ * @param seeded - identities the deployment was already offered.
127
+ * @returns the shipped identities that are marked as offered yet absent.
128
+ */
129
+ export declare function missingSeededBuiltinTeams(teams: readonly TeamPreset[], seeded: readonly string[]): string[];
116
130
  /**
117
131
  * Whether two metadata objects are equal field by field.
118
132
  * @param a - left metadata, or undefined.
@@ -146,6 +146,24 @@ export function seedBuiltinTeams(teams, seeded) {
146
146
  changed: install.length > 0 || mark.length > 0,
147
147
  };
148
148
  }
149
+ /**
150
+ * The shipped presets a deployment was offered but no longer holds.
151
+ *
152
+ * The marker exists so a deleted preset stays deleted, which also means a Team
153
+ * list that lost its shipped presets for any other reason — a hand edit, a
154
+ * restored settings file, a rollback — never gets them back on its own. This
155
+ * reads that state instead of changing it: the caller warns, and the reader can
156
+ * decide to restore. A preset the deployment was never offered is not reported,
157
+ * because the install pass will add it on this same startup.
158
+ * @param teams - the stored Team list.
159
+ * @param seeded - identities the deployment was already offered.
160
+ * @returns the shipped identities that are marked as offered yet absent.
161
+ */
162
+ export function missingSeededBuiltinTeams(teams, seeded) {
163
+ const held = new Set(teams.map(team => team.id));
164
+ const known = new Set(seeded);
165
+ return BUILTIN_TEAMS.filter(entry => known.has(entry.id) && !held.has(entry.id)).map(entry => entry.id);
166
+ }
149
167
  /**
150
168
  * Whether two slots carry the same stored fields.
151
169
  * @param a - left slot.
@@ -45,13 +45,55 @@ export interface CardPatchTarget {
45
45
  /** sha256 of the prebuilt replacement; the only state one may restore from. */
46
46
  readonly patchedSha256: string;
47
47
  }
48
+ /** Version of the shipped catalog overlay document; a different one is ignored. */
49
+ export declare const CARD_PATCH_CATALOG_VERSION = 1;
48
50
  /**
49
- * The supported targets.
51
+ * Validate one overlay entry.
50
52
  *
51
- * Each entry is fixed to one upstream version on purpose: the replacement is a
52
- * whole-bundle build, so a different version's bundle would silently change
53
- * behaviour that was never reviewed here.
53
+ * The overlay is data, not code, so it may be edited by hand or written by an
54
+ * older tool; every field is checked against the same shape the compiled
55
+ * entries use. An entry that fails is a reason to ignore the whole document,
56
+ * because acting on part of it would make "what does this build support"
57
+ * depend on JSON key order.
58
+ * @param candidate - one parsed entry.
59
+ * @returns the normalized target.
60
+ * @throws when any field is unusable.
54
61
  */
62
+ export declare function normalizeCatalogTarget(candidate: unknown): CardPatchTarget;
63
+ /**
64
+ * Parse a shipped catalog overlay document.
65
+ * @param text - the document text.
66
+ * @returns every entry it declares.
67
+ * @throws when the document or any entry is unusable.
68
+ */
69
+ export declare function parseCardPatchCatalog(text: string): readonly CardPatchTarget[];
70
+ /**
71
+ * Combine the compiled baseline with the shipped overlay.
72
+ *
73
+ * Entries are keyed by identity *and* version, not by identity alone: keeping
74
+ * the already-supported versions is the whole point of shipping a replacement
75
+ * per version, so rebuilding 0.84.1 must not drop 0.84.0 for the installations
76
+ * still on it. Only the exact pair is replaced when the same version is rebuilt.
77
+ * Compiled order is kept, because that is the order the settings page lists.
78
+ * @param baseline - entries compiled into this build.
79
+ * @param overlay - entries read from the shipped catalog.
80
+ * @returns the merged catalog.
81
+ */
82
+ export declare function mergeCatalogTargets(baseline: readonly CardPatchTarget[], overlay: readonly CardPatchTarget[]): readonly CardPatchTarget[];
83
+ /**
84
+ * The distinct target identities, in catalog order.
85
+ * @param targets - the catalog to read.
86
+ * @returns one identity per target, first occurrence order.
87
+ */
88
+ export declare function catalogIdentities(targets?: readonly CardPatchTarget[]): readonly string[];
89
+ /**
90
+ * Every catalog entry for one identity.
91
+ * @param id - the target identity.
92
+ * @param targets - the catalog to read.
93
+ * @returns its entries, oldest build first.
94
+ */
95
+ export declare function catalogTargetsFor(id: string, targets?: readonly CardPatchTarget[]): readonly CardPatchTarget[];
96
+ /** Every version this build can patch: the compiled baseline plus the overlay. */
55
97
  export declare const CARD_PATCH_TARGETS: readonly CardPatchTarget[];
56
98
  /**
57
99
  * The file-system facts one patch operation depends on.
@@ -102,3 +144,28 @@ export declare function uninstallCardPatch(target: CardPatchTarget, env?: CardPa
102
144
  * @returns the entry, or undefined for an id this build does not ship.
103
145
  */
104
146
  export declare function findCardPatchTarget(id: string): CardPatchTarget | undefined;
147
+ /**
148
+ * Classify one identity by the version that is actually installed.
149
+ *
150
+ * Several catalog entries may exist for the same target, one per supported
151
+ * upstream version; which one is relevant depends entirely on the installed
152
+ * package, so the choice belongs here rather than at each call site. A version
153
+ * this build has no replacement for reports `unsupported` and names the
154
+ * versions it does ship, which is what tells an operator whether to update the
155
+ * target plugin or this one.
156
+ * @param entries - every catalog entry for one identity, oldest first.
157
+ * @param env - the file-system facts to read through.
158
+ * @returns the row the settings page renders.
159
+ */
160
+ export declare function resolveTargetView(entries: readonly CardPatchTarget[], env?: CardPatchEnvironment): CardPatchTargetView;
161
+ /**
162
+ * Resolve the catalog entry that matches the installed version of one target.
163
+ * @param id - the target identity.
164
+ * @param env - the file-system facts to read through.
165
+ * @param targets - the catalog to read.
166
+ * @returns the entry to patch, when this build has one for that exact version.
167
+ */
168
+ export declare function resolveInstalledTarget(id: string, env?: CardPatchEnvironment, targets?: readonly CardPatchTarget[]): {
169
+ target?: CardPatchTarget;
170
+ view: CardPatchTargetView;
171
+ };
@@ -28,13 +28,15 @@ import { dirname, join } from 'node:path';
28
28
  import { fileURLToPath } from 'node:url';
29
29
  import { gunzipSync } from 'node:zlib';
30
30
  /**
31
- * The supported targets.
31
+ * The versions compiled into this build.
32
32
  *
33
- * Each entry is fixed to one upstream version on purpose: the replacement is a
34
- * whole-bundle build, so a different version's bundle would silently change
35
- * behaviour that was never reviewed here.
33
+ * Each entry is a finished artifact: the replacement is a whole-bundle build, so
34
+ * a different version's bundle would silently change behaviour that was never
35
+ * reviewed here. Newer versions are added by `tools/card-patches.mjs`, which
36
+ * verifies the rebuild first and then writes them to the shipped catalog
37
+ * overlay; nothing here needs to change for that.
36
38
  */
37
- export const CARD_PATCH_TARGETS = [
39
+ const COMPILED_TARGETS = [
38
40
  {
39
41
  id: 'dsh-context',
40
42
  packageName: 'dsh-context',
@@ -56,6 +58,141 @@ export const CARD_PATCH_TARGETS = [
56
58
  patchedSha256: 'd0a9f0257e80fb3fdf6eb06a587b5b5aa985e1cfbaaf7a187ee381da0a8ac7ba',
57
59
  },
58
60
  ];
61
+ /** Version of the shipped catalog overlay document; a different one is ignored. */
62
+ export const CARD_PATCH_CATALOG_VERSION = 1;
63
+ /** The shipped overlay: entries a build produced for versions this code predates. */
64
+ function shippedCatalogFile() {
65
+ return join(shippedAssets(), 'catalog.json');
66
+ }
67
+ /** One validated overlay entry, or a message naming what is wrong with it. */
68
+ function catalogString(row, field, pattern, hint) {
69
+ const value = row[field];
70
+ if (typeof value !== 'string' || !pattern.test(value)) {
71
+ throw new Error(`${field} ${hint}: ${JSON.stringify(value)}`);
72
+ }
73
+ return value;
74
+ }
75
+ /**
76
+ * Validate one overlay entry.
77
+ *
78
+ * The overlay is data, not code, so it may be edited by hand or written by an
79
+ * older tool; every field is checked against the same shape the compiled
80
+ * entries use. An entry that fails is a reason to ignore the whole document,
81
+ * because acting on part of it would make "what does this build support"
82
+ * depend on JSON key order.
83
+ * @param candidate - one parsed entry.
84
+ * @returns the normalized target.
85
+ * @throws when any field is unusable.
86
+ */
87
+ export function normalizeCatalogTarget(candidate) {
88
+ if (candidate === null || typeof candidate !== 'object' || Array.isArray(candidate)) {
89
+ throw new Error('the entry is not an object');
90
+ }
91
+ const row = candidate;
92
+ const pristineSha256 = catalogString(row, 'pristineSha256', /^[0-9a-f]{64}$/, 'must be 64 lowercase hex characters');
93
+ const patchedSha256 = catalogString(row, 'patchedSha256', /^[0-9a-f]{64}$/, 'must be 64 lowercase hex characters');
94
+ if (pristineSha256 === patchedSha256) {
95
+ throw new Error('pristineSha256 and patchedSha256 must differ, or the replacement would be the published build');
96
+ }
97
+ const source = row['source'];
98
+ if (typeof source !== 'string' || source.trim() === '' || /\s/.test(source)) {
99
+ throw new Error(`source must be one non-empty token: ${JSON.stringify(source)}`);
100
+ }
101
+ return {
102
+ id: catalogString(row, 'id', /^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'must be lowercase words joined by hyphens'),
103
+ packageName: catalogString(row, 'packageName', /^[a-z0-9][a-z0-9._-]*$/, 'must be a bare package name'),
104
+ version: catalogString(row, 'version', /^\d+\.\d+\.\d+(?:-[0-9A-Za-z]+(?:\.[0-9A-Za-z]+)*)?$/, 'must be a semver version'),
105
+ source,
106
+ asset: catalogString(row, 'asset', /^[a-z0-9][a-z0-9._-]*\.client\.js\.gz$/, 'must be a bare `<name>.client.js.gz` file name'),
107
+ service: catalogString(row, 'service', /^[A-Za-z_$][A-Za-z0-9_$]*$/, 'must be a JavaScript identifier'),
108
+ pristineSha256,
109
+ patchedSha256,
110
+ };
111
+ }
112
+ /**
113
+ * Parse a shipped catalog overlay document.
114
+ * @param text - the document text.
115
+ * @returns every entry it declares.
116
+ * @throws when the document or any entry is unusable.
117
+ */
118
+ export function parseCardPatchCatalog(text) {
119
+ const document = JSON.parse(text);
120
+ if (document === null || typeof document !== 'object' || Array.isArray(document)) {
121
+ throw new Error('the catalog is not an object');
122
+ }
123
+ const version = document.version;
124
+ if (version !== CARD_PATCH_CATALOG_VERSION) {
125
+ throw new Error(`the catalog version is ${JSON.stringify(version)}, not ${CARD_PATCH_CATALOG_VERSION}`);
126
+ }
127
+ const targets = document.targets;
128
+ if (!Array.isArray(targets))
129
+ throw new Error('the catalog has no targets array');
130
+ return targets.map(normalizeCatalogTarget);
131
+ }
132
+ /**
133
+ * Combine the compiled baseline with the shipped overlay.
134
+ *
135
+ * Entries are keyed by identity *and* version, not by identity alone: keeping
136
+ * the already-supported versions is the whole point of shipping a replacement
137
+ * per version, so rebuilding 0.84.1 must not drop 0.84.0 for the installations
138
+ * still on it. Only the exact pair is replaced when the same version is rebuilt.
139
+ * Compiled order is kept, because that is the order the settings page lists.
140
+ * @param baseline - entries compiled into this build.
141
+ * @param overlay - entries read from the shipped catalog.
142
+ * @returns the merged catalog.
143
+ */
144
+ export function mergeCatalogTargets(baseline, overlay) {
145
+ const key = (entry) => `${entry.id}@${entry.version}`;
146
+ const byKey = new Map(overlay.map(entry => [key(entry), entry]));
147
+ const merged = baseline.map(entry => byKey.get(key(entry)) ?? entry);
148
+ // Numeric collation, so appending 0.9.0 after 0.10.0 is impossible: "newest
149
+ // last" is what the settings row and the resolver rely on.
150
+ const order = { numeric: true };
151
+ for (const [entryKey, entry] of [...byKey].sort(([left], [right]) => left.localeCompare(right, 'en', order))) {
152
+ if (!baseline.some(current => key(current) === entryKey))
153
+ merged.push(entry);
154
+ }
155
+ return merged;
156
+ }
157
+ /**
158
+ * The distinct target identities, in catalog order.
159
+ * @param targets - the catalog to read.
160
+ * @returns one identity per target, first occurrence order.
161
+ */
162
+ export function catalogIdentities(targets = CARD_PATCH_TARGETS) {
163
+ return [...new Set(targets.map(target => target.id))];
164
+ }
165
+ /**
166
+ * Every catalog entry for one identity.
167
+ * @param id - the target identity.
168
+ * @param targets - the catalog to read.
169
+ * @returns its entries, oldest build first.
170
+ */
171
+ export function catalogTargetsFor(id, targets = CARD_PATCH_TARGETS) {
172
+ return targets.filter(target => target.id === id);
173
+ }
174
+ /**
175
+ * Read the shipped overlay, or nothing when it is absent or unusable.
176
+ *
177
+ * A broken overlay must not take the whole settings page down: it is optional
178
+ * data, so a refusal here falls back to the versions compiled into this build
179
+ * and says so in the log.
180
+ * @returns the overlay entries.
181
+ */
182
+ function readShippedCatalog() {
183
+ const file = shippedCatalogFile();
184
+ if (!existsSync(file))
185
+ return [];
186
+ try {
187
+ return parseCardPatchCatalog(readFileSync(file, 'utf8'));
188
+ }
189
+ catch (error) {
190
+ console.warn(`[team-presets] ignoring the shipped card-patch catalog: ${error instanceof Error ? error.message : String(error)}`);
191
+ return [];
192
+ }
193
+ }
194
+ /** Every version this build can patch: the compiled baseline plus the overlay. */
195
+ export const CARD_PATCH_TARGETS = mergeCatalogTargets(COMPILED_TARGETS, readShippedCatalog());
59
196
  /** Directory holding the prebuilt replacements shipped with this package. */
60
197
  function shippedAssets() {
61
198
  // Built output lives in `lib/`, one level below the package root.
@@ -133,7 +270,9 @@ export function targetState(target, env = realCardPatchEnvironment) {
133
270
  id: target.id,
134
271
  packageName: target.packageName,
135
272
  source: target.source,
273
+ service: target.service,
136
274
  supportedVersion: target.version,
275
+ supportedVersions: [target.version],
137
276
  };
138
277
  const directory = env.resolvePackage(target.packageName);
139
278
  if (directory === undefined) {
@@ -271,5 +410,82 @@ export function uninstallCardPatch(target, env = realCardPatchEnvironment) {
271
410
  * @returns the entry, or undefined for an id this build does not ship.
272
411
  */
273
412
  export function findCardPatchTarget(id) {
274
- return CARD_PATCH_TARGETS.find(target => target.id === id);
413
+ // The catalog appends in build order, so the last entry for an identity is the
414
+ // newest version this build can patch.
415
+ return catalogTargetsFor(id).at(-1);
416
+ }
417
+ /**
418
+ * Classify one identity by the version that is actually installed.
419
+ *
420
+ * Several catalog entries may exist for the same target, one per supported
421
+ * upstream version; which one is relevant depends entirely on the installed
422
+ * package, so the choice belongs here rather than at each call site. A version
423
+ * this build has no replacement for reports `unsupported` and names the
424
+ * versions it does ship, which is what tells an operator whether to update the
425
+ * target plugin or this one.
426
+ * @param entries - every catalog entry for one identity, oldest first.
427
+ * @param env - the file-system facts to read through.
428
+ * @returns the row the settings page renders.
429
+ */
430
+ export function resolveTargetView(entries, env = realCardPatchEnvironment) {
431
+ const newest = entries.at(-1);
432
+ if (newest === undefined)
433
+ throw new Error('a card-patch target needs at least one catalog entry');
434
+ const supportedVersions = entries.map(entry => entry.version);
435
+ const base = {
436
+ id: newest.id,
437
+ packageName: newest.packageName,
438
+ source: newest.source,
439
+ service: newest.service,
440
+ supportedVersion: newest.version,
441
+ supportedVersions,
442
+ };
443
+ const directory = env.resolvePackage(newest.packageName);
444
+ if (directory === undefined) {
445
+ return { ...base, state: 'absent', detail: 'this plugin is not installed in the running profile' };
446
+ }
447
+ const installed = installedVersion(directory);
448
+ if (installed === undefined) {
449
+ return { ...base, state: 'absent', detail: 'its package.json could not be read' };
450
+ }
451
+ const target = entries.find(entry => entry.version === installed);
452
+ if (target === undefined) {
453
+ return {
454
+ ...base,
455
+ installedVersion: installed,
456
+ state: 'unsupported',
457
+ detail: `this build ships a replacement for ${supportedVersions.join(', ')}, not ${installed}`,
458
+ };
459
+ }
460
+ return { ...targetState(target, env), supportedVersions };
461
+ }
462
+ /**
463
+ * Resolve the catalog entry that matches the installed version of one target.
464
+ * @param id - the target identity.
465
+ * @param env - the file-system facts to read through.
466
+ * @param targets - the catalog to read.
467
+ * @returns the entry to patch, when this build has one for that exact version.
468
+ */
469
+ export function resolveInstalledTarget(id, env = realCardPatchEnvironment, targets = CARD_PATCH_TARGETS) {
470
+ const entries = catalogTargetsFor(id, targets);
471
+ if (entries.length === 0) {
472
+ const absent = {
473
+ id,
474
+ packageName: id,
475
+ source: 'unknown',
476
+ service: id,
477
+ supportedVersion: '',
478
+ supportedVersions: [],
479
+ state: 'absent',
480
+ detail: `this build ships no card patch for "${id}"`,
481
+ };
482
+ return { view: absent };
483
+ }
484
+ const view = resolveTargetView(entries, env);
485
+ if (view.state === 'absent' || view.state === 'unsupported')
486
+ return { view };
487
+ const target = entries.find(entry => entry.version === view.supportedVersion);
488
+ // `exactOptionalPropertyTypes` forbids assigning `undefined` to an optional
489
+ // property, so the "no matching entry" case is its own return.
490
+ return target === undefined ? { view } : { target, view };
275
491
  }
@@ -54,6 +54,18 @@ function ResultLine({ result, t }) {
54
54
  : t('patchRefused');
55
55
  return (_jsxs("p", { className: result.ok ? css.result : css.resultFailed, role: "status", children: [text, result.detail === undefined ? null : _jsxs("span", { className: css.detail, children: [" \u2014 ", result.detail] })] }));
56
56
  }
57
+ /**
58
+ * The versions a row can patch, as text.
59
+ *
60
+ * A Host that predates the multi-version catalog sends no `supportedVersions`,
61
+ * and the page must still render the single version it does report: the client
62
+ * bundle reloads on its own while the Host only changes on restart.
63
+ * @param target - the row.
64
+ * @returns the versions, comma separated.
65
+ */
66
+ function versionsOf(target) {
67
+ return (target.supportedVersions ?? [target.supportedVersion]).join(', ');
68
+ }
57
69
  /**
58
70
  * Render one target with its state and the action that state allows.
59
71
  * @param props - the row facts and the action callback.
@@ -68,7 +80,7 @@ function Row({ target, live, busy, phase, t, onAct }) {
68
80
  // A patched bundle that has not been served yet is the one case where the row
69
81
  // must say "restart", because nothing is wrong with the file itself.
70
82
  const waiting = target.state === 'patched' && !live;
71
- return (_jsxs("li", { className: css.row, children: [_jsxs("div", { className: css.rowHead, children: [_jsx("code", { className: css.packageName, children: target.packageName }), _jsx("span", { className: css.badge, "data-state": target.state, children: t(STATE_KEYS[target.state]) }), target.state === 'patched' && live ? _jsx("span", { className: css.live, children: t('patchActive') }) : null] }), _jsxs("dl", { className: css.meta, children: [_jsx("dt", { children: t('patchSupported') }), _jsx("dd", { children: target.supportedVersion }), _jsx("dt", { children: t('patchInstalledVersion') }), _jsx("dd", { children: target.installedVersion ?? '—' }), _jsx("dt", { children: t('patchSource') }), _jsx("dd", { className: css.source, children: target.source })] }), target.detail === undefined ? null : _jsx("p", { className: css.detail, children: target.detail }), busy && phase !== undefined ? (_jsxs("p", { className: css.progress, role: "status", children: [_jsx(StateDot, { state: "ongoing", size: 13 }), phase === 'applying' ? t('patchApplying') : t('patchWaiting')] })) : null, waiting ? _jsx("p", { className: css.hint, children: t('patchPendingHint') }) : null, action === undefined ? null : (_jsx("div", { className: css.actions, children: _jsx(Button, { variant: action === 'install' ? 'primary' : 'outline', disabled: busy, onClick: () => { onAct(action); }, children: busy ? t('patchWorking') : t(action === 'install' ? 'patchInstall' : 'patchUninstall') }) }))] }));
83
+ return (_jsxs("li", { className: css.row, children: [_jsxs("div", { className: css.rowHead, children: [_jsx("code", { className: css.packageName, children: target.packageName }), _jsx("span", { className: css.badge, "data-state": target.state, children: t(STATE_KEYS[target.state]) }), target.state === 'patched' && live ? _jsx("span", { className: css.live, children: t('patchActive') }) : null] }), _jsxs("dl", { className: css.meta, children: [_jsx("dt", { children: t('patchSupported') }), _jsx("dd", { children: versionsOf(target) }), _jsx("dt", { children: t('patchInstalledVersion') }), _jsx("dd", { children: target.installedVersion ?? '—' }), _jsx("dt", { children: t('patchSource') }), _jsx("dd", { className: css.source, children: target.source })] }), target.detail === undefined ? null : _jsx("p", { className: css.detail, children: target.detail }), busy && phase !== undefined ? (_jsxs("p", { className: css.progress, role: "status", children: [_jsx(StateDot, { state: "ongoing", size: 13 }), phase === 'applying' ? t('patchApplying') : t('patchWaiting')] })) : null, waiting ? _jsx("p", { className: css.hint, children: t('patchPendingHint') }) : null, action === undefined ? null : (_jsx("div", { className: css.actions, children: _jsx(Button, { variant: action === 'install' ? 'primary' : 'outline', disabled: busy, onClick: () => { onAct(action); }, children: busy ? t('patchWorking') : t(action === 'install' ? 'patchInstall' : 'patchUninstall') }) }))] }));
72
84
  }
73
85
  /**
74
86
  * Ask before touching another plugin's installed files.
@@ -76,5 +88,5 @@ function Row({ target, live, busy, phase, t, onAct }) {
76
88
  * @returns the dialog.
77
89
  */
78
90
  function ConfirmDialog({ target, action, t, onCancel, onConfirm }) {
79
- return (_jsxs(Modal, { open: true, onClose: onCancel, title: t(action === 'install' ? 'patchInstallTitle' : 'patchUninstallTitle'), closeLabel: t('close'), footer: (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "outline", onClick: onCancel, children: t('cancel') }), _jsx(Button, { variant: "primary", onClick: onConfirm, children: t(action === 'install' ? 'patchInstall' : 'patchUninstall') })] })), children: [_jsx("p", { children: t(action === 'install' ? 'patchInstallBody' : 'patchUninstallBody') }), _jsxs("dl", { className: css.meta, children: [_jsx("dt", { children: t('patchPackage') }), _jsx("dd", { children: _jsx("code", { children: target.packageName }) }), _jsx("dt", { children: t('patchFile') }), _jsx("dd", { children: _jsx("code", { children: `${target.packageName}/lib/client.js` }) }), _jsx("dt", { children: t('patchSupported') }), _jsx("dd", { children: target.supportedVersion })] })] }));
91
+ return (_jsxs(Modal, { open: true, onClose: onCancel, title: t(action === 'install' ? 'patchInstallTitle' : 'patchUninstallTitle'), closeLabel: t('close'), footer: (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "outline", onClick: onCancel, children: t('cancel') }), _jsx(Button, { variant: "primary", onClick: onConfirm, children: t(action === 'install' ? 'patchInstall' : 'patchUninstall') })] })), children: [_jsx("p", { children: t(action === 'install' ? 'patchInstallBody' : 'patchUninstallBody') }), _jsxs("dl", { className: css.meta, children: [_jsx("dt", { children: t('patchPackage') }), _jsx("dd", { children: _jsx("code", { children: target.packageName }) }), _jsx("dt", { children: t('patchFile') }), _jsx("dd", { children: _jsx("code", { children: `${target.packageName}/lib/client.js` }) }), _jsx("dt", { children: t('patchSupported') }), _jsx("dd", { children: versionsOf(target) })] })] }));
80
92
  }
@@ -37,6 +37,11 @@ export interface TeamListViewProps {
37
37
  }[];
38
38
  /** Opens the page that manages the Team preset categories. */
39
39
  readonly onManageCategories?: () => void;
40
+ /**
41
+ * How many shipped presets this deployment was offered but no longer holds,
42
+ * when none of them are in the list. Zero or undefined renders no hint.
43
+ */
44
+ readonly missingBuiltins?: number | undefined;
40
45
  }
41
46
  /**
42
47
  * Render the Team list.
@@ -33,7 +33,7 @@ export function TeamListView(props) {
33
33
  const matchesQuery = tokens.length === 0 || matchTeam(team, tokens) !== undefined;
34
34
  return matchesSource && matchesSeries && matchesCategory && matchesQuery;
35
35
  }), [props.teams, props.teamCategories, source, series, category, tokens]);
36
- return (_jsxs(_Fragment, { children: [_jsxs("header", { className: css.pageHead, children: [_jsx("h2", { className: css.title, children: t('title') }), _jsx("p", { className: css.intro, children: t('description') })] }), _jsxs("div", { className: css.toolbar, children: [_jsxs("div", { className: css.toolbarGroup, children: [_jsx(Button, { size: "sm", variant: "primary", disabled: disabled, onClick: props.onCreate, children: t('newTeam') }), _jsx(Button, { size: "sm", variant: "outline", disabled: disabled, title: t('importNote'), onClick: () => { fileInput.current?.click(); }, children: t('importPreset') })] }), _jsxs("div", { className: css.toolbarGroup, children: [props.onManageCategories === undefined ? null : (_jsx(Button, { size: "sm", variant: "outline", onClick: props.onManageCategories, children: t('categoryManagePage') })), _jsx(Button, { size: "sm", variant: "ghost", disabled: disabled, onClick: () => { setConfirmRestore(true); }, children: t('restoreDefaults') })] }), _jsx("input", { ref: fileInput, className: css.fileInput, type: "file", accept: "application/json,.json", disabled: disabled, onChange: (event) => {
36
+ return (_jsxs(_Fragment, { children: [_jsxs("header", { className: css.pageHead, children: [_jsx("h2", { className: css.title, children: t('title') }), _jsx("p", { className: css.intro, children: t('description') })] }), (props.missingBuiltins ?? 0) === 0 ? null : (_jsxs("div", { className: css.restoreHint, role: "status", children: [_jsx("span", { children: t('restoreMissingHint').replace('{count}', String(props.missingBuiltins)) }), _jsx(Button, { size: "sm", variant: "outline", disabled: disabled, onClick: () => { setConfirmRestore(true); }, children: t('restoreDefaults') })] })), _jsxs("div", { className: css.toolbar, children: [_jsxs("div", { className: css.toolbarGroup, children: [_jsx(Button, { size: "sm", variant: "primary", disabled: disabled, onClick: props.onCreate, children: t('newTeam') }), _jsx(Button, { size: "sm", variant: "outline", disabled: disabled, title: t('importNote'), onClick: () => { fileInput.current?.click(); }, children: t('importPreset') })] }), _jsxs("div", { className: css.toolbarGroup, children: [props.onManageCategories === undefined ? null : (_jsx(Button, { size: "sm", variant: "outline", onClick: props.onManageCategories, children: t('categoryManagePage') })), _jsx(Button, { size: "sm", variant: "ghost", disabled: disabled, onClick: () => { setConfirmRestore(true); }, children: t('restoreDefaults') })] }), _jsx("input", { ref: fileInput, className: css.fileInput, type: "file", accept: "application/json,.json", disabled: disabled, onChange: (event) => {
37
37
  const file = event.target.files?.[0];
38
38
  // Clearing the value lets the same document be chosen twice in a row.
39
39
  event.target.value = '';
@@ -12,6 +12,7 @@ import { TeamImportDialog } from "./TeamImportDialog.js";
12
12
  import { TeamListView } from "./TeamListView.js";
13
13
  import { TeamSkillsView } from "./TeamSkillsView.js";
14
14
  import { CardPatchView } from "./CardPatchView.js";
15
+ import { BUILTIN_TEAM_IDS } from "../builtin-teams.js";
15
16
  import { defaultImportResolution, executionStateOf, unnamedTeamsOf } from "./team-presets-controller.js";
16
17
  import { downloadPresetText, presetFileName, readPresetFile } from "./preset-file.js";
17
18
  import { DEFAULTS_NOTICE_KEYS, DISCLOSURE_NOTICE_KEYS, EXECUTION_NOTICE_KEYS, FORM_ISSUE_KEYS, IMPORT_FAILURE_KEYS, selectionFailureText } from "./locales.js";
@@ -145,6 +146,11 @@ export function TeamPresetsSection(props) {
145
146
  // silent failure.
146
147
  const disabled = !state.writable || state.formIssue !== undefined;
147
148
  const teamList = state.teams;
149
+ // The install pass never re-adds a preset it once offered, so an empty shipped
150
+ // set is a state this page must explain rather than hide. Counting only the
151
+ // complete case keeps the hint off the page for a reader who deleted one Team.
152
+ const heldIds = new Set(teamList.map(entry => entry.id));
153
+ const missingBuiltins = BUILTIN_TEAM_IDS.every(id => !heldIds.has(id)) ? BUILTIN_TEAM_IDS.length : 0;
148
154
  // Only the team and agent views address a Team; the categories page stands alone.
149
155
  const addressed = view.kind === 'team' || view.kind === 'agent' ? view.teamId : undefined;
150
156
  const found = addressed === undefined ? undefined : teamList.find(entry => entry.id === addressed);
@@ -211,7 +217,7 @@ export function TeamPresetsSection(props) {
211
217
  const agent = team === undefined || active.kind !== 'agent'
212
218
  ? undefined
213
219
  : active.slot === 'captain' ? team.captain : team.members[active.slot];
214
- return (_jsxs("div", { className: css.section, children: [_jsxs("div", { role: "tablist", className: css.tabs, children: [_jsx(TabButton, { active: tab === 'teams', onClick: () => { setTab('teams'); }, children: t('tabTeams') }), props.skills === undefined ? null : _jsx(TabButton, { active: tab === 'skills', onClick: () => { setTab('skills'); }, children: t('tabSkills') }), props.cardPatches === undefined ? null : _jsx(TabButton, { active: tab === 'links', onClick: () => { setTab('links'); }, children: t('tabLinks') })] }), _jsxs("div", { className: css.page, children: [active.kind === 'categories' && (_jsx(TeamCategoryManager, { categories: state.categories, teamCategories: state.teamCategories, disabled: disabled, t: t, onBack: () => { setView({ kind: 'list' }); }, onAdd: (name) => { void props.addCategory(name); }, onRename: (id, name) => { void props.renameCategory(id, name); }, onMove: (id, delta) => { void props.moveCategory(id, delta); }, onRemove: (id) => { void props.removeCategory(id); } })), active.kind === 'list' && (_jsx(TeamListView, { teams: teamList, t: t, disabled: disabled, importError: importError, categories: categoriesForList, onManageCategories: () => { setView({ kind: 'categories' }); }, teamCategories: state.teamCategories, onOpen: openTeam, onCreate: () => { openTeam(props.createTeam()); }, onImport: (file) => { void importDocument(file); }, onExport: exportDocument, onRestoreDefaults: () => {
220
+ return (_jsxs("div", { className: css.section, children: [_jsxs("div", { role: "tablist", className: css.tabs, children: [_jsx(TabButton, { active: tab === 'teams', onClick: () => { setTab('teams'); }, children: t('tabTeams') }), props.skills === undefined ? null : _jsx(TabButton, { active: tab === 'skills', onClick: () => { setTab('skills'); }, children: t('tabSkills') }), props.cardPatches === undefined ? null : _jsx(TabButton, { active: tab === 'links', onClick: () => { setTab('links'); }, children: t('tabLinks') })] }), _jsxs("div", { className: css.page, children: [active.kind === 'categories' && (_jsx(TeamCategoryManager, { categories: state.categories, teamCategories: state.teamCategories, disabled: disabled, t: t, onBack: () => { setView({ kind: 'list' }); }, onAdd: (name) => { void props.addCategory(name); }, onRename: (id, name) => { void props.renameCategory(id, name); }, onMove: (id, delta) => { void props.moveCategory(id, delta); }, onRemove: (id) => { void props.removeCategory(id); } })), active.kind === 'list' && (_jsx(TeamListView, { teams: teamList, t: t, disabled: disabled, importError: importError, categories: categoriesForList, onManageCategories: () => { setView({ kind: 'categories' }); }, missingBuiltins: missingBuiltins, teamCategories: state.teamCategories, onOpen: openTeam, onCreate: () => { openTeam(props.createTeam()); }, onImport: (file) => { void importDocument(file); }, onExport: exportDocument, onRestoreDefaults: () => {
215
221
  props.restoreDefaults();
216
222
  void props.skills?.restoreBuiltinBindings();
217
223
  }, onDuplicate: (teamId) => {
@@ -17,7 +17,13 @@
17
17
  const SETTLE_TIMEOUT_MS = 6000;
18
18
  /** How often that wait re-reads the registered services. */
19
19
  const SETTLE_POLL_MS = 250;
20
- /** Services a patched target registers, by target identity. */
20
+ /**
21
+ * Fallback services, used only before the Host's rows have arrived.
22
+ *
23
+ * Once a row exists its own `service` field is authoritative: the Host derives
24
+ * it from the catalog entry that matches the installed version, so a target
25
+ * added by a shipped catalog never needs a code change here.
26
+ */
21
27
  const SERVICES = {
22
28
  'dsh-context': 'contextAgentCardBadges',
23
29
  'dsh-better-sidebar': 'betterSidebarAgentCardBadges',
@@ -97,9 +103,14 @@ export class CardPatchesController {
97
103
  * alone changes nothing until the server restarts and the page reloads.
98
104
  * @returns the live target identities, in catalog order.
99
105
  */
100
- liveTargets() {
101
- return Object.entries(SERVICES)
102
- .filter(([, service]) => this.ctx.get(service) !== undefined)
106
+ liveTargets(targets = this.state.targets) {
107
+ // `target.service` is authoritative once the Host sends it; a Host from
108
+ // before the multi-version catalog sends none, so the fallback still applies.
109
+ const pairs = targets.length > 0
110
+ ? targets.map(target => [target.id, target.service ?? SERVICES[target.id]])
111
+ : Object.entries(SERVICES);
112
+ return pairs
113
+ .filter(([, service]) => service !== undefined && this.ctx.get(service) !== undefined)
103
114
  .map(([id]) => id);
104
115
  }
105
116
  /**
@@ -115,7 +126,7 @@ export class CardPatchesController {
115
126
  }
116
127
  try {
117
128
  const targets = unwrap(await remote.cardPatches());
118
- this.state = { ...this.state, status: 'ready', targets, live: this.liveTargets() };
129
+ this.state = { ...this.state, status: 'ready', targets, live: this.liveTargets(targets) };
119
130
  }
120
131
  catch (error) {
121
132
  this.state = { ...this.state, status: 'unavailable', live: this.liveTargets() };