@howaboua/pi-chatgpt-sites 0.0.2 → 0.0.4
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/CHANGELOG.md +15 -0
- package/dist/index.js +27 -20
- package/dist/src/docs/deployment.md +8 -8
- package/dist/src/docs/environment.md +11 -11
- package/dist/src/docs/index.md +12 -12
- package/dist/src/facade.d.ts +1 -5
- package/dist/src/facade.js +1 -5
- package/dist/src/redact.js +1 -1
- package/package.json +60 -59
- package/changelog.ts +0 -337
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @howaboua/pi-chatgpt-sites
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
- Requires Pi 1.5 or newer.
|
|
6
|
+
|
|
7
|
+
- Removed custom changelog suppression. Updates use Pi's native notices and `collapseChangelog`.
|
|
8
|
+
- Replaced the TypeBox dependency with Pi's native schema builders.
|
|
9
|
+
|
|
10
|
+
Sites documentation examples no longer prescribe `await`.
|
|
11
|
+
|
|
12
|
+
## 0.0.3
|
|
13
|
+
|
|
14
|
+
- - Sites calls now return their payload directly instead of an outer `result` wrapper.
|
|
15
|
+
- Errors show the problem and recovery information without diagnostic envelopes.
|
|
16
|
+
- GPT mode uses note-style guide and schema discovery.
|
|
17
|
+
|
|
3
18
|
## 0.0.2
|
|
4
19
|
|
|
5
20
|
- Streamlined tool descriptions and on-demand help discovery. Guide contents are unchanged.
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { map, obj, opt, str, unknown, } from "@earendil-works/pi-schema";
|
|
3
3
|
import { getSitesAuth } from "./src/auth.js";
|
|
4
4
|
import { SitesClient } from "./src/client.js";
|
|
5
5
|
import { call, documentation } from "./src/facade.js";
|
|
6
|
-
import { boundedJson } from "./src/redact.js";
|
|
6
|
+
import { boundedJson, redact } from "./src/redact.js";
|
|
7
7
|
async function result(run) {
|
|
8
8
|
try {
|
|
9
9
|
const value = await run();
|
|
@@ -21,32 +21,39 @@ async function result(run) {
|
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
23
23
|
const info = error instanceof Error ? error : new Error(String(error));
|
|
24
|
-
throw new Error(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
throw new Error([
|
|
25
|
+
redact(info.message),
|
|
26
|
+
"topic" in info &&
|
|
27
|
+
info.topic &&
|
|
28
|
+
!info.message.includes("sites_documentation(")
|
|
29
|
+
? `See sites_documentation({topic:${JSON.stringify(info.topic)}})`
|
|
30
|
+
: undefined,
|
|
31
|
+
"termsUrl" in info && info.termsUrl
|
|
32
|
+
? `Terms: ${redact(info.termsUrl)}`
|
|
33
|
+
: undefined,
|
|
34
|
+
"details" in info && info.details
|
|
35
|
+
? boundedJson(info.details)
|
|
36
|
+
: undefined,
|
|
37
|
+
]
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.join("\n"));
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
function isRecord(value) {
|
|
38
43
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
39
44
|
}
|
|
45
|
+
const SitesParameters = obj({
|
|
46
|
+
resource: opt(str()),
|
|
47
|
+
action: opt(str()),
|
|
48
|
+
params: opt(map(unknown())),
|
|
49
|
+
}, { open: false });
|
|
50
|
+
const GuideParameters = obj({ topic: opt(str()) }, { open: false });
|
|
40
51
|
export default async function sitesExtension(pi) {
|
|
41
52
|
const sites = defineTool({
|
|
42
53
|
name: "sites",
|
|
43
54
|
label: "Sites",
|
|
44
55
|
description: "Manage ChatGPT Sites",
|
|
45
|
-
parameters:
|
|
46
|
-
resource: Type.Optional(Type.String()),
|
|
47
|
-
action: Type.Optional(Type.String()),
|
|
48
|
-
params: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
|
|
49
|
-
}, { additionalProperties: false }),
|
|
56
|
+
parameters: SitesParameters,
|
|
50
57
|
async execute(_id, args, signal, _onUpdate, ctx) {
|
|
51
58
|
const client = new SitesClient({
|
|
52
59
|
authProvider: () => getSitesAuth(ctx),
|
|
@@ -61,7 +68,7 @@ export default async function sitesExtension(pi) {
|
|
|
61
68
|
name: "sites_documentation",
|
|
62
69
|
label: "Sites documentation",
|
|
63
70
|
description: "Sites guide or current resource.action parameter schema",
|
|
64
|
-
parameters:
|
|
71
|
+
parameters: GuideParameters,
|
|
65
72
|
async execute(_id, args, signal, _onUpdate, ctx) {
|
|
66
73
|
return result(() => documentation(args.topic === "help" ? "index" : args.topic, new SitesClient({ authProvider: () => getSitesAuth(ctx), signal })));
|
|
67
74
|
},
|
|
@@ -74,7 +81,7 @@ export default async function sitesExtension(pi) {
|
|
|
74
81
|
},
|
|
75
82
|
{
|
|
76
83
|
tool: guide,
|
|
77
|
-
gpt: "Sites guide
|
|
84
|
+
gpt: "Sites guide/live resource.action parameter schema",
|
|
78
85
|
ordinary: guide.description,
|
|
79
86
|
},
|
|
80
87
|
];
|
|
@@ -12,14 +12,14 @@ Required facade parameters: `project_id` (or local manifest), `version_id`, and
|
|
|
12
12
|
Calling this action is the production effect. Preserve the existing audience unless the user requests a change.
|
|
13
13
|
|
|
14
14
|
```js
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
15
|
+
tools.sites({
|
|
16
|
+
resource: "deployment",
|
|
17
|
+
action: "deploy",
|
|
18
|
+
params: {
|
|
19
|
+
version_id: "<opaque-version-id>",
|
|
20
|
+
visibility: "private",
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
If private deployment is rejected because access is not owner-only, reread `site.get`. Never silently fall back or alter access. Report any conflict with the requested audience.
|
|
@@ -11,17 +11,17 @@ Get configured production runtime entries and their revision. The facade recursi
|
|
|
11
11
|
Pass `set_values` and optional `remove`:
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})
|
|
14
|
+
tools.sites({
|
|
15
|
+
resource: "environment",
|
|
16
|
+
action: "update",
|
|
17
|
+
params: {
|
|
18
|
+
set_values: [
|
|
19
|
+
{ key: "API_ORIGIN", value: "https://example.test", is_secret: false },
|
|
20
|
+
{ key: "SERVICE_TOKEN", value: "<secret>", is_secret: true },
|
|
21
|
+
],
|
|
22
|
+
remove: [],
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
Keys are case-sensitive. Do not repeat a key or put it in both lists. Only listed keys change. Mark sensitive values with `is_secret: true` and do not echo them in prose or logs. The tool deliberately cannot read values from arbitrary environment variables or files. For secrets that should never enter model context, use the Sites settings UI instead.
|
package/dist/src/docs/index.md
CHANGED
|
@@ -4,17 +4,17 @@ Private beta API. Read `workflow`, then the relevant topic. `resource.action` re
|
|
|
4
4
|
|
|
5
5
|
Call `sites` with `{resource, action, params}`. Omitted `project_id` uses `.openai/hosting.json`. `params.project_dir` selects another project root. Copy IDs and cursors unchanged.
|
|
6
6
|
|
|
7
|
-
| Topic
|
|
8
|
-
|
|
9
|
-
| `site`
|
|
10
|
-
| `version`
|
|
11
|
-
| `deployment`
|
|
12
|
-
| `access`
|
|
13
|
-
| `environment` | `environment`: `get`, `update`
|
|
14
|
-
| `domains`
|
|
15
|
-
| `analytics`
|
|
16
|
-
| `diagnostics` | `diagnostics`: `logs`
|
|
17
|
-
| `database`
|
|
18
|
-
| `schedules`
|
|
7
|
+
| Topic | Resource actions |
|
|
8
|
+
| ------------- | --------------------------------------------------- |
|
|
9
|
+
| `site` | `site`: `list`, `get`, `create`, `update`, `slug` |
|
|
10
|
+
| `version` | `version`: `list`, `get`, `save`, `publish_private` |
|
|
11
|
+
| `deployment` | `deployment`: `deploy`, `status` |
|
|
12
|
+
| `access` | `access`: `get`, `update` |
|
|
13
|
+
| `environment` | `environment`: `get`, `update` |
|
|
14
|
+
| `domains` | `domain`: `list`, `add`, `refresh`, `remove` |
|
|
15
|
+
| `analytics` | `analytics`: `overview`, `events`, `query` |
|
|
16
|
+
| `diagnostics` | `diagnostics`: `logs` |
|
|
17
|
+
| `database` | `database`: `overview`, `rows` |
|
|
18
|
+
| `schedules` | `schedule`: `create`, `validate` |
|
|
19
19
|
|
|
20
20
|
`building` covers build, storage and connector boundaries. `mcp` covers Site-hosted tools and connection. OAuth, Git credentials, secret environment values and service-access tokens are redacted.
|
package/dist/src/facade.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import type { SitesClient } from "./client.js";
|
|
2
|
-
export declare function call(request: unknown, client: Pick<SitesClient, "schema" | "call">, cwd: string, signal?: AbortSignal): Promise<
|
|
3
|
-
ok: boolean;
|
|
4
|
-
operation: string;
|
|
5
|
-
result: unknown;
|
|
6
|
-
}>;
|
|
2
|
+
export declare function call(request: unknown, client: Pick<SitesClient, "schema" | "call">, cwd: string, signal?: AbortSignal): Promise<unknown>;
|
|
7
3
|
export declare function documentation(input: string | undefined, client: Pick<SitesClient, "schema">): Promise<string>;
|
package/dist/src/facade.js
CHANGED
|
@@ -20,11 +20,7 @@ export async function call(request, client, cwd, signal) {
|
|
|
20
20
|
validateAgainstSchema(prepared.args, await client.schema(prepared.tool), prepared.allowedExtra);
|
|
21
21
|
const raw = await client.call(prepared.tool, prepared.args);
|
|
22
22
|
const completed = await prepared.after(raw);
|
|
23
|
-
return
|
|
24
|
-
ok: true,
|
|
25
|
-
operation: operation.key,
|
|
26
|
-
result: redact(selectResult(operation, completed)),
|
|
27
|
-
};
|
|
23
|
+
return redact(selectResult(operation, completed));
|
|
28
24
|
}
|
|
29
25
|
finally {
|
|
30
26
|
await prepared.cleanup();
|
package/dist/src/redact.js
CHANGED
|
@@ -43,7 +43,7 @@ function redactValue(value, seen) {
|
|
|
43
43
|
function redactString(value) {
|
|
44
44
|
return value
|
|
45
45
|
.replace(/(https?:\/\/)[^/@\s:]+:[^/@\s]+@/gi, "$1[redacted]@")
|
|
46
|
-
.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._
|
|
46
|
+
.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/-]+=*/gi, "$1 [redacted]")
|
|
47
47
|
.replace(/([?&](?:token|access_token|key|signature|sig)=)[^&#\s]+/gi, "$1[redacted]");
|
|
48
48
|
}
|
|
49
49
|
export function boundedJson(value, maxBytes = 32_000) {
|
package/package.json
CHANGED
|
@@ -1,61 +1,62 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
2
|
+
"name": "@howaboua/pi-chatgpt-sites",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "ChatGPT Sites management for Pi, Code Mode and Notebook",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/IgorWarzocha/howaboua-pi-stuff.git",
|
|
10
|
+
"directory": "packages/pi-chatgpt-sites"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"CHANGELOG.md"
|
|
17
|
+
],
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"pi": {
|
|
27
|
+
"extensions": [
|
|
28
|
+
"./dist/index.js"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=22.19.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "node scripts/build.mjs",
|
|
36
|
+
"check": "bun run lint && bun run typecheck",
|
|
37
|
+
"lint": "bun run format:check && oxlint --type-aware",
|
|
38
|
+
"typecheck": "tsrs --noEmit",
|
|
39
|
+
"prepack": "bun run check && bun run build",
|
|
40
|
+
"pack:dry": "npm pack --dry-run",
|
|
41
|
+
"format:check": "oxfmt --check '**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,json,jsonc,json5,css}'"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@earendil-works/pi-coding-agent": ">=1.5.0",
|
|
45
|
+
"@earendil-works/pi-tui": ">=1.0.0",
|
|
46
|
+
"@howaboua/pi-codex-conversion": ">=5.0.1"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"@howaboua/pi-codex-conversion": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@howaboua/pi-codex-conversion": "5.0.1"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@earendil-works/pi-schema": "1.5.2"
|
|
61
|
+
}
|
|
61
62
|
}
|
package/changelog.ts
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
// Generated extension packages copy this file during changelog:extensions.
|
|
2
|
-
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
5
|
-
import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
6
|
-
import { dirname, join } from "node:path";
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
-
import {
|
|
9
|
-
DynamicBorder,
|
|
10
|
-
type ExtensionAPI,
|
|
11
|
-
getAgentDir,
|
|
12
|
-
getMarkdownTheme,
|
|
13
|
-
} from "@earendil-works/pi-coding-agent";
|
|
14
|
-
import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
|
|
15
|
-
|
|
16
|
-
const ENTRY_TYPE = "@howaboua/pi-stuff/changelog";
|
|
17
|
-
const REGISTRATION_CHANNEL = "@howaboua/pi-stuff/changelog/register/v1";
|
|
18
|
-
const STATE_FILENAME = "howaboua-pi-stuff-changelog.json";
|
|
19
|
-
const SUPPRESS_KEY = "suppress";
|
|
20
|
-
const LOCK_STALE_MS = 30_000;
|
|
21
|
-
const LOCK_TIMEOUT_MS = 2_000;
|
|
22
|
-
|
|
23
|
-
interface PackageMetadata {
|
|
24
|
-
name: string;
|
|
25
|
-
version: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface PackageRegistration extends PackageMetadata {
|
|
29
|
-
changelogPath: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface RegistrationEvent {
|
|
33
|
-
accept: () => void;
|
|
34
|
-
registration: PackageRegistration;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface ChangelogEntry {
|
|
38
|
-
content: string;
|
|
39
|
-
version: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface ChangelogEntryData {
|
|
43
|
-
markdown: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
type ChangelogState = Record<string, boolean | string>;
|
|
47
|
-
|
|
48
|
-
function packageRegistration(): PackageRegistration {
|
|
49
|
-
const packageDirectory = fileURLToPath(new URL(".", import.meta.url));
|
|
50
|
-
const metadata = JSON.parse(
|
|
51
|
-
readFileSync(join(packageDirectory, "package.json"), "utf8"),
|
|
52
|
-
) as Partial<PackageMetadata>;
|
|
53
|
-
if (typeof metadata.name !== "string" || typeof metadata.version !== "string")
|
|
54
|
-
throw new Error(`Invalid package metadata in ${packageDirectory}`);
|
|
55
|
-
return {
|
|
56
|
-
name: metadata.name,
|
|
57
|
-
version: metadata.version,
|
|
58
|
-
changelogPath: join(packageDirectory, "CHANGELOG.md"),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function isRegistrationEvent(value: unknown): value is RegistrationEvent {
|
|
63
|
-
if (!value || typeof value !== "object") return false;
|
|
64
|
-
const event = value as Partial<RegistrationEvent>;
|
|
65
|
-
return (
|
|
66
|
-
typeof event.accept === "function" &&
|
|
67
|
-
typeof event.registration?.name === "string" &&
|
|
68
|
-
typeof event.registration.version === "string" &&
|
|
69
|
-
typeof event.registration.changelogPath === "string"
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function parseChangelog(markdown: string): ChangelogEntry[] {
|
|
74
|
-
const entries: ChangelogEntry[] = [];
|
|
75
|
-
let currentLines: string[] = [];
|
|
76
|
-
let currentVersion: string | undefined;
|
|
77
|
-
|
|
78
|
-
for (const line of markdown.split("\n")) {
|
|
79
|
-
const version = line.match(/^##\s+\[?(\d+\.\d+\.\d+)\]?(?:\s.*)?$/)?.[1];
|
|
80
|
-
if (version) {
|
|
81
|
-
if (currentVersion)
|
|
82
|
-
entries.push({
|
|
83
|
-
content: currentLines.join("\n").trim(),
|
|
84
|
-
version: currentVersion,
|
|
85
|
-
});
|
|
86
|
-
currentVersion = version;
|
|
87
|
-
currentLines = [line];
|
|
88
|
-
} else if (currentVersion) {
|
|
89
|
-
currentLines.push(line);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (currentVersion)
|
|
94
|
-
entries.push({
|
|
95
|
-
content: currentLines.join("\n").trim(),
|
|
96
|
-
version: currentVersion,
|
|
97
|
-
});
|
|
98
|
-
return entries;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function compareVersions(left: string, right: string): number {
|
|
102
|
-
const leftParts = left.split(".").map(Number);
|
|
103
|
-
const rightParts = right.split(".").map(Number);
|
|
104
|
-
for (let index = 0; index < 3; index++) {
|
|
105
|
-
const difference = (leftParts[index] ?? 0) - (rightParts[index] ?? 0);
|
|
106
|
-
if (difference !== 0) return difference;
|
|
107
|
-
}
|
|
108
|
-
return 0;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function isStableVersion(version: string): boolean {
|
|
112
|
-
return /^\d+\.\d+\.\d+$/.test(version);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function statePath(): string {
|
|
116
|
-
return join(getAgentDir(), STATE_FILENAME);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function readState(path: string): Promise<ChangelogState> {
|
|
120
|
-
let text: string;
|
|
121
|
-
try {
|
|
122
|
-
text = await readFile(path, "utf8");
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return {};
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
const parsed = JSON.parse(text) as unknown;
|
|
128
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
129
|
-
throw new Error(`${path} must contain a JSON object`);
|
|
130
|
-
for (const [name, value] of Object.entries(parsed)) {
|
|
131
|
-
if (name === SUPPRESS_KEY) {
|
|
132
|
-
if (typeof value !== "boolean")
|
|
133
|
-
throw new Error(`${path} ${SUPPRESS_KEY} must be a boolean`);
|
|
134
|
-
} else if (typeof value !== "string") {
|
|
135
|
-
throw new Error(`${path} version for ${name} must be a string`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return parsed as ChangelogState;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function acquireLock(path: string): Promise<() => Promise<void>> {
|
|
142
|
-
const deadline = Date.now() + LOCK_TIMEOUT_MS;
|
|
143
|
-
while (true) {
|
|
144
|
-
try {
|
|
145
|
-
await mkdir(path);
|
|
146
|
-
return () => rm(path, { force: true, recursive: true });
|
|
147
|
-
} catch (error) {
|
|
148
|
-
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
149
|
-
const info = await stat(path).catch(() => undefined);
|
|
150
|
-
if (info && Date.now() - info.mtimeMs > LOCK_STALE_MS) {
|
|
151
|
-
await rm(path, { force: true, recursive: true });
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (Date.now() >= deadline)
|
|
155
|
-
throw new Error(`Timed out waiting for ${path}`);
|
|
156
|
-
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async function writeState(path: string, state: ChangelogState): Promise<void> {
|
|
162
|
-
await mkdir(dirname(path), { mode: 0o700, recursive: true });
|
|
163
|
-
const temporaryPath = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
164
|
-
try {
|
|
165
|
-
const ordered = Object.fromEntries(
|
|
166
|
-
Object.entries(state).sort(([left], [right]) =>
|
|
167
|
-
left.localeCompare(right),
|
|
168
|
-
),
|
|
169
|
-
);
|
|
170
|
-
await writeFile(temporaryPath, `${JSON.stringify(ordered, null, 2)}\n`, {
|
|
171
|
-
encoding: "utf8",
|
|
172
|
-
mode: 0o600,
|
|
173
|
-
});
|
|
174
|
-
await rename(temporaryPath, path);
|
|
175
|
-
} catch (error) {
|
|
176
|
-
await rm(temporaryPath, { force: true });
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function packageMarkdown(
|
|
182
|
-
registration: PackageRegistration,
|
|
183
|
-
entries: ChangelogEntry[],
|
|
184
|
-
): string {
|
|
185
|
-
const body = (entry: ChangelogEntry) =>
|
|
186
|
-
entry.content
|
|
187
|
-
.replace(/^##[^\n]*\n*/, "")
|
|
188
|
-
.replace(/^###\s+(?:Changes|Minor Changes|Patch Changes)\s*\n*/gim, "")
|
|
189
|
-
.replace(/^###\s+(.+)$/gm, "**$1**");
|
|
190
|
-
if (entries.length === 1) {
|
|
191
|
-
const [entry] = entries;
|
|
192
|
-
if (!entry) return "";
|
|
193
|
-
return `## ${registration.name} ${entry.version}\n\n${body(entry)}`;
|
|
194
|
-
}
|
|
195
|
-
return [
|
|
196
|
-
`## ${registration.name}`,
|
|
197
|
-
...entries.map((entry) => `**${entry.version}**\n\n${body(entry)}`),
|
|
198
|
-
].join("\n\n");
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async function claimUpdates(
|
|
202
|
-
registrations: Iterable<PackageRegistration>,
|
|
203
|
-
): Promise<{ errors: string[]; markdown?: string }> {
|
|
204
|
-
const stableRegistrations = [...registrations]
|
|
205
|
-
.filter((registration) => isStableVersion(registration.version))
|
|
206
|
-
.sort((left, right) => left.name.localeCompare(right.name));
|
|
207
|
-
if (stableRegistrations.length === 0) return { errors: [] };
|
|
208
|
-
const path = statePath();
|
|
209
|
-
await mkdir(dirname(path), { mode: 0o700, recursive: true });
|
|
210
|
-
const release = await acquireLock(`${path}.lock`);
|
|
211
|
-
try {
|
|
212
|
-
const state = await readState(path);
|
|
213
|
-
const errors: string[] = [];
|
|
214
|
-
const sections: string[] = [];
|
|
215
|
-
let changed = false;
|
|
216
|
-
if (state[SUPPRESS_KEY] === true) {
|
|
217
|
-
for (const registration of stableRegistrations) {
|
|
218
|
-
const seenVersion = state[registration.name];
|
|
219
|
-
if (
|
|
220
|
-
typeof seenVersion !== "string" ||
|
|
221
|
-
compareVersions(registration.version, seenVersion) > 0
|
|
222
|
-
) {
|
|
223
|
-
state[registration.name] = registration.version;
|
|
224
|
-
changed = true;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (changed) await writeState(path, state);
|
|
228
|
-
return { errors };
|
|
229
|
-
}
|
|
230
|
-
for (const registration of stableRegistrations) {
|
|
231
|
-
const seenVersion = state[registration.name];
|
|
232
|
-
if (
|
|
233
|
-
typeof seenVersion === "string" &&
|
|
234
|
-
compareVersions(registration.version, seenVersion) <= 0
|
|
235
|
-
)
|
|
236
|
-
continue;
|
|
237
|
-
try {
|
|
238
|
-
const entries = parseChangelog(
|
|
239
|
-
await readFile(registration.changelogPath, "utf8"),
|
|
240
|
-
).filter(
|
|
241
|
-
(entry) =>
|
|
242
|
-
compareVersions(entry.version, registration.version) <= 0 &&
|
|
243
|
-
(typeof seenVersion === "string"
|
|
244
|
-
? compareVersions(entry.version, seenVersion) > 0
|
|
245
|
-
: entry.version === registration.version),
|
|
246
|
-
);
|
|
247
|
-
if (entries.length === 0) {
|
|
248
|
-
errors.push(
|
|
249
|
-
`No ${registration.version} changelog entry found for ${registration.name}`,
|
|
250
|
-
);
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
sections.push(packageMarkdown(registration, entries));
|
|
254
|
-
state[registration.name] = registration.version;
|
|
255
|
-
changed = true;
|
|
256
|
-
} catch (error) {
|
|
257
|
-
errors.push(
|
|
258
|
-
`Could not read the ${registration.name} changelog: ${error instanceof Error ? error.message : String(error)}`,
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (changed) await writeState(path, state);
|
|
263
|
-
return {
|
|
264
|
-
errors,
|
|
265
|
-
...(sections.length > 0 ? { markdown: sections.join("\n\n") } : {}),
|
|
266
|
-
};
|
|
267
|
-
} finally {
|
|
268
|
-
await release();
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function registerCoordinator(
|
|
273
|
-
pi: ExtensionAPI,
|
|
274
|
-
registration: PackageRegistration,
|
|
275
|
-
): void {
|
|
276
|
-
let accepted = false;
|
|
277
|
-
pi.events.emit(REGISTRATION_CHANNEL, {
|
|
278
|
-
registration,
|
|
279
|
-
accept: () => {
|
|
280
|
-
accepted = true;
|
|
281
|
-
},
|
|
282
|
-
} satisfies RegistrationEvent);
|
|
283
|
-
if (accepted) return;
|
|
284
|
-
|
|
285
|
-
const registrations = new Map([[registration.name, registration]]);
|
|
286
|
-
pi.events.on(REGISTRATION_CHANNEL, (value) => {
|
|
287
|
-
if (!isRegistrationEvent(value)) return;
|
|
288
|
-
registrations.set(value.registration.name, value.registration);
|
|
289
|
-
value.accept();
|
|
290
|
-
});
|
|
291
|
-
pi.registerEntryRenderer<ChangelogEntryData>(
|
|
292
|
-
ENTRY_TYPE,
|
|
293
|
-
(entry, _options, theme) => {
|
|
294
|
-
if (!entry.data) return undefined;
|
|
295
|
-
const container = new Container();
|
|
296
|
-
container.addChild(new DynamicBorder());
|
|
297
|
-
container.addChild(
|
|
298
|
-
new Text(theme.bold(theme.fg("accent", "What's New")), 1, 0),
|
|
299
|
-
);
|
|
300
|
-
container.addChild(new Spacer(1));
|
|
301
|
-
container.addChild(
|
|
302
|
-
new Markdown(entry.data.markdown.trim(), 1, 0, getMarkdownTheme()),
|
|
303
|
-
);
|
|
304
|
-
container.addChild(new Spacer(1));
|
|
305
|
-
container.addChild(new DynamicBorder());
|
|
306
|
-
return container;
|
|
307
|
-
},
|
|
308
|
-
);
|
|
309
|
-
pi.on("session_start", async (event, ctx) => {
|
|
310
|
-
if (event.reason === "reload" || ctx.mode !== "tui") return;
|
|
311
|
-
if (
|
|
312
|
-
ctx.sessionManager
|
|
313
|
-
.getEntries()
|
|
314
|
-
.some((entry) =>
|
|
315
|
-
["branch_summary", "compaction", "message"].includes(entry.type),
|
|
316
|
-
)
|
|
317
|
-
)
|
|
318
|
-
return;
|
|
319
|
-
try {
|
|
320
|
-
const update = await claimUpdates(registrations.values());
|
|
321
|
-
if (update.markdown)
|
|
322
|
-
pi.appendEntry<ChangelogEntryData>(ENTRY_TYPE, {
|
|
323
|
-
markdown: update.markdown,
|
|
324
|
-
});
|
|
325
|
-
for (const error of update.errors) ctx.ui.notify(error, "warning");
|
|
326
|
-
} catch (error) {
|
|
327
|
-
ctx.ui.notify(
|
|
328
|
-
`Could not update Howaboua changelog state: ${error instanceof Error ? error.message : String(error)}`,
|
|
329
|
-
"warning",
|
|
330
|
-
);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export default function howabouaPackageChangelog(pi: ExtensionAPI): void {
|
|
336
|
-
registerCoordinator(pi, packageRegistration());
|
|
337
|
-
}
|