htmlhost-cli 2.4.0 → 2.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.
- package/README.md +11 -0
- package/package.json +1 -1
- package/src/cli.mjs +11 -1
- package/src/commands/agents.mjs +95 -0
- package/src/commands/clone.mjs +8 -0
- package/src/commands/deploy.mjs +19 -0
package/README.md
CHANGED
|
@@ -131,6 +131,17 @@ push changes and `htmlhost pull` to sync remote edits.
|
|
|
131
131
|
|
|
132
132
|
Use `--force` to overwrite an existing non-empty directory.
|
|
133
133
|
|
|
134
|
+
### `htmlhost agents [dir] [options]`
|
|
135
|
+
Teach your AI coding tool (Claude Code, Codex, Cursor, Copilot…) how htmlhost works: static hosting rules, this CLI, and how to build forms that deliver to your inbox. Writes a managed block into `AGENTS.md` (your own content is kept) and adds an `@AGENTS.md` import to `CLAUDE.md`. `clone` adds it automatically, and `deploy` keeps it current. Agent files are never deployed.
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
htmlhost agents # add or refresh
|
|
139
|
+
htmlhost agents --print # print the guide instead
|
|
140
|
+
htmlhost agents --no-claude # don't touch CLAUDE.md
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The same guide is at https://htmlhost.co/agents.md.
|
|
144
|
+
|
|
134
145
|
### `htmlhost list`
|
|
135
146
|
List all your sites with titles, sizes, TTL, and expiry. Multi-page sites are marked with 📄.
|
|
136
147
|
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { bold, dim, cyan, err } from "./ui.mjs";
|
|
|
5
5
|
import { ApiError } from "./api.mjs";
|
|
6
6
|
import { startUpdateCheck, applyUpdate } from "./update.mjs";
|
|
7
7
|
|
|
8
|
-
const VERSION = "2.
|
|
8
|
+
const VERSION = "2.5.0";
|
|
9
9
|
|
|
10
10
|
const HELP = `
|
|
11
11
|
${bold("htmlhost")} ${dim(`v${VERSION}`)} — deploy HTML from the terminal
|
|
@@ -15,6 +15,7 @@ const HELP = `
|
|
|
15
15
|
${cyan("htmlhost upload")} <file|dir...> [opts] Upload media file or directory
|
|
16
16
|
${cyan("htmlhost pull")} [slug] [opts] Pull remote changes to local
|
|
17
17
|
${cyan("htmlhost clone")} <slug> [dir] Clone a site to a local directory
|
|
18
|
+
${cyan("htmlhost agents")} [dir] Teach your AI coding tool htmlhost (AGENTS.md)
|
|
18
19
|
${cyan("htmlhost list")} List your sites
|
|
19
20
|
${cyan("htmlhost delete")} <slug> Delete a site
|
|
20
21
|
${cyan("htmlhost login")} Authenticate with an API token
|
|
@@ -39,6 +40,10 @@ const HELP = `
|
|
|
39
40
|
--force, -f Pull without confirmation prompt
|
|
40
41
|
--dry-run Show what would change without writing
|
|
41
42
|
|
|
43
|
+
${bold("Agents options:")}
|
|
44
|
+
--print Print the guide instead of writing files
|
|
45
|
+
--no-claude Don't add the @AGENTS.md import to CLAUDE.md
|
|
46
|
+
|
|
42
47
|
${bold("Delete options:")}
|
|
43
48
|
--force, -f Skip confirmation prompt
|
|
44
49
|
|
|
@@ -128,6 +133,11 @@ export async function run(argv) {
|
|
|
128
133
|
await clone(args);
|
|
129
134
|
break;
|
|
130
135
|
}
|
|
136
|
+
case "agents": {
|
|
137
|
+
const { agents } = await import("./commands/agents.mjs");
|
|
138
|
+
await agents(args);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
131
141
|
case "list":
|
|
132
142
|
case "ls": {
|
|
133
143
|
const { list } = await import("./commands/list.mjs");
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* htmlhost agents [dir] [--print] [--no-claude]
|
|
3
|
+
*
|
|
4
|
+
* Write htmlhost's instructions for AI coding agents (hosting rules, CLI, forms)
|
|
5
|
+
* into the project's AGENTS.md, so tools like Codex, Cursor, Copilot and Claude
|
|
6
|
+
* Code build features that work on htmlhost. The guide is fetched from
|
|
7
|
+
* https://htmlhost.co/agents.md so it's always current.
|
|
8
|
+
*
|
|
9
|
+
* Only a marked block is managed: anything else in AGENTS.md is left alone,
|
|
10
|
+
* and running the command again replaces just that block. Claude Code reads
|
|
11
|
+
* CLAUDE.md rather than AGENTS.md, so an `@AGENTS.md` import is added there too.
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
14
|
+
import { join, resolve } from "node:path";
|
|
15
|
+
import { getApi } from "../config.mjs";
|
|
16
|
+
import { ok, err, dim, cyan } from "../ui.mjs";
|
|
17
|
+
|
|
18
|
+
const START = "<!-- htmlhost:agents:start — managed by `htmlhost agents`; edits inside this block are replaced -->";
|
|
19
|
+
const END = "<!-- htmlhost:agents:end -->";
|
|
20
|
+
const BLOCK_RE = /<!-- htmlhost:agents:start[^>]*-->[\s\S]*?<!-- htmlhost:agents:end -->/;
|
|
21
|
+
|
|
22
|
+
/** Fetch the current guide. Throws on network or HTTP failure. */
|
|
23
|
+
export async function fetchAgentGuide(timeoutMs = 10000) {
|
|
24
|
+
const res = await fetch(`${getApi()}/agents.md`, { signal: AbortSignal.timeout(timeoutMs) });
|
|
25
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
26
|
+
return (await res.text()).trim();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Whether a project already carries the managed block. */
|
|
30
|
+
export function hasAgentGuide(dir) {
|
|
31
|
+
const path = join(dir, "AGENTS.md");
|
|
32
|
+
return existsSync(path) && BLOCK_RE.test(readFileSync(path, "utf8"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Write (or refresh) the guide in `dir`. Returns what changed, for reporting.
|
|
37
|
+
* `claude: false` leaves CLAUDE.md untouched.
|
|
38
|
+
*/
|
|
39
|
+
export function writeAgentGuide(dir, guide, { claude = true } = {}) {
|
|
40
|
+
const changed = [];
|
|
41
|
+
const block = `${START}\n${guide}\n${END}`;
|
|
42
|
+
|
|
43
|
+
const agentsPath = join(dir, "AGENTS.md");
|
|
44
|
+
const before = existsSync(agentsPath) ? readFileSync(agentsPath, "utf8") : null;
|
|
45
|
+
const after = before === null
|
|
46
|
+
? `${block}\n`
|
|
47
|
+
: BLOCK_RE.test(before)
|
|
48
|
+
? before.replace(BLOCK_RE, () => block)
|
|
49
|
+
: `${before.replace(/\s*$/, "")}\n\n${block}\n`;
|
|
50
|
+
if (after !== before) {
|
|
51
|
+
writeFileSync(agentsPath, after, "utf8");
|
|
52
|
+
changed.push(before === null ? "created AGENTS.md" : "updated AGENTS.md");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (claude) {
|
|
56
|
+
const claudePath = join(dir, "CLAUDE.md");
|
|
57
|
+
const current = existsSync(claudePath) ? readFileSync(claudePath, "utf8") : null;
|
|
58
|
+
if (current === null) {
|
|
59
|
+
writeFileSync(claudePath, "@AGENTS.md\n", "utf8");
|
|
60
|
+
changed.push("created CLAUDE.md (imports AGENTS.md)");
|
|
61
|
+
} else if (!/@AGENTS\.md\b/.test(current)) {
|
|
62
|
+
writeFileSync(claudePath, `${current.replace(/\s*$/, "")}\n\n@AGENTS.md\n`, "utf8");
|
|
63
|
+
changed.push("added @AGENTS.md to CLAUDE.md");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return changed;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function agents(args) {
|
|
70
|
+
const positionals = args.filter((a) => !a.startsWith("-"));
|
|
71
|
+
const dir = resolve(positionals[0] || ".");
|
|
72
|
+
const print = args.includes("--print");
|
|
73
|
+
|
|
74
|
+
let guide;
|
|
75
|
+
try {
|
|
76
|
+
guide = await fetchAgentGuide();
|
|
77
|
+
} catch (e) {
|
|
78
|
+
err(`Couldn't download the agent guide from ${getApi()}/agents.md (${e.message}).`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (print) {
|
|
83
|
+
console.log(guide);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const changed = writeAgentGuide(dir, guide, { claude: !args.includes("--no-claude") });
|
|
88
|
+
if (changed.length === 0) {
|
|
89
|
+
ok("AI agent instructions are already up to date.");
|
|
90
|
+
} else {
|
|
91
|
+
ok(`AI agent instructions ${changed.join(", ")}.`);
|
|
92
|
+
}
|
|
93
|
+
console.log(` ${dim("Your AI coding tool now knows how htmlhost hosting and forms work.")}`);
|
|
94
|
+
console.log(` ${dim("Refresh any time with")} ${cyan("htmlhost agents")}${dim(". These files are never deployed.")}`);
|
|
95
|
+
}
|
package/src/commands/clone.mjs
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
10
10
|
import { join, dirname, resolve } from "node:path";
|
|
11
11
|
import { get, downloadBuffer } from "../api.mjs";
|
|
12
|
+
import { fetchAgentGuide, writeAgentGuide } from "./agents.mjs";
|
|
12
13
|
import {
|
|
13
14
|
ok,
|
|
14
15
|
err,
|
|
@@ -164,6 +165,12 @@ export async function clone(args) {
|
|
|
164
165
|
const linkPath = join(destDir, LINK_FILE);
|
|
165
166
|
writeFileSync(linkPath, JSON.stringify(linkData, null, 2) + "\n", "utf8");
|
|
166
167
|
|
|
168
|
+
// Teach the user's AI coding tool how htmlhost works. Best-effort: a
|
|
169
|
+
// failed download mustn't fail the clone.
|
|
170
|
+
const agentsWritten = await fetchAgentGuide(5000)
|
|
171
|
+
.then((guide) => writeAgentGuide(destDir, guide).length > 0)
|
|
172
|
+
.catch(() => false);
|
|
173
|
+
|
|
167
174
|
// --- Done ---
|
|
168
175
|
console.log("");
|
|
169
176
|
console.log(` ${green("━".repeat(40))}`);
|
|
@@ -174,5 +181,6 @@ export async function clone(args) {
|
|
|
174
181
|
console.log("");
|
|
175
182
|
console.log(` ${dim("Deploy changes:")} ${cyan("htmlhost deploy")}`);
|
|
176
183
|
console.log(` ${dim("Pull updates:")} ${cyan("htmlhost pull")}`);
|
|
184
|
+
if (agentsWritten) console.log(` ${dim("AI agent guide:")} ${cyan("AGENTS.md")} ${dim("(not deployed)")}`);
|
|
177
185
|
console.log("");
|
|
178
186
|
}
|
package/src/commands/deploy.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { createHash } from "node:crypto";
|
|
|
5
5
|
import { post } from "../api.mjs";
|
|
6
6
|
import { ok, err, info, warn, cyan, dim, bold, yellow, green, formatBytes, mimeFromExt } from "../ui.mjs";
|
|
7
7
|
import { checkRemoteChanges } from "./pull.mjs";
|
|
8
|
+
import { fetchAgentGuide, hasAgentGuide, writeAgentGuide } from "./agents.mjs";
|
|
8
9
|
|
|
9
10
|
const LINK_FILE = ".htmlhost";
|
|
10
11
|
|
|
@@ -68,6 +69,15 @@ const DEFAULT_IGNORE = [
|
|
|
68
69
|
"package-lock.json",
|
|
69
70
|
"yarn.lock",
|
|
70
71
|
"pnpm-lock.yaml",
|
|
72
|
+
// Instructions for AI coding tools — private to the project, never published.
|
|
73
|
+
"AGENTS.md",
|
|
74
|
+
"CLAUDE.md",
|
|
75
|
+
"GEMINI.md",
|
|
76
|
+
".claude",
|
|
77
|
+
".cursor",
|
|
78
|
+
".cursorrules",
|
|
79
|
+
".windsurfrules",
|
|
80
|
+
".github",
|
|
71
81
|
];
|
|
72
82
|
|
|
73
83
|
/**
|
|
@@ -342,6 +352,10 @@ async function deployDirectory(dirPath, { ttl, title, slug: explicitSlug, forceN
|
|
|
342
352
|
}
|
|
343
353
|
}
|
|
344
354
|
|
|
355
|
+
// Keep an existing AI agent guide current (downloaded alongside the deploy).
|
|
356
|
+
const hadAgentGuide = hasAgentGuide(dirPath);
|
|
357
|
+
const agentGuide = hadAgentGuide && !json ? fetchAgentGuide(5000).catch(() => null) : Promise.resolve(null);
|
|
358
|
+
|
|
345
359
|
// Read existing link data
|
|
346
360
|
const link = readLink(dirPath);
|
|
347
361
|
let existingSlug = explicitSlug || (!forceNew && link?.multipage?.slug) || null;
|
|
@@ -557,6 +571,11 @@ async function deployDirectory(dirPath, { ttl, title, slug: explicitSlug, forceN
|
|
|
557
571
|
}
|
|
558
572
|
console.log("");
|
|
559
573
|
console.log(` ${dim("Linked → .htmlhost")}`);
|
|
574
|
+
const guide = await agentGuide;
|
|
575
|
+
if (guide) writeAgentGuide(dirPath, guide, { claude: false });
|
|
576
|
+
else if (!hadAgentGuide) {
|
|
577
|
+
console.log(` ${dim("Building with AI? Run")} ${cyan("htmlhost agents")} ${dim("so your coding tool knows how htmlhost forms and hosting work.")}`);
|
|
578
|
+
}
|
|
560
579
|
console.log("");
|
|
561
580
|
} catch (e) {
|
|
562
581
|
err(`Deploy failed: ${e.message}`);
|