hicreator-agent 0.1.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/LICENSE +21 -0
- package/README.md +48 -0
- package/bin/hicreator-agent.js +5 -0
- package/package.json +41 -0
- package/skills/hicreator/SKILL.md +35 -0
- package/skills/hicreator/agents/openai.yaml +4 -0
- package/src/cli.js +160 -0
- package/src/configure.js +120 -0
- package/src/constants.js +7 -0
- package/src/files.js +44 -0
- package/src/install-skill.js +154 -0
- package/src/mcp-check.js +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hiCreator
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# hiCreator Agent
|
|
2
|
+
|
|
3
|
+
Install one hiCreator skill and remote MCP connection for Codex, Claude Code, and Cursor. It provides AI creator search, similar-creator search, email lookup, folder creation, folder listing, and batch save.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js 20 or newer.
|
|
8
|
+
- A hiCreator Developer API key beginning with `hc_`.
|
|
9
|
+
- Codex, Claude Code, or Cursor installed locally.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx --yes --prefer-online hicreator-agent@latest setup
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The installer detects supported clients, asks for the API key without echoing it, verifies the remote MCP connection without making a paid call, installs the skill, and merges a `hicreator` MCP entry into each user configuration.
|
|
18
|
+
|
|
19
|
+
To choose clients explicitly:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx --yes --prefer-online hicreator-agent@latest setup --clients codex,claude,cursor
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The API key is stored only in the selected clients' local configuration files. The installer applies owner-only file permissions and never includes the key in command arguments or output.
|
|
26
|
+
|
|
27
|
+
## Updates
|
|
28
|
+
|
|
29
|
+
The skill runs this once at the start of each hiCreator workflow:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx --yes --prefer-online hicreator-agent@latest prepare --json
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`prepare` compares the bundled version and checksum, repairs missing or modified files, and atomically replaces older skill files. MCP business logic runs remotely and updates immediately when hiCreator deploys it.
|
|
36
|
+
|
|
37
|
+
## Billing
|
|
38
|
+
|
|
39
|
+
AI search, similar-creator search, and email lookup consume hiCreator credits. The skill never automatically retries those tools. Creating, listing, and adding existing creators to folders are free.
|
|
40
|
+
|
|
41
|
+
## Local Files
|
|
42
|
+
|
|
43
|
+
- hiCreator state: `~/.hicreator/manifest.json`
|
|
44
|
+
- Codex skill: `~/.codex/skills/hicreator/`
|
|
45
|
+
- Claude Code skill: `~/.claude/skills/hicreator/`
|
|
46
|
+
- Cursor skill: `~/.cursor/skills/hicreator/`
|
|
47
|
+
|
|
48
|
+
Existing unrelated MCP servers and settings are preserved.
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hicreator-agent",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Install and update the hiCreator Agent Skill and remote MCP connection.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"hicreator-agent": "bin/hicreator-agent.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src",
|
|
12
|
+
"skills"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "node --test",
|
|
16
|
+
"check": "node --check bin/hicreator-agent.js && node --check src/*.js && npm test"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Archivev/hicreator-agent.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/Archivev/hicreator-agent#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/Archivev/hicreator-agent/issues"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"hicreator",
|
|
31
|
+
"agent-skills",
|
|
32
|
+
"mcp",
|
|
33
|
+
"codex",
|
|
34
|
+
"claude-code",
|
|
35
|
+
"cursor"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hicreator
|
|
3
|
+
description: Find Instagram, YouTube, or TikTok creators, find similar creators or public contact emails, and organize creators in hiCreator folders. Use when the user asks for creator discovery, creator email lookup, or saving creator results to hiCreator.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# hiCreator
|
|
7
|
+
|
|
8
|
+
Use the hiCreator MCP tools to find and organize creators through natural language.
|
|
9
|
+
|
|
10
|
+
## Start
|
|
11
|
+
|
|
12
|
+
At the beginning of each hiCreator workflow, run:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx --yes --prefer-online hicreator-agent@latest prepare --json
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Run it once per user workflow, before the first hiCreator tool call. If it returns `updated: true`, read the `SKILL.md` at the returned `skillPath` again before continuing. If npm cannot be reached, continue with this installed Skill and do not retry the update during the same workflow. Never print, request through chat, or pass the API key on a command line.
|
|
19
|
+
|
|
20
|
+
## Workflow
|
|
21
|
+
|
|
22
|
+
1. Infer or confirm the platform, requested count, hard filters, and whether the user wants results saved.
|
|
23
|
+
2. Use `search_creators_ai` for intent-based discovery or `find_similar_creators` for a reference account.
|
|
24
|
+
3. Check returned results against hard constraints and state which constraints the data could not verify.
|
|
25
|
+
4. To save results, call `list_creator_folders`; create the destination with `create_creator_folder` only when needed; then call `add_creators_to_folder` once with stable `platform` and `creator_id` values from search results.
|
|
26
|
+
5. Call `find_creator_email` only when the user explicitly asks for an email and the selected result does not already include one.
|
|
27
|
+
6. Report returned count, verified constraints, folder result, and any per-item failures.
|
|
28
|
+
|
|
29
|
+
## Billing Safety
|
|
30
|
+
|
|
31
|
+
`search_creators_ai`, `find_similar_creators`, and `find_creator_email` consume credits. Search cost scales with `limit`; email lookup charges one lookup. State the operation and quantity before a paid call. When the user's request already specifies them, proceed without asking the same question again.
|
|
32
|
+
|
|
33
|
+
Never automatically retry a paid tool after a timeout, disconnect, or uncertain result. Tell the user the request may have been charged and ask them to inspect API history before deciding whether to retry. Never silently raise `limit`, broaden filters, run a second search, or perform email lookup.
|
|
34
|
+
|
|
35
|
+
Folder listing, creation, and batch add are free. A failed free folder operation may be retried without repeating the paid search. Do not claim support for folder deletion, rename, removal, or sharing.
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { Writable } from "node:stream";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_MCP_URL,
|
|
7
|
+
SUPPORTED_CLIENTS,
|
|
8
|
+
} from "./constants.js";
|
|
9
|
+
import {
|
|
10
|
+
configureClients,
|
|
11
|
+
detectClients,
|
|
12
|
+
parseClients,
|
|
13
|
+
} from "./configure.js";
|
|
14
|
+
import { installedClients, syncSkill } from "./install-skill.js";
|
|
15
|
+
import { verifyMcp } from "./mcp-check.js";
|
|
16
|
+
|
|
17
|
+
function parseOptions(argv) {
|
|
18
|
+
const [command, ...rest] = argv;
|
|
19
|
+
const options = { command, json: false, skipVerify: false };
|
|
20
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
21
|
+
const argument = rest[index];
|
|
22
|
+
if (argument === "--json") options.json = true;
|
|
23
|
+
else if (argument === "--skip-verify") options.skipVerify = true;
|
|
24
|
+
else if (argument === "--clients" || argument === "--mcp-url") {
|
|
25
|
+
const value = rest[index + 1];
|
|
26
|
+
if (!value) throw new Error(`${argument} requires a value.`);
|
|
27
|
+
options[argument === "--clients" ? "clients" : "mcpUrl"] = value;
|
|
28
|
+
index += 1;
|
|
29
|
+
} else if (argument === "--api-key" || argument?.startsWith("--api-key=")) {
|
|
30
|
+
throw new Error("Do not pass API keys as command arguments.");
|
|
31
|
+
} else {
|
|
32
|
+
throw new Error(`Unknown option: ${argument}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return options;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function promptForApiKey() {
|
|
39
|
+
if (!process.stdin.isTTY) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
"Set HICREATOR_API_KEY or run setup in an interactive terminal.",
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
let muted = false;
|
|
45
|
+
const output = new Writable({
|
|
46
|
+
write(chunk, encoding, callback) {
|
|
47
|
+
if (!muted) process.stderr.write(chunk, encoding);
|
|
48
|
+
callback();
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const readline = createInterface({ input: process.stdin, output, terminal: true });
|
|
52
|
+
const answerPromise = readline.question("hiCreator API key: ");
|
|
53
|
+
muted = true;
|
|
54
|
+
const answer = await answerPromise;
|
|
55
|
+
muted = false;
|
|
56
|
+
process.stderr.write("\n");
|
|
57
|
+
readline.close();
|
|
58
|
+
return answer;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function validateApiKey(value) {
|
|
62
|
+
const apiKey = value?.trim();
|
|
63
|
+
if (!/^hc_[A-Za-z0-9_-]{17,253}$/u.test(apiKey ?? "")) {
|
|
64
|
+
throw new Error("Enter a valid hiCreator Developer API key.");
|
|
65
|
+
}
|
|
66
|
+
return apiKey;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function validateMcpUrl(value) {
|
|
70
|
+
let url;
|
|
71
|
+
try {
|
|
72
|
+
url = new URL(value);
|
|
73
|
+
} catch {
|
|
74
|
+
throw new Error("Enter a valid MCP URL.");
|
|
75
|
+
}
|
|
76
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
77
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {
|
|
78
|
+
throw new Error("The MCP URL must use HTTPS unless it targets localhost.");
|
|
79
|
+
}
|
|
80
|
+
if (url.username || url.password || url.hash) {
|
|
81
|
+
throw new Error("The MCP URL cannot contain credentials or a fragment.");
|
|
82
|
+
}
|
|
83
|
+
return url.href;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function printResult(result, json) {
|
|
87
|
+
if (json) process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
88
|
+
else {
|
|
89
|
+
process.stdout.write(
|
|
90
|
+
`hiCreator ${result.version} ready for ${result.clients.join(", ")}.\n`,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function setup(options = {}) {
|
|
96
|
+
const home = options.home ?? homedir();
|
|
97
|
+
const clients = options.clients
|
|
98
|
+
?? await detectClients(options.pathValue);
|
|
99
|
+
if (clients.length === 0) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`No supported client found. Install one of: ${SUPPORTED_CLIENTS.join(", ")}.`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const apiKey = validateApiKey(
|
|
105
|
+
options.apiKey ?? process.env.HICREATOR_API_KEY ?? await promptForApiKey(),
|
|
106
|
+
);
|
|
107
|
+
const mcpUrl = validateMcpUrl(options.mcpUrl ?? DEFAULT_MCP_URL);
|
|
108
|
+
const connection = options.skipVerify
|
|
109
|
+
? null
|
|
110
|
+
: await verifyMcp(mcpUrl, apiKey);
|
|
111
|
+
const skill = await syncSkill({ home, clients });
|
|
112
|
+
const configPaths = await configureClients({
|
|
113
|
+
home,
|
|
114
|
+
clients,
|
|
115
|
+
apiKey,
|
|
116
|
+
mcpUrl,
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
...skill,
|
|
120
|
+
clients,
|
|
121
|
+
configPaths,
|
|
122
|
+
mcpUrl,
|
|
123
|
+
verified: Boolean(connection),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function prepare(options = {}) {
|
|
128
|
+
const home = options.home ?? homedir();
|
|
129
|
+
const clients = options.clients ?? await installedClients(home);
|
|
130
|
+
if (clients.length === 0) {
|
|
131
|
+
throw new Error("hiCreator is not installed. Run setup first.");
|
|
132
|
+
}
|
|
133
|
+
return syncSkill({ home, clients });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function runCli(argv) {
|
|
137
|
+
try {
|
|
138
|
+
const options = parseOptions(argv);
|
|
139
|
+
if (options.command === "setup") {
|
|
140
|
+
const result = await setup({
|
|
141
|
+
clients: options.clients ? parseClients(options.clients) : undefined,
|
|
142
|
+
mcpUrl: options.mcpUrl,
|
|
143
|
+
skipVerify: options.skipVerify,
|
|
144
|
+
});
|
|
145
|
+
printResult(result, options.json);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (options.command === "prepare") {
|
|
149
|
+
const result = await prepare();
|
|
150
|
+
printResult({ ...result, clients: Object.keys(result.targets) }, options.json);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
throw new Error(
|
|
154
|
+
"Usage: hicreator-agent <setup|prepare> [--clients codex,claude,cursor] [--json]",
|
|
155
|
+
);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
process.stderr.write(`hicreator-agent: ${error.message}\n`);
|
|
158
|
+
process.exitCode = 1;
|
|
159
|
+
}
|
|
160
|
+
}
|
package/src/configure.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { access, readFile } from "node:fs/promises";
|
|
2
|
+
import { constants as fsConstants } from "node:fs";
|
|
3
|
+
import { delimiter, join } from "node:path";
|
|
4
|
+
|
|
5
|
+
import { SERVER_NAME, SUPPORTED_CLIENTS } from "./constants.js";
|
|
6
|
+
import { readJson, writeFileAtomic, writeJsonAtomic } from "./files.js";
|
|
7
|
+
|
|
8
|
+
const CODEX_BLOCK_START = "# BEGIN hicreator-agent managed MCP";
|
|
9
|
+
const CODEX_BLOCK_END = "# END hicreator-agent managed MCP";
|
|
10
|
+
|
|
11
|
+
function tomlString(value) {
|
|
12
|
+
return JSON.stringify(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function configureCodex(home, apiKey, mcpUrl) {
|
|
16
|
+
const path = join(home, ".codex", "config.toml");
|
|
17
|
+
const existing = await readFile(path, "utf8").catch((error) => {
|
|
18
|
+
if (error?.code === "ENOENT") return "";
|
|
19
|
+
throw error;
|
|
20
|
+
});
|
|
21
|
+
const managedPattern = new RegExp(
|
|
22
|
+
`\\n?${CODEX_BLOCK_START}[\\s\\S]*?${CODEX_BLOCK_END}\\n?`,
|
|
23
|
+
"g",
|
|
24
|
+
);
|
|
25
|
+
const withoutManaged = existing.replace(managedPattern, "\n").trimEnd();
|
|
26
|
+
if (/^\[mcp_servers\.(?:hicreator|"hicreator")\]/mu.test(withoutManaged)) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
"Codex already has an unmanaged hicreator MCP entry. Remove it and run setup again.",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const block = [
|
|
32
|
+
CODEX_BLOCK_START,
|
|
33
|
+
`[mcp_servers.${SERVER_NAME}]`,
|
|
34
|
+
`url = ${tomlString(mcpUrl)}`,
|
|
35
|
+
`http_headers = { Authorization = ${tomlString(`Bearer ${apiKey}`)} }`,
|
|
36
|
+
"enabled = true",
|
|
37
|
+
CODEX_BLOCK_END,
|
|
38
|
+
].join("\n");
|
|
39
|
+
await writeFileAtomic(
|
|
40
|
+
path,
|
|
41
|
+
`${withoutManaged ? `${withoutManaged}\n\n` : ""}${block}\n`,
|
|
42
|
+
);
|
|
43
|
+
return path;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function configureClaude(home, apiKey, mcpUrl) {
|
|
47
|
+
const path = join(home, ".claude.json");
|
|
48
|
+
const config = await readJson(path, {});
|
|
49
|
+
config.mcpServers = {
|
|
50
|
+
...(config.mcpServers ?? {}),
|
|
51
|
+
[SERVER_NAME]: {
|
|
52
|
+
type: "http",
|
|
53
|
+
url: mcpUrl,
|
|
54
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
await writeJsonAtomic(path, config);
|
|
58
|
+
return path;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function configureCursor(home, apiKey, mcpUrl) {
|
|
62
|
+
const path = join(home, ".cursor", "mcp.json");
|
|
63
|
+
const config = await readJson(path, {});
|
|
64
|
+
config.mcpServers = {
|
|
65
|
+
...(config.mcpServers ?? {}),
|
|
66
|
+
[SERVER_NAME]: {
|
|
67
|
+
url: mcpUrl,
|
|
68
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
await writeJsonAtomic(path, config);
|
|
72
|
+
return path;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const configurators = {
|
|
76
|
+
codex: configureCodex,
|
|
77
|
+
claude: configureClaude,
|
|
78
|
+
cursor: configureCursor,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export async function configureClients({ home, clients, apiKey, mcpUrl }) {
|
|
82
|
+
const paths = {};
|
|
83
|
+
for (const client of clients) {
|
|
84
|
+
paths[client] = await configurators[client](home, apiKey, mcpUrl);
|
|
85
|
+
}
|
|
86
|
+
return paths;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function executableExists(command, pathValue = process.env.PATH ?? "") {
|
|
90
|
+
for (const directory of pathValue.split(delimiter)) {
|
|
91
|
+
if (!directory) continue;
|
|
92
|
+
try {
|
|
93
|
+
await access(join(directory, command), fsConstants.X_OK);
|
|
94
|
+
return true;
|
|
95
|
+
} catch {
|
|
96
|
+
// Continue through PATH entries.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function detectClients(pathValue) {
|
|
103
|
+
const detected = [];
|
|
104
|
+
for (const client of SUPPORTED_CLIENTS) {
|
|
105
|
+
if (await executableExists(client, pathValue)) detected.push(client);
|
|
106
|
+
}
|
|
107
|
+
return detected;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function parseClients(value) {
|
|
111
|
+
if (value === "all") return [...SUPPORTED_CLIENTS];
|
|
112
|
+
const clients = [...new Set(value.split(",").map((item) => item.trim())
|
|
113
|
+
.filter(Boolean))];
|
|
114
|
+
const unsupported = clients.filter((client) =>
|
|
115
|
+
!SUPPORTED_CLIENTS.includes(client));
|
|
116
|
+
if (unsupported.length > 0) {
|
|
117
|
+
throw new Error(`Unsupported clients: ${unsupported.join(", ")}`);
|
|
118
|
+
}
|
|
119
|
+
return clients;
|
|
120
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
|
|
3
|
+
export const PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
|
|
4
|
+
export const SKILL_NAME = "hicreator";
|
|
5
|
+
export const SERVER_NAME = "hicreator";
|
|
6
|
+
export const DEFAULT_MCP_URL = "https://mcp.hicreator.ai/mcp";
|
|
7
|
+
export const SUPPORTED_CLIENTS = ["codex", "claude", "cursor"];
|
package/src/files.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chmod,
|
|
3
|
+
mkdir,
|
|
4
|
+
readFile,
|
|
5
|
+
rename,
|
|
6
|
+
writeFile,
|
|
7
|
+
} from "node:fs/promises";
|
|
8
|
+
import { basename, dirname, join } from "node:path";
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
|
|
11
|
+
export async function pathExists(path) {
|
|
12
|
+
try {
|
|
13
|
+
await readFile(path);
|
|
14
|
+
return true;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (error?.code === "EISDIR") return true;
|
|
17
|
+
if (error?.code === "ENOENT") return false;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function readJson(path, fallback) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error?.code === "ENOENT") return fallback;
|
|
27
|
+
throw new Error(`Cannot read JSON config at ${path}: ${error.message}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function writeFileAtomic(path, content, mode = 0o600) {
|
|
32
|
+
await mkdir(dirname(path), { recursive: true });
|
|
33
|
+
const temporary = join(
|
|
34
|
+
dirname(path),
|
|
35
|
+
`.${basename(path)}.${process.pid}.${randomUUID()}.tmp`,
|
|
36
|
+
);
|
|
37
|
+
await writeFile(temporary, content, { mode });
|
|
38
|
+
await rename(temporary, path);
|
|
39
|
+
await chmod(path, mode);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function writeJsonAtomic(path, value, mode = 0o600) {
|
|
43
|
+
await writeFileAtomic(path, `${JSON.stringify(value, null, 2)}\n`, mode);
|
|
44
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cp,
|
|
3
|
+
mkdir,
|
|
4
|
+
readdir,
|
|
5
|
+
readFile,
|
|
6
|
+
rename,
|
|
7
|
+
rm,
|
|
8
|
+
stat,
|
|
9
|
+
} from "node:fs/promises";
|
|
10
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
11
|
+
import { basename, dirname, join } from "node:path";
|
|
12
|
+
|
|
13
|
+
import { PACKAGE_ROOT, SKILL_NAME } from "./constants.js";
|
|
14
|
+
import { pathExists, readJson, writeJsonAtomic } from "./files.js";
|
|
15
|
+
|
|
16
|
+
const LOCK_WAIT_MS = 15_000;
|
|
17
|
+
const STALE_LOCK_MS = 120_000;
|
|
18
|
+
|
|
19
|
+
export function clientSkillPath(home, client) {
|
|
20
|
+
return join(home, `.${client}`, "skills", SKILL_NAME);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function directoryChecksum(root) {
|
|
24
|
+
const hash = createHash("sha256");
|
|
25
|
+
|
|
26
|
+
async function visit(path, relative = "") {
|
|
27
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
28
|
+
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
const child = join(path, entry.name);
|
|
31
|
+
const childRelative = relative ? `${relative}/${entry.name}` : entry.name;
|
|
32
|
+
hash.update(childRelative);
|
|
33
|
+
hash.update("\0");
|
|
34
|
+
if (entry.isDirectory()) await visit(child, childRelative);
|
|
35
|
+
else hash.update(await readFile(child));
|
|
36
|
+
hash.update("\0");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await visit(root);
|
|
41
|
+
return hash.digest("hex");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function packageVersion() {
|
|
45
|
+
const packageJson = JSON.parse(
|
|
46
|
+
await readFile(join(PACKAGE_ROOT, "package.json"), "utf8"),
|
|
47
|
+
);
|
|
48
|
+
return packageJson.version;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function acquireLock(root) {
|
|
52
|
+
const lockPath = join(root, "update.lock");
|
|
53
|
+
const startedAt = Date.now();
|
|
54
|
+
while (true) {
|
|
55
|
+
try {
|
|
56
|
+
await mkdir(lockPath);
|
|
57
|
+
return async () => rm(lockPath, { recursive: true, force: true });
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error?.code !== "EEXIST") throw error;
|
|
60
|
+
const lock = await stat(lockPath).catch(() => null);
|
|
61
|
+
if (lock && Date.now() - lock.mtimeMs > STALE_LOCK_MS) {
|
|
62
|
+
await rm(lockPath, { recursive: true, force: true });
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (Date.now() - startedAt >= LOCK_WAIT_MS) {
|
|
66
|
+
throw new Error("Another hiCreator update is still running.");
|
|
67
|
+
}
|
|
68
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function replaceDirectory(source, target, backup) {
|
|
74
|
+
await mkdir(dirname(target), { recursive: true });
|
|
75
|
+
const temporary = join(
|
|
76
|
+
dirname(target),
|
|
77
|
+
`.${basename(target)}.${process.pid}.${randomUUID()}.tmp`,
|
|
78
|
+
);
|
|
79
|
+
const rollback = `${temporary}.rollback`;
|
|
80
|
+
await cp(source, temporary, { recursive: true });
|
|
81
|
+
const hadPrevious = await pathExists(target);
|
|
82
|
+
if (hadPrevious) {
|
|
83
|
+
await mkdir(dirname(backup), { recursive: true });
|
|
84
|
+
await cp(target, backup, { recursive: true });
|
|
85
|
+
await rename(target, rollback);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
await rename(temporary, target);
|
|
89
|
+
if (hadPrevious) await rm(rollback, { recursive: true, force: true });
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (hadPrevious && await pathExists(rollback)) {
|
|
92
|
+
await rename(rollback, target);
|
|
93
|
+
}
|
|
94
|
+
await rm(temporary, { recursive: true, force: true });
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function syncSkill({ home, clients, source = "npm" }) {
|
|
100
|
+
const stateRoot = join(home, ".hicreator");
|
|
101
|
+
await mkdir(stateRoot, { recursive: true });
|
|
102
|
+
const release = await acquireLock(stateRoot);
|
|
103
|
+
try {
|
|
104
|
+
const bundledSkill = join(PACKAGE_ROOT, "skills", SKILL_NAME);
|
|
105
|
+
const version = await packageVersion();
|
|
106
|
+
const checksum = await directoryChecksum(bundledSkill);
|
|
107
|
+
const manifestPath = join(stateRoot, "manifest.json");
|
|
108
|
+
const previous = await readJson(manifestPath, null);
|
|
109
|
+
const targets = Object.fromEntries(
|
|
110
|
+
clients.map((client) => [client, clientSkillPath(home, client)]),
|
|
111
|
+
);
|
|
112
|
+
let updated = previous?.version !== version
|
|
113
|
+
|| previous?.checksum !== checksum;
|
|
114
|
+
|
|
115
|
+
for (const [client, target] of Object.entries(targets)) {
|
|
116
|
+
const currentChecksum = await pathExists(target)
|
|
117
|
+
? await directoryChecksum(target)
|
|
118
|
+
: null;
|
|
119
|
+
if (currentChecksum === checksum) continue;
|
|
120
|
+
updated = true;
|
|
121
|
+
const backupVersion = previous?.version ?? "unknown";
|
|
122
|
+
const backup = join(
|
|
123
|
+
stateRoot,
|
|
124
|
+
"backups",
|
|
125
|
+
`${backupVersion}-${Date.now()}`,
|
|
126
|
+
client,
|
|
127
|
+
);
|
|
128
|
+
await replaceDirectory(bundledSkill, target, backup);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const installedAt = previous?.installedAt ?? new Date().toISOString();
|
|
132
|
+
await writeJsonAtomic(manifestPath, {
|
|
133
|
+
version,
|
|
134
|
+
checksum,
|
|
135
|
+
installedAt,
|
|
136
|
+
updatedAt: new Date().toISOString(),
|
|
137
|
+
source,
|
|
138
|
+
targets,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
version,
|
|
142
|
+
updated,
|
|
143
|
+
skillPath: targets.codex ?? Object.values(targets)[0],
|
|
144
|
+
targets,
|
|
145
|
+
};
|
|
146
|
+
} finally {
|
|
147
|
+
await release();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function installedClients(home) {
|
|
152
|
+
const manifest = await readJson(join(home, ".hicreator", "manifest.json"), null);
|
|
153
|
+
return manifest?.targets ? Object.keys(manifest.targets) : [];
|
|
154
|
+
}
|
package/src/mcp-check.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const PROTOCOL_VERSION = "2025-06-18";
|
|
2
|
+
const EXPECTED_TOOLS = [
|
|
3
|
+
"search_creators_ai",
|
|
4
|
+
"find_similar_creators",
|
|
5
|
+
"find_creator_email",
|
|
6
|
+
"create_creator_folder",
|
|
7
|
+
"list_creator_folders",
|
|
8
|
+
"add_creators_to_folder",
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
function parseMcpPayload(text) {
|
|
12
|
+
if (text.trimStart().startsWith("{")) return JSON.parse(text);
|
|
13
|
+
const data = text.split("\n").find((line) => line.startsWith("data: "));
|
|
14
|
+
if (!data) throw new Error("MCP response did not contain a JSON result.");
|
|
15
|
+
return JSON.parse(data.slice("data: ".length));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function request(mcpUrl, apiKey, id, method, params) {
|
|
19
|
+
const response = await fetch(mcpUrl, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: {
|
|
22
|
+
Accept: "application/json, text/event-stream",
|
|
23
|
+
Authorization: `Bearer ${apiKey}`,
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"MCP-Protocol-Version": PROTOCOL_VERSION,
|
|
26
|
+
},
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
jsonrpc: "2.0",
|
|
29
|
+
id,
|
|
30
|
+
method,
|
|
31
|
+
...(params ? { params } : {}),
|
|
32
|
+
}),
|
|
33
|
+
redirect: "error",
|
|
34
|
+
signal: AbortSignal.timeout(10_000),
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
throw new Error(`MCP connection failed with HTTP ${response.status}.`);
|
|
38
|
+
}
|
|
39
|
+
return parseMcpPayload(await response.text());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function verifyMcp(mcpUrl, apiKey) {
|
|
43
|
+
const initialized = await request(mcpUrl, apiKey, 1, "initialize", {
|
|
44
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
45
|
+
capabilities: {},
|
|
46
|
+
clientInfo: { name: "hicreator-agent-setup", version: "0.1.0" },
|
|
47
|
+
});
|
|
48
|
+
if (initialized.error || initialized.result?.serverInfo?.name !== "hicreator") {
|
|
49
|
+
throw new Error("MCP initialize returned an unexpected response.");
|
|
50
|
+
}
|
|
51
|
+
const listed = await request(mcpUrl, apiKey, 2, "tools/list");
|
|
52
|
+
const tools = listed.result?.tools?.map((tool) => tool.name);
|
|
53
|
+
if (!Array.isArray(tools)
|
|
54
|
+
|| EXPECTED_TOOLS.some((tool) => !tools.includes(tool))) {
|
|
55
|
+
throw new Error("MCP server did not advertise all six hiCreator tools.");
|
|
56
|
+
}
|
|
57
|
+
return { server: initialized.result.serverInfo, tools };
|
|
58
|
+
}
|