gitskins 0.2.0 → 0.3.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 +21 -0
- package/bin/gitskins.js +11 -0
- package/package.json +2 -2
- package/src/commands/portfolio.js +142 -0
- package/src/commands/template.js +7 -1
- package/src/template.js +7 -5
package/README.md
CHANGED
|
@@ -206,3 +206,24 @@ Node.js 18+. No dependencies.
|
|
|
206
206
|
## License
|
|
207
207
|
|
|
208
208
|
MIT
|
|
209
|
+
|
|
210
|
+
## Character portfolio with an AI agent
|
|
211
|
+
|
|
212
|
+
Work on your GitSkins character portfolio in Claude Code, Codex, Cursor or any
|
|
213
|
+
agent with a terminal. On gitskins.com, open your portfolio builder and choose
|
|
214
|
+
**Continue with AI → Copy prompt for my agent**, or run the steps yourself:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
npx gitskins portfolio pull "<link from Continue with AI>" my-portfolio
|
|
218
|
+
cd my-portfolio
|
|
219
|
+
npx gitskins portfolio dev # preview at http://localhost:4321
|
|
220
|
+
npx gitskins portfolio status # content changed since pull
|
|
221
|
+
npx gitskins portfolio push # send gitskins.json "content" to GitSkins
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
The folder has an `AGENTS.md` (and `CLAUDE.md`) that tells the agent how the page
|
|
225
|
+
and the character work and what not to break. Wording, projects, look and accent
|
|
226
|
+
go in the `content` section of `gitskins.json`; `push` sends them back to your
|
|
227
|
+
GitSkins portfolio, where they are checked like edits in the builder. Code changes
|
|
228
|
+
stay in your folder; deploy it to any static host if you change code. The push key
|
|
229
|
+
is stored in `.gitskins-portfolio/` (git-ignored) and lasts a week.
|
package/bin/gitskins.js
CHANGED
|
@@ -14,6 +14,7 @@ import { initCommand } from '../src/commands/init.js';
|
|
|
14
14
|
import { renderCommand } from '../src/commands/render.js';
|
|
15
15
|
import { portraitCommand } from '../src/commands/portrait.js';
|
|
16
16
|
import { templateCommand } from '../src/commands/template.js';
|
|
17
|
+
import { portfolioCommand } from '../src/commands/portfolio.js';
|
|
17
18
|
import { log } from '../src/util.js';
|
|
18
19
|
|
|
19
20
|
const HELP = `
|
|
@@ -27,6 +28,7 @@ ${log.bold('Commands')}
|
|
|
27
28
|
render Re-render the widgets defined in .gitskins.json
|
|
28
29
|
portrait Render a local photo to an ASCII-art SVG (subject on dark)
|
|
29
30
|
template Build, validate and preview a community README template
|
|
31
|
+
portfolio Work on your character portfolio with an AI agent (pull, dev, status, push)
|
|
30
32
|
help Show this help
|
|
31
33
|
|
|
32
34
|
${log.bold('init options')}
|
|
@@ -64,6 +66,12 @@ ${log.bold('template actions')}
|
|
|
64
66
|
--author <login> Whose credit the footer shows (default: the --user profile)
|
|
65
67
|
Submit a finished template at https://www.gitskins.com/community-templates
|
|
66
68
|
|
|
69
|
+
${log.bold('portfolio actions')}
|
|
70
|
+
pull <link> [dir] Download your portfolio (link from "Continue with AI")
|
|
71
|
+
dev [--port 4321] Preview it locally
|
|
72
|
+
status Content changes not pushed yet
|
|
73
|
+
push Send gitskins.json "content" back to GitSkins
|
|
74
|
+
|
|
67
75
|
${log.bold('Examples')}
|
|
68
76
|
npx gitskins init --username torvalds --theme satan
|
|
69
77
|
npx gitskins render --snippet
|
|
@@ -89,6 +97,9 @@ async function main() {
|
|
|
89
97
|
case 'template':
|
|
90
98
|
await templateCommand(argv);
|
|
91
99
|
break;
|
|
100
|
+
case 'portfolio':
|
|
101
|
+
await portfolioCommand(argv);
|
|
102
|
+
break;
|
|
92
103
|
case undefined:
|
|
93
104
|
case 'help':
|
|
94
105
|
case '--help':
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitskins",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "GitSkins from the terminal: self-updating profile widgets via a GitHub Action, community README templates, and your character portfolio with AI agents (pull, preview, push).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gitskins": "bin/gitskins.js"
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gitskins portfolio: work on a GitSkins character portfolio with an AI coding
|
|
3
|
+
* agent (Claude Code, Codex, Cursor) and send the content back.
|
|
4
|
+
*
|
|
5
|
+
* gitskins portfolio pull <link> [dir] download the folder (from "Continue with AI")
|
|
6
|
+
* gitskins portfolio dev [--port 4321] preview it locally
|
|
7
|
+
* gitskins portfolio status show content changes not pushed yet
|
|
8
|
+
* gitskins portfolio push send gitskins.json "content" to GitSkins
|
|
9
|
+
*
|
|
10
|
+
* Dependency-free. The push key lives in .gitskins-portfolio/ (git-ignored), never in gitskins.json.
|
|
11
|
+
*/
|
|
12
|
+
import { createServer } from 'node:http';
|
|
13
|
+
import { existsSync } from 'node:fs';
|
|
14
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { dirname, extname, join, normalize, resolve, sep } from 'node:path';
|
|
16
|
+
import { log } from '../util.js';
|
|
17
|
+
|
|
18
|
+
export const SESSION_DIR = '.gitskins-portfolio';
|
|
19
|
+
const SESSION_FILE = join(SESSION_DIR, 'session.json');
|
|
20
|
+
const ALLOWED_HOSTS = /^(?:[a-z0-9-]+\.)*gitskins\.com$|^localhost$|^127\.0\.0\.1$/;
|
|
21
|
+
|
|
22
|
+
const HELP = `Usage:
|
|
23
|
+
gitskins portfolio pull <link> [dir] Download your portfolio (link from "Continue with AI" on gitskins.com)
|
|
24
|
+
gitskins portfolio dev [--port 4321] Preview it at http://localhost:4321
|
|
25
|
+
gitskins portfolio status Show content changes not sent yet
|
|
26
|
+
gitskins portfolio push Send the "content" in gitskins.json to your GitSkins portfolio`;
|
|
27
|
+
|
|
28
|
+
/** Only GitSkins links; the folder JSON format; a safe path for every file. */
|
|
29
|
+
export function bundleRequestUrl(link) {
|
|
30
|
+
let url;
|
|
31
|
+
try { url = new URL(link); } catch { throw new Error('That is not a link. Copy it from "Continue with AI" on gitskins.com.'); }
|
|
32
|
+
if (url.protocol !== 'https:' && !/^(localhost|127\.0\.0\.1)$/.test(url.hostname)) throw new Error('Use the https link from gitskins.com.');
|
|
33
|
+
if (!ALLOWED_HOSTS.test(url.hostname)) throw new Error('Only gitskins.com portfolio links can be pulled.');
|
|
34
|
+
if (!url.pathname.endsWith('/api/agent/portfolio-bundle') || !url.searchParams.get('t')) throw new Error('That is not a GitSkins portfolio link.');
|
|
35
|
+
url.searchParams.set('format', 'json');
|
|
36
|
+
return url;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function safeTarget(root, name) {
|
|
40
|
+
const target = normalize(join(root, name));
|
|
41
|
+
if (!target.startsWith(resolve(root) + sep) || name.includes('\0')) throw new Error(`Refusing to write outside the folder: ${name}`);
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function pull(link, dir = 'gitskins-portfolio', { fetchImpl = fetch } = {}) {
|
|
46
|
+
const url = bundleRequestUrl(link);
|
|
47
|
+
log.step('Downloading your portfolio…');
|
|
48
|
+
const response = await fetchImpl(url, { headers: { Accept: 'application/json' } });
|
|
49
|
+
const body = await response.json().catch(() => ({}));
|
|
50
|
+
if (!response.ok) throw new Error(body.error || `GitSkins answered ${response.status}.`);
|
|
51
|
+
if (!body.files || typeof body.files !== 'object') throw new Error('GitSkins sent an unexpected answer.');
|
|
52
|
+
const root = resolve(dir);
|
|
53
|
+
await mkdir(root, { recursive: true });
|
|
54
|
+
let count = 0;
|
|
55
|
+
for (const [name, base64] of Object.entries(body.files)) {
|
|
56
|
+
const target = safeTarget(root, name);
|
|
57
|
+
await mkdir(dirname(target), { recursive: true });
|
|
58
|
+
await writeFile(target, Buffer.from(base64, 'base64'));
|
|
59
|
+
count += 1;
|
|
60
|
+
}
|
|
61
|
+
const manifest = JSON.parse(await readFile(join(root, 'gitskins.json'), 'utf8'));
|
|
62
|
+
await mkdir(join(root, SESSION_DIR), { recursive: true });
|
|
63
|
+
await writeFile(join(root, SESSION_FILE), JSON.stringify({ buildId: body.buildId, template: body.template, username: body.username, pushUrl: body.pushUrl, pushToken: body.pushToken, pulledContent: manifest.content ?? {}, pulledAt: new Date().toISOString() }, null, 2));
|
|
64
|
+
// Keep the push key out of git, whatever else the folder becomes.
|
|
65
|
+
const gitignore = join(root, '.gitignore');
|
|
66
|
+
const existing = existsSync(gitignore) ? await readFile(gitignore, 'utf8') : '';
|
|
67
|
+
if (!existing.split('\n').includes(`${SESSION_DIR}/`)) await writeFile(gitignore, `${existing}${existing && !existing.endsWith('\n') ? '\n' : ''}${SESSION_DIR}/\n`);
|
|
68
|
+
log.ok(`Saved ${count} files to ${dir}`);
|
|
69
|
+
log.dim(' Next: read AGENTS.md, then run: npx gitskins portfolio dev');
|
|
70
|
+
return { root, count };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function readSession(root) {
|
|
74
|
+
const file = join(root, SESSION_FILE);
|
|
75
|
+
if (!existsSync(file)) throw new Error('No GitSkins session here. Run this inside a folder made by "gitskins portfolio pull".');
|
|
76
|
+
return JSON.parse(await readFile(file, 'utf8'));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function contentChanges(before = {}, after = {}) {
|
|
80
|
+
const keys = new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
81
|
+
return [...keys].filter((key) => JSON.stringify(before[key]) !== JSON.stringify(after[key])).sort();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function status(root = process.cwd()) {
|
|
85
|
+
const session = await readSession(root);
|
|
86
|
+
const { content = {} } = JSON.parse(await readFile(join(root, 'gitskins.json'), 'utf8'));
|
|
87
|
+
const changed = contentChanges(session.pulledContent, content);
|
|
88
|
+
if (!changed.length) log.ok('No content changes to push.');
|
|
89
|
+
else log.info(`Changed since pull: ${changed.join(', ')}`);
|
|
90
|
+
return changed;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function push(root = process.cwd(), { fetchImpl = fetch } = {}) {
|
|
94
|
+
const session = await readSession(root);
|
|
95
|
+
const { content } = JSON.parse(await readFile(join(root, 'gitskins.json'), 'utf8'));
|
|
96
|
+
if (!content || typeof content !== 'object') throw new Error('gitskins.json has no "content" section.');
|
|
97
|
+
log.step('Sending your content to GitSkins…');
|
|
98
|
+
const response = await fetchImpl(session.pushUrl, { method: 'POST', headers: { Authorization: `Bearer ${session.pushToken}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ content }) });
|
|
99
|
+
const body = await response.json().catch(() => ({}));
|
|
100
|
+
if (!response.ok) throw new Error(body.error || `GitSkins answered ${response.status}.`);
|
|
101
|
+
if (!body.changed?.length) { log.ok('Already up to date.'); return body; }
|
|
102
|
+
// Keep what GitSkins stored (it checks every field), so status starts clean.
|
|
103
|
+
session.pulledContent = { ...content, ...body.content };
|
|
104
|
+
await writeFile(join(root, SESSION_FILE), JSON.stringify(session, null, 2));
|
|
105
|
+
log.ok(`Updated on GitSkins: ${body.changed.join(', ')}`);
|
|
106
|
+
log.dim(' Open your portfolio builder on gitskins.com to see it. Code changes to index.html stay in this folder.');
|
|
107
|
+
return body;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const TYPES = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript', '.json': 'application/json', '.webp': 'image/webp', '.png': 'image/png', '.woff2': 'font/woff2', '.md': 'text/markdown; charset=utf-8', '.css': 'text/css' };
|
|
111
|
+
|
|
112
|
+
export function dev(root = process.cwd(), port = 4321) {
|
|
113
|
+
const server = createServer(async (req, res) => {
|
|
114
|
+
try {
|
|
115
|
+
const path = decodeURIComponent(new URL(req.url, 'http://x').pathname);
|
|
116
|
+
const file = safeTarget(root, path === '/' ? 'index.html' : path.slice(1));
|
|
117
|
+
if (file.includes(`${sep}${SESSION_DIR}`)) throw new Error('private');
|
|
118
|
+
const data = await readFile(file);
|
|
119
|
+
res.writeHead(200, { 'Content-Type': TYPES[extname(file)] ?? 'application/octet-stream', 'Cache-Control': 'no-store' });
|
|
120
|
+
res.end(data);
|
|
121
|
+
} catch {
|
|
122
|
+
res.writeHead(404); res.end('Not found');
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
server.listen(port, '127.0.0.1', () => log.ok(`Preview: http://localhost:${port} (edit gitskins.json or index.html, then reload)`));
|
|
126
|
+
return server;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function portfolioCommand(argv) {
|
|
130
|
+
const [action, ...tail] = argv;
|
|
131
|
+
const portIndex = tail.indexOf('--port');
|
|
132
|
+
const args = { port: portIndex >= 0 ? tail[portIndex + 1] : undefined };
|
|
133
|
+
const rest = tail.filter((_, i) => i !== portIndex && i !== portIndex + 1 || portIndex < 0);
|
|
134
|
+
if (action === 'pull') {
|
|
135
|
+
if (!rest[0]) throw new Error(`Pass the link.\n${HELP}`);
|
|
136
|
+
return pull(rest[0], rest[1]);
|
|
137
|
+
}
|
|
138
|
+
if (action === 'dev') return dev(process.cwd(), Number(args.port) || 4321);
|
|
139
|
+
if (action === 'status') return status();
|
|
140
|
+
if (action === 'push') return push();
|
|
141
|
+
log.info(HELP);
|
|
142
|
+
}
|
package/src/commands/template.js
CHANGED
|
@@ -131,8 +131,14 @@ export async function templateCommand(argv) {
|
|
|
131
131
|
return validate(rest);
|
|
132
132
|
case 'preview':
|
|
133
133
|
return preview(rest, flags);
|
|
134
|
+
case undefined:
|
|
135
|
+
case 'help':
|
|
136
|
+
case '--help':
|
|
137
|
+
case '-h':
|
|
138
|
+
log.info(USAGE);
|
|
139
|
+
return undefined;
|
|
134
140
|
default:
|
|
135
|
-
log.error(
|
|
141
|
+
log.error(`Unknown template action: ${action}`);
|
|
136
142
|
log.info(USAGE);
|
|
137
143
|
process.exit(1);
|
|
138
144
|
}
|
package/src/template.js
CHANGED
|
@@ -33,7 +33,7 @@ export const TEMPLATE_PRO_LOOK = {
|
|
|
33
33
|
|
|
34
34
|
const SAFE_TEXT = /^[\p{L}\p{N}\p{M}\p{Extended_Pictographic}️ .,:;'’"“”&+/?!()@–—·-]+$/u;
|
|
35
35
|
const RECIPE_KEYS = new Set(['version', 'theme', 'sectionOrder', 'headings', ...Object.keys(TEMPLATE_VARIANTS), ...Object.keys(TEMPLATE_PRO_LOOK)]);
|
|
36
|
-
const FILE_KEYS = new Set(['$schema', 'name', 'description', 'category', 'recipe']);
|
|
36
|
+
const FILE_KEYS = new Set(['$schema', 'name', 'description', 'category', 'recipe', 'allowRemix']);
|
|
37
37
|
|
|
38
38
|
const isObject = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
39
39
|
const list = (values) => values.map((value) => `"${value}"`).join(', ');
|
|
@@ -131,16 +131,18 @@ export function validateTemplate(input) {
|
|
|
131
131
|
const [description, descriptionError] = safeText('The description', input.description, 10, 160);
|
|
132
132
|
if (descriptionError) errors.push(descriptionError);
|
|
133
133
|
if (!TEMPLATE_CATEGORIES.includes(input.category)) errors.push(`"category" must be one of ${list(TEMPLATE_CATEGORIES)}.`);
|
|
134
|
+
if (input.allowRemix !== undefined && typeof input.allowRemix !== 'boolean') errors.push('"allowRemix" must be true or false.');
|
|
134
135
|
const result = validateRecipe(input.recipe);
|
|
135
136
|
errors.push(...result.errors);
|
|
136
137
|
warnings.push(...result.warnings);
|
|
137
138
|
if (errors.length) return { template: null, errors, warnings };
|
|
138
|
-
|
|
139
|
+
// Others may remix it unless the creator says no (credit is always kept).
|
|
140
|
+
return { template: { name, description, category: input.category, recipe: result.recipe, allowRemix: input.allowRemix ?? true }, errors, warnings };
|
|
139
141
|
}
|
|
140
142
|
|
|
141
|
-
/**
|
|
142
|
-
export function templateIsFree(
|
|
143
|
-
return
|
|
143
|
+
/** Community templates are free: free accounts get their free look, as the server prices it. */
|
|
144
|
+
export function templateIsFree(_recipe) {
|
|
145
|
+
return true;
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
/** A valid starting point for `gitskins template init`. */
|