pi-extmgr 0.1.22 → 0.1.24
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/README.md +25 -12
- package/package.json +1 -1
- package/src/commands/auto-update.ts +1 -1
- package/src/commands/cache.ts +5 -1
- package/src/commands/history.ts +4 -2
- package/src/commands/registry.ts +1 -1
- package/src/index.ts +6 -1
- package/src/packages/discovery.ts +53 -28
- package/src/packages/extensions.ts +171 -63
- package/src/packages/install.ts +118 -24
- package/src/packages/management.ts +58 -37
- package/src/ui/package-config.ts +157 -126
- package/src/ui/remote.ts +79 -54
- package/src/ui/unified.ts +222 -173
- package/src/utils/auto-update.ts +36 -31
- package/src/utils/command.ts +77 -1
- package/src/utils/format.ts +23 -3
- package/src/utils/history.ts +41 -2
- package/src/utils/mode.ts +56 -5
- package/src/utils/npm-exec.ts +47 -0
- package/src/utils/package-source.ts +43 -0
- package/src/utils/settings-list.ts +12 -0
- package/src/utils/settings.ts +35 -7
- package/src/utils/status.ts +10 -2
- package/src/utils/timer.ts +32 -8
- package/src/utils/ui-helpers.ts +2 -1
package/src/utils/command.ts
CHANGED
|
@@ -3,7 +3,83 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export function tokenizeArgs(input: string): string[] {
|
|
6
|
-
|
|
6
|
+
const tokens: string[] = [];
|
|
7
|
+
let current = "";
|
|
8
|
+
let inSingleQuote = false;
|
|
9
|
+
let inDoubleQuote = false;
|
|
10
|
+
let tokenStarted = false;
|
|
11
|
+
|
|
12
|
+
const pushCurrent = () => {
|
|
13
|
+
if (tokenStarted) {
|
|
14
|
+
tokens.push(current);
|
|
15
|
+
current = "";
|
|
16
|
+
tokenStarted = false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < input.length; i++) {
|
|
21
|
+
const char = input[i]!;
|
|
22
|
+
const next = input[i + 1];
|
|
23
|
+
|
|
24
|
+
if (inSingleQuote) {
|
|
25
|
+
if (char === "'") {
|
|
26
|
+
inSingleQuote = false;
|
|
27
|
+
} else {
|
|
28
|
+
current += char;
|
|
29
|
+
}
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (inDoubleQuote) {
|
|
34
|
+
if (char === '"') {
|
|
35
|
+
inDoubleQuote = false;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (char === "\\" && next === '"') {
|
|
40
|
+
current += next;
|
|
41
|
+
i++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
current += char;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (/\s/.test(char)) {
|
|
50
|
+
pushCurrent();
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (char === "'") {
|
|
55
|
+
inSingleQuote = true;
|
|
56
|
+
tokenStarted = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (char === '"') {
|
|
61
|
+
inDoubleQuote = true;
|
|
62
|
+
tokenStarted = true;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (char === "\\" && (next === '"' || next === "'" || /\s/.test(next ?? ""))) {
|
|
67
|
+
tokenStarted = true;
|
|
68
|
+
if (next) {
|
|
69
|
+
current += next;
|
|
70
|
+
i++;
|
|
71
|
+
} else {
|
|
72
|
+
current += char;
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
tokenStarted = true;
|
|
78
|
+
current += char;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
pushCurrent();
|
|
82
|
+
return tokens;
|
|
7
83
|
}
|
|
8
84
|
|
|
9
85
|
export function splitCommandArgs(input: string): { subcommand: string; args: string[] } {
|
package/src/utils/format.ts
CHANGED
|
@@ -59,6 +59,9 @@ export function formatBytes(bytes: number): string {
|
|
|
59
59
|
|
|
60
60
|
const GIT_PATTERNS = {
|
|
61
61
|
gitPrefix: /^git:/,
|
|
62
|
+
gitPlusHttpPrefix: /^git\+https?:\/\//,
|
|
63
|
+
gitPlusSshPrefix: /^git\+ssh:\/\//,
|
|
64
|
+
gitPlusGitPrefix: /^git\+git:\/\//,
|
|
62
65
|
httpPrefix: /^https?:\/\//,
|
|
63
66
|
sshPrefix: /^ssh:\/\//,
|
|
64
67
|
gitProtoPrefix: /^git:\/\//,
|
|
@@ -78,6 +81,9 @@ const LOCAL_PATH_PATTERNS = {
|
|
|
78
81
|
function isGitLikeSource(source: string): boolean {
|
|
79
82
|
return (
|
|
80
83
|
GIT_PATTERNS.gitPrefix.test(source) ||
|
|
84
|
+
GIT_PATTERNS.gitPlusHttpPrefix.test(source) ||
|
|
85
|
+
GIT_PATTERNS.gitPlusSshPrefix.test(source) ||
|
|
86
|
+
GIT_PATTERNS.gitPlusGitPrefix.test(source) ||
|
|
81
87
|
GIT_PATTERNS.httpPrefix.test(source) ||
|
|
82
88
|
GIT_PATTERNS.sshPrefix.test(source) ||
|
|
83
89
|
GIT_PATTERNS.gitProtoPrefix.test(source) ||
|
|
@@ -97,22 +103,36 @@ function isLocalPathSource(source: string): boolean {
|
|
|
97
103
|
);
|
|
98
104
|
}
|
|
99
105
|
|
|
106
|
+
function unwrapQuotedSource(source: string): string {
|
|
107
|
+
const trimmed = source.trim();
|
|
108
|
+
if (trimmed.length < 2) return trimmed;
|
|
109
|
+
|
|
110
|
+
const first = trimmed[0];
|
|
111
|
+
const last = trimmed[trimmed.length - 1];
|
|
112
|
+
|
|
113
|
+
if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
|
|
114
|
+
return trimmed.slice(1, -1).trim();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return trimmed;
|
|
118
|
+
}
|
|
119
|
+
|
|
100
120
|
export function isPackageSource(str: string): boolean {
|
|
101
|
-
const source = str
|
|
121
|
+
const source = unwrapQuotedSource(str);
|
|
102
122
|
if (!source) return false;
|
|
103
123
|
|
|
104
124
|
return source.startsWith("npm:") || isGitLikeSource(source) || isLocalPathSource(source);
|
|
105
125
|
}
|
|
106
126
|
|
|
107
127
|
export function normalizePackageSource(source: string): string {
|
|
108
|
-
const trimmed = source
|
|
128
|
+
const trimmed = unwrapQuotedSource(source);
|
|
109
129
|
if (!trimmed) return trimmed;
|
|
110
130
|
|
|
111
131
|
if (GIT_PATTERNS.gitSsh.test(trimmed)) {
|
|
112
132
|
return `git:${trimmed}`;
|
|
113
133
|
}
|
|
114
134
|
|
|
115
|
-
if (
|
|
135
|
+
if (trimmed.startsWith("npm:") || isGitLikeSource(trimmed) || isLocalPathSource(trimmed)) {
|
|
116
136
|
return trimmed;
|
|
117
137
|
}
|
|
118
138
|
|
package/src/utils/history.ts
CHANGED
|
@@ -9,10 +9,12 @@ import { join } from "node:path";
|
|
|
9
9
|
|
|
10
10
|
export type ChangeAction =
|
|
11
11
|
| "extension_toggle"
|
|
12
|
+
| "extension_delete"
|
|
12
13
|
| "package_install"
|
|
13
14
|
| "package_update"
|
|
14
15
|
| "package_remove"
|
|
15
|
-
| "cache_clear"
|
|
16
|
+
| "cache_clear"
|
|
17
|
+
| "auto_update_config";
|
|
16
18
|
|
|
17
19
|
export interface ExtensionChangeEntry {
|
|
18
20
|
action: ChangeAction;
|
|
@@ -26,6 +28,7 @@ export interface ExtensionChangeEntry {
|
|
|
26
28
|
packageName?: string | undefined;
|
|
27
29
|
version?: string | undefined;
|
|
28
30
|
scope?: "global" | "project" | undefined;
|
|
31
|
+
detail?: string | undefined;
|
|
29
32
|
// Result
|
|
30
33
|
success: boolean;
|
|
31
34
|
error?: string | undefined;
|
|
@@ -80,6 +83,34 @@ export function logExtensionToggle(
|
|
|
80
83
|
});
|
|
81
84
|
}
|
|
82
85
|
|
|
86
|
+
export function logExtensionDelete(
|
|
87
|
+
pi: ExtensionAPI,
|
|
88
|
+
extensionId: string,
|
|
89
|
+
success: boolean,
|
|
90
|
+
error?: string
|
|
91
|
+
): void {
|
|
92
|
+
logChange(pi, {
|
|
93
|
+
action: "extension_delete",
|
|
94
|
+
extensionId,
|
|
95
|
+
success,
|
|
96
|
+
error,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function logAutoUpdateConfig(
|
|
101
|
+
pi: ExtensionAPI,
|
|
102
|
+
detail: string,
|
|
103
|
+
success: boolean,
|
|
104
|
+
error?: string
|
|
105
|
+
): void {
|
|
106
|
+
logChange(pi, {
|
|
107
|
+
action: "auto_update_config",
|
|
108
|
+
detail,
|
|
109
|
+
success,
|
|
110
|
+
error,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
83
114
|
/**
|
|
84
115
|
* Log package installation
|
|
85
116
|
*/
|
|
@@ -180,10 +211,12 @@ function matchesHistoryFilters(change: ExtensionChangeEntry, filters: HistoryFil
|
|
|
180
211
|
const packageName = change.packageName?.toLowerCase() ?? "";
|
|
181
212
|
const packageSource = change.packageSource?.toLowerCase() ?? "";
|
|
182
213
|
const extensionId = change.extensionId?.toLowerCase() ?? "";
|
|
214
|
+
const detail = change.detail?.toLowerCase() ?? "";
|
|
183
215
|
if (
|
|
184
216
|
!packageName.includes(packageQuery) &&
|
|
185
217
|
!packageSource.includes(packageQuery) &&
|
|
186
|
-
!extensionId.includes(packageQuery)
|
|
218
|
+
!extensionId.includes(packageQuery) &&
|
|
219
|
+
!detail.includes(packageQuery)
|
|
187
220
|
) {
|
|
188
221
|
return false;
|
|
189
222
|
}
|
|
@@ -330,6 +363,9 @@ export function formatChangeEntry(entry: ExtensionChangeEntry): string {
|
|
|
330
363
|
case "extension_toggle":
|
|
331
364
|
return `[${time}] ${icon} ${entry.extensionId}: ${entry.fromState} → ${entry.toState}`;
|
|
332
365
|
|
|
366
|
+
case "extension_delete":
|
|
367
|
+
return `[${time}] ${icon} Deleted ${entry.extensionId ?? "extension"}`;
|
|
368
|
+
|
|
333
369
|
case "package_install":
|
|
334
370
|
return `[${time}] ${icon} Installed ${packageLabel}${entry.version ? `@${entry.version}` : ""}${sourceSuffix}`;
|
|
335
371
|
|
|
@@ -342,6 +378,9 @@ export function formatChangeEntry(entry: ExtensionChangeEntry): string {
|
|
|
342
378
|
case "cache_clear":
|
|
343
379
|
return `[${time}] ${icon} Cache cleared`;
|
|
344
380
|
|
|
381
|
+
case "auto_update_config":
|
|
382
|
+
return `[${time}] ${icon} Auto-update ${entry.detail ?? "configuration changed"}`;
|
|
383
|
+
|
|
345
384
|
default:
|
|
346
385
|
return `[${time}] ${icon} Unknown action`;
|
|
347
386
|
}
|
package/src/utils/mode.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* UI
|
|
2
|
+
* UI capability helpers
|
|
3
3
|
*/
|
|
4
|
-
import type { ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
|
|
4
|
+
import type { ExtensionCommandContext, ExtensionContext } from "@mariozechner/pi-coding-agent";
|
|
5
5
|
import { notify } from "./notify.js";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
type AnyContext = ExtensionCommandContext | ExtensionContext;
|
|
8
|
+
|
|
9
|
+
export type UICapability = "none" | "dialog" | "custom";
|
|
10
|
+
|
|
11
|
+
export function getUICapability(ctx: AnyContext): UICapability {
|
|
12
|
+
if (!ctx.hasUI) {
|
|
13
|
+
return "none";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return typeof ctx.ui?.custom === "function" ? "custom" : "dialog";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function hasCustomUI(ctx: AnyContext): boolean {
|
|
20
|
+
return getUICapability(ctx) === "custom";
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
export function requireUI(ctx: ExtensionCommandContext, featureName: string): boolean {
|
|
11
24
|
if (!ctx.hasUI) {
|
|
12
25
|
notify(
|
|
@@ -19,6 +32,44 @@ export function requireUI(ctx: ExtensionCommandContext, featureName: string): bo
|
|
|
19
32
|
return true;
|
|
20
33
|
}
|
|
21
34
|
|
|
35
|
+
export function requireCustomUI(
|
|
36
|
+
ctx: AnyContext,
|
|
37
|
+
featureName: string,
|
|
38
|
+
fallbackMessage?: string
|
|
39
|
+
): boolean {
|
|
40
|
+
if (hasCustomUI(ctx)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const suffix = fallbackMessage ? ` ${fallbackMessage}` : "";
|
|
45
|
+
if (ctx.hasUI) {
|
|
46
|
+
notify(ctx, `${featureName} requires the full interactive TUI.${suffix}`, "warning");
|
|
47
|
+
} else {
|
|
48
|
+
notify(ctx, `${featureName} requires interactive mode.${suffix}`, "warning");
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function runCustomUI<T>(
|
|
54
|
+
ctx: AnyContext,
|
|
55
|
+
featureName: string,
|
|
56
|
+
open: () => Promise<T | undefined>,
|
|
57
|
+
fallbackMessage?: string
|
|
58
|
+
): Promise<T | undefined> {
|
|
59
|
+
if (!requireCustomUI(ctx, featureName, fallbackMessage)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const result = await open();
|
|
64
|
+
if (result !== undefined) {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const suffix = fallbackMessage ? ` ${fallbackMessage}` : "";
|
|
69
|
+
notify(ctx, `${featureName} requires the full interactive TUI.${suffix}`, "warning");
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
22
73
|
/**
|
|
23
74
|
* Execute operation with automatic error handling
|
|
24
75
|
*/
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { execPath, platform } from "node:process";
|
|
3
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
4
|
+
|
|
5
|
+
interface NpmCommandResolutionOptions {
|
|
6
|
+
platform?: NodeJS.Platform;
|
|
7
|
+
nodeExecPath?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface NpmExecOptions {
|
|
11
|
+
timeout: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getNpmCliPath(nodeExecPath: string, runtimePlatform: NodeJS.Platform): string {
|
|
15
|
+
const pathImpl = runtimePlatform === "win32" ? path.win32 : path;
|
|
16
|
+
return pathImpl.join(pathImpl.dirname(nodeExecPath), "node_modules", "npm", "bin", "npm-cli.js");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function resolveNpmCommand(
|
|
20
|
+
npmArgs: string[],
|
|
21
|
+
options?: NpmCommandResolutionOptions
|
|
22
|
+
): { command: string; args: string[] } {
|
|
23
|
+
const runtimePlatform = options?.platform ?? platform;
|
|
24
|
+
|
|
25
|
+
if (runtimePlatform === "win32") {
|
|
26
|
+
const nodeBinary = options?.nodeExecPath ?? execPath;
|
|
27
|
+
return {
|
|
28
|
+
command: nodeBinary,
|
|
29
|
+
args: [getNpmCliPath(nodeBinary, runtimePlatform), ...npmArgs],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return { command: "npm", args: npmArgs };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function execNpm(
|
|
37
|
+
pi: ExtensionAPI,
|
|
38
|
+
npmArgs: string[],
|
|
39
|
+
ctx: { cwd: string },
|
|
40
|
+
options: NpmExecOptions
|
|
41
|
+
): Promise<{ code: number; stdout: string; stderr: string; killed: boolean }> {
|
|
42
|
+
const resolved = resolveNpmCommand(npmArgs);
|
|
43
|
+
return pi.exec(resolved.command, resolved.args, {
|
|
44
|
+
timeout: options.timeout,
|
|
45
|
+
cwd: ctx.cwd,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Package source parsing helpers shared across discovery/management flows.
|
|
3
3
|
*/
|
|
4
|
+
import { parseNpmSource } from "./format.js";
|
|
4
5
|
|
|
5
6
|
export type PackageSourceKind = "npm" | "git" | "local" | "unknown";
|
|
6
7
|
|
|
@@ -18,6 +19,10 @@ export function getPackageSourceKind(source: string): PackageSourceKind {
|
|
|
18
19
|
|
|
19
20
|
if (
|
|
20
21
|
normalized.startsWith("git:") ||
|
|
22
|
+
normalized.startsWith("git+http://") ||
|
|
23
|
+
normalized.startsWith("git+https://") ||
|
|
24
|
+
normalized.startsWith("git+ssh://") ||
|
|
25
|
+
normalized.startsWith("git+git://") ||
|
|
21
26
|
normalized.startsWith("http://") ||
|
|
22
27
|
normalized.startsWith("https://") ||
|
|
23
28
|
normalized.startsWith("ssh://") ||
|
|
@@ -43,6 +48,44 @@ export function getPackageSourceKind(source: string): PackageSourceKind {
|
|
|
43
48
|
return "unknown";
|
|
44
49
|
}
|
|
45
50
|
|
|
51
|
+
export function normalizeLocalSourceIdentity(source: string): string {
|
|
52
|
+
const normalized = source.replace(/\\/g, "/");
|
|
53
|
+
const looksWindowsPath =
|
|
54
|
+
/^[a-zA-Z]:\//.test(normalized) || normalized.startsWith("//") || source.includes("\\");
|
|
55
|
+
|
|
56
|
+
return looksWindowsPath ? normalized.toLowerCase() : normalized;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function stripGitSourcePrefix(source: string): string {
|
|
60
|
+
const withoutGitPlus = source.startsWith("git+") ? source.slice(4) : source;
|
|
61
|
+
return withoutGitPlus.startsWith("git:") ? withoutGitPlus.slice(4) : withoutGitPlus;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function normalizePackageIdentity(
|
|
65
|
+
source: string,
|
|
66
|
+
options?: { resolvedPath?: string }
|
|
67
|
+
): string {
|
|
68
|
+
const normalized = sanitizeSource(source);
|
|
69
|
+
const kind = getPackageSourceKind(normalized);
|
|
70
|
+
|
|
71
|
+
if (kind === "npm") {
|
|
72
|
+
const npm = parseNpmSource(normalized);
|
|
73
|
+
return `npm:${(npm?.name ?? normalized).toLowerCase()}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (kind === "git") {
|
|
77
|
+
const gitSpec = stripGitSourcePrefix(normalized);
|
|
78
|
+
const { repo } = splitGitRepoAndRef(gitSpec);
|
|
79
|
+
return `git:${repo.replace(/\\/g, "/").toLowerCase()}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (kind === "local") {
|
|
83
|
+
return `local:${normalizeLocalSourceIdentity(options?.resolvedPath ?? normalized)}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return `raw:${normalized.replace(/\\/g, "/").toLowerCase()}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
46
89
|
export function splitGitRepoAndRef(gitSpec: string): { repo: string; ref?: string | undefined } {
|
|
47
90
|
const lastAt = gitSpec.lastIndexOf("@");
|
|
48
91
|
if (lastAt <= 0) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface SelectableListLike {
|
|
2
|
+
selectedIndex?: number;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function getSettingsListSelectedIndex(settingsList: unknown): number | undefined {
|
|
6
|
+
if (!settingsList || typeof settingsList !== "object") {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const selectable = settingsList as SelectableListLike;
|
|
11
|
+
return Number.isInteger(selectable.selectedIndex) ? selectable.selectedIndex : undefined;
|
|
12
|
+
}
|
package/src/utils/settings.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { readFile, writeFile, mkdir, rename, rm } from "node:fs/promises";
|
|
|
11
11
|
import { homedir } from "node:os";
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
import { fileExists } from "./fs.js";
|
|
14
|
+
import { normalizePackageIdentity } from "./package-source.js";
|
|
14
15
|
|
|
15
16
|
export interface AutoUpdateConfig {
|
|
16
17
|
intervalMs: number;
|
|
@@ -49,6 +50,20 @@ function sanitizeStringArray(value: unknown): string[] | undefined {
|
|
|
49
50
|
return sanitized.length > 0 ? sanitized : undefined;
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
function isUpdateIdentity(value: string): boolean {
|
|
54
|
+
return /^(npm|git|local|raw):/i.test(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function sanitizeUpdateIdentities(value: unknown): string[] | undefined {
|
|
58
|
+
const updates = sanitizeStringArray(value);
|
|
59
|
+
if (!updates) return undefined;
|
|
60
|
+
|
|
61
|
+
const sanitized = updates
|
|
62
|
+
.filter(isUpdateIdentity)
|
|
63
|
+
.map((entry) => normalizePackageIdentity(entry));
|
|
64
|
+
return sanitized.length > 0 ? sanitized : undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
function sanitizeAutoUpdateConfig(input: unknown): AutoUpdateConfig {
|
|
53
68
|
if (!isRecord(input)) {
|
|
54
69
|
return { ...DEFAULT_CONFIG };
|
|
@@ -85,7 +100,7 @@ function sanitizeAutoUpdateConfig(input: unknown): AutoUpdateConfig {
|
|
|
85
100
|
config.nextCheck = input.nextCheck;
|
|
86
101
|
}
|
|
87
102
|
|
|
88
|
-
const updates =
|
|
103
|
+
const updates = sanitizeUpdateIdentities(input.updatesAvailable);
|
|
89
104
|
if (updates) {
|
|
90
105
|
config.updatesAvailable = updates;
|
|
91
106
|
}
|
|
@@ -263,15 +278,28 @@ export function saveAutoUpdateConfig(pi: ExtensionAPI, config: Partial<AutoUpdat
|
|
|
263
278
|
*/
|
|
264
279
|
export function clearUpdatesAvailable(
|
|
265
280
|
pi: ExtensionAPI,
|
|
266
|
-
ctx: ExtensionCommandContext | ExtensionContext
|
|
281
|
+
ctx: ExtensionCommandContext | ExtensionContext,
|
|
282
|
+
identities?: Iterable<string>
|
|
267
283
|
): void {
|
|
268
284
|
const config = getAutoUpdateConfig(ctx);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
285
|
+
const currentUpdates = config.updatesAvailable ?? [];
|
|
286
|
+
if (currentUpdates.length === 0) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const clearedIdentities = identities ? new Set(identities) : undefined;
|
|
291
|
+
const updatesAvailable = clearedIdentities
|
|
292
|
+
? currentUpdates.filter((identity) => !clearedIdentities.has(identity))
|
|
293
|
+
: [];
|
|
294
|
+
|
|
295
|
+
if (updatesAvailable.length === currentUpdates.length) {
|
|
296
|
+
return;
|
|
274
297
|
}
|
|
298
|
+
|
|
299
|
+
saveAutoUpdateConfig(pi, {
|
|
300
|
+
...config,
|
|
301
|
+
updatesAvailable,
|
|
302
|
+
});
|
|
275
303
|
}
|
|
276
304
|
|
|
277
305
|
/**
|
package/src/utils/status.ts
CHANGED
|
@@ -8,14 +8,22 @@ import type {
|
|
|
8
8
|
} from "@mariozechner/pi-coding-agent";
|
|
9
9
|
import { getInstalledPackages } from "../packages/discovery.js";
|
|
10
10
|
import { getAutoUpdateStatus } from "./auto-update.js";
|
|
11
|
+
import { normalizePackageIdentity } from "./package-source.js";
|
|
11
12
|
import { getAutoUpdateConfigAsync, saveAutoUpdateConfig } from "./settings.js";
|
|
12
13
|
|
|
13
14
|
function filterStaleUpdates(
|
|
14
15
|
knownUpdates: string[],
|
|
15
16
|
installedPackages: Awaited<ReturnType<typeof getInstalledPackages>>
|
|
16
17
|
): string[] {
|
|
17
|
-
const
|
|
18
|
-
|
|
18
|
+
const installedIdentities = new Set(
|
|
19
|
+
installedPackages.map((pkg) =>
|
|
20
|
+
normalizePackageIdentity(
|
|
21
|
+
pkg.source,
|
|
22
|
+
pkg.resolvedPath ? { resolvedPath: pkg.resolvedPath } : undefined
|
|
23
|
+
)
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
return knownUpdates.filter((identity) => installedIdentities.has(identity));
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
export async function updateExtmgrStatus(
|
package/src/utils/timer.ts
CHANGED
|
@@ -4,33 +4,57 @@
|
|
|
4
4
|
|
|
5
5
|
export type TimerCallback = () => void;
|
|
6
6
|
|
|
7
|
-
let
|
|
7
|
+
let intervalId: ReturnType<typeof setInterval> | null = null;
|
|
8
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Start a recurring timer with the given interval and callback.
|
|
11
12
|
* Clears any existing timer first.
|
|
12
13
|
*/
|
|
13
|
-
export function startTimer(
|
|
14
|
+
export function startTimer(
|
|
15
|
+
intervalMs: number,
|
|
16
|
+
callback: TimerCallback,
|
|
17
|
+
options?: { initialDelayMs?: number }
|
|
18
|
+
): void {
|
|
14
19
|
stopTimer();
|
|
15
20
|
|
|
16
21
|
if (intervalMs <= 0) return;
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
const runAndReschedule = (): void => {
|
|
24
|
+
intervalId = setInterval(callback, intervalMs);
|
|
25
|
+
callback();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const initialDelayMs = options?.initialDelayMs ?? 0;
|
|
29
|
+
if (initialDelayMs <= 0) {
|
|
30
|
+
runAndReschedule();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
timeoutId = setTimeout(() => {
|
|
35
|
+
timeoutId = null;
|
|
36
|
+
runAndReschedule();
|
|
37
|
+
}, initialDelayMs);
|
|
19
38
|
}
|
|
20
39
|
|
|
21
40
|
/**
|
|
22
41
|
* Stop the current timer if running.
|
|
23
42
|
*/
|
|
24
43
|
export function stopTimer(): void {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
if (timeoutId) {
|
|
45
|
+
clearTimeout(timeoutId);
|
|
46
|
+
timeoutId = null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (intervalId) {
|
|
50
|
+
clearInterval(intervalId);
|
|
51
|
+
intervalId = null;
|
|
52
|
+
}
|
|
29
53
|
}
|
|
30
54
|
|
|
31
55
|
/**
|
|
32
56
|
* Check if a timer is currently running.
|
|
33
57
|
*/
|
|
34
58
|
export function isTimerRunning(): boolean {
|
|
35
|
-
return
|
|
59
|
+
return timeoutId !== null || intervalId !== null;
|
|
36
60
|
}
|
package/src/utils/ui-helpers.ts
CHANGED
|
@@ -67,9 +67,10 @@ export function formatListOutput(
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
const output = items.join("\n");
|
|
70
|
+
const titledOutput = `${title}:\n${output}`;
|
|
70
71
|
|
|
71
72
|
if (ctx.hasUI) {
|
|
72
|
-
ctx.ui.notify(
|
|
73
|
+
ctx.ui.notify(titledOutput, "info");
|
|
73
74
|
} else {
|
|
74
75
|
console.log(`${title}:`);
|
|
75
76
|
console.log(output);
|