orizu 0.3.4 → 0.3.6

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.
@@ -0,0 +1,180 @@
1
+ import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from 'fs';
2
+ import { dirname, isAbsolute, relative, resolve } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { homedir } from 'os';
5
+ export const SKILL_NAME = 'orizu-cli';
6
+ export const AGENTS_START_MARKER = '<!-- orizu-cli:start -->';
7
+ export const AGENTS_END_MARKER = '<!-- orizu-cli:end -->';
8
+ export const SKILL_INSTALL_TARGETS = [
9
+ 'agent-user',
10
+ 'codex-project',
11
+ 'claude-user',
12
+ 'claude-project',
13
+ 'agents-md',
14
+ ];
15
+ function getCliRoot() {
16
+ return resolve(dirname(fileURLToPath(import.meta.url)), '..');
17
+ }
18
+ function isSkillDir(path) {
19
+ return existsSync(resolve(path, 'SKILL.md'));
20
+ }
21
+ export function isSafeRelativeSkillPath(rel) {
22
+ return rel !== '..' && !rel.startsWith('../') && !isAbsolute(rel);
23
+ }
24
+ export function formatMissingSkillSourceError(paths) {
25
+ return `Unable to find bundled ${SKILL_NAME} skill. Reinstall the orizu CLI or run from the Orizu repository.\n`
26
+ + `Searched:\n- ${paths.join('\n- ')}`;
27
+ }
28
+ export function resolveSkillSourceDir() {
29
+ const override = process.env.ORIZU_SKILL_SOURCE_DIR;
30
+ if (override) {
31
+ const resolvedOverride = resolve(override);
32
+ if (!isSkillDir(resolvedOverride)) {
33
+ throw new Error(`ORIZU_SKILL_SOURCE_DIR is not an Orizu skill directory: ${resolvedOverride}`);
34
+ }
35
+ return resolvedOverride;
36
+ }
37
+ const cliRoot = getCliRoot();
38
+ const packagedSkill = resolve(cliRoot, 'vendor', 'skills', SKILL_NAME);
39
+ if (isSkillDir(packagedSkill)) {
40
+ return packagedSkill;
41
+ }
42
+ const repoSkill = resolve(cliRoot, '..', '..', 'skills', SKILL_NAME);
43
+ if (isSkillDir(repoSkill)) {
44
+ return repoSkill;
45
+ }
46
+ const searchedPaths = [
47
+ `packaged skill: ${packagedSkill}`,
48
+ `repository fallback: ${repoSkill}`,
49
+ ];
50
+ throw new Error(formatMissingSkillSourceError(searchedPaths));
51
+ }
52
+ function resolveHome(options) {
53
+ return resolve(options?.homeDir || process.env.HOME || homedir());
54
+ }
55
+ function resolveCwd(options) {
56
+ return resolve(options?.cwd || process.cwd());
57
+ }
58
+ export function getSkillInstallPath(target, options) {
59
+ const home = resolveHome(options);
60
+ const cwd = resolveCwd(options);
61
+ if (target === 'agent-user') {
62
+ return resolve(home, '.agents', 'skills', SKILL_NAME);
63
+ }
64
+ if (target === 'codex-project') {
65
+ return resolve(cwd, '.codex', 'skills', SKILL_NAME);
66
+ }
67
+ if (target === 'claude-user') {
68
+ return resolve(home, '.claude', 'skills', SKILL_NAME);
69
+ }
70
+ if (target === 'claude-project') {
71
+ return resolve(cwd, '.claude', 'skills', SKILL_NAME);
72
+ }
73
+ return resolve(cwd, 'AGENTS.md');
74
+ }
75
+ function shouldCopySkillPath(sourceRoot, sourcePath) {
76
+ const rel = relative(sourceRoot, sourcePath).replace(/\\/g, '/');
77
+ if (!rel) {
78
+ return true;
79
+ }
80
+ if (!isSafeRelativeSkillPath(rel)) {
81
+ return false;
82
+ }
83
+ const parts = rel.split('/');
84
+ return !parts.some(part => part === '.DS_Store' ||
85
+ part === '__pycache__' ||
86
+ part === '.pytest_cache') && !rel.endsWith('.pyc') && !rel.endsWith('.pyo');
87
+ }
88
+ function copySkillTree(sourceDir, targetDir) {
89
+ rmSync(targetDir, { recursive: true, force: true });
90
+ mkdirSync(dirname(targetDir), { recursive: true });
91
+ cpSync(sourceDir, targetDir, {
92
+ recursive: true,
93
+ filter: sourcePath => shouldCopySkillPath(sourceDir, sourcePath),
94
+ });
95
+ }
96
+ function stripFrontmatter(markdown) {
97
+ const match = markdown.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n/);
98
+ if (!match) {
99
+ return markdown;
100
+ }
101
+ return markdown.slice(match[0].length).replace(/^[\r\n]+/, '');
102
+ }
103
+ function buildAgentsSection(sourceDir) {
104
+ const skillMarkdown = readFileSync(resolve(sourceDir, 'SKILL.md'), 'utf8');
105
+ const body = stripFrontmatter(skillMarkdown).trimEnd();
106
+ return `${AGENTS_START_MARKER}\n${body}\n${AGENTS_END_MARKER}\n`;
107
+ }
108
+ function installAgentsMd(sourceDir, targetPath, options) {
109
+ const section = buildAgentsSection(sourceDir);
110
+ const exists = existsSync(targetPath);
111
+ const existing = exists ? readFileSync(targetPath, 'utf8') : '';
112
+ const hasManagedSection = existing.includes(AGENTS_START_MARKER)
113
+ && existing.includes(AGENTS_END_MARKER);
114
+ const action = exists ? 'updated' : 'created';
115
+ if (options?.dryRun) {
116
+ return {
117
+ target: 'agents-md',
118
+ path: targetPath,
119
+ action: action === 'updated' ? 'would-update' : 'would-create',
120
+ };
121
+ }
122
+ if (hasManagedSection && !options?.overwrite) {
123
+ throw new Error(`${targetPath} already contains an Orizu CLI section. Pass --yes to replace it.`);
124
+ }
125
+ mkdirSync(dirname(targetPath), { recursive: true });
126
+ if (!exists) {
127
+ writeFileSync(targetPath, section, 'utf8');
128
+ return { target: 'agents-md', path: targetPath, action: 'created' };
129
+ }
130
+ if (hasManagedSection) {
131
+ const pattern = new RegExp(`${escapeRegExp(AGENTS_START_MARKER)}[\\s\\S]*?${escapeRegExp(AGENTS_END_MARKER)}\\n?`);
132
+ writeFileSync(targetPath, existing.replace(pattern, section), 'utf8');
133
+ return { target: 'agents-md', path: targetPath, action: 'updated' };
134
+ }
135
+ const existingPrefix = existing.trim().length === 0 ? '' : existing;
136
+ const separator = existingPrefix.endsWith('\n') ? '\n' : '\n\n';
137
+ writeFileSync(targetPath, `${existingPrefix}${existingPrefix ? separator : ''}${section}`, 'utf8');
138
+ return { target: 'agents-md', path: targetPath, action: 'updated' };
139
+ }
140
+ function escapeRegExp(value) {
141
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
142
+ }
143
+ export function targetNeedsOverwrite(target, options) {
144
+ const targetPath = getSkillInstallPath(target, options);
145
+ if (!existsSync(targetPath)) {
146
+ return false;
147
+ }
148
+ if (target !== 'agents-md') {
149
+ return true;
150
+ }
151
+ const existing = readFileSync(targetPath, 'utf8');
152
+ return existing.includes(AGENTS_START_MARKER) && existing.includes(AGENTS_END_MARKER);
153
+ }
154
+ export function installSkillTarget(target, options) {
155
+ const sourceDir = resolveSkillSourceDir();
156
+ const targetPath = getSkillInstallPath(target, options);
157
+ const exists = existsSync(targetPath);
158
+ if (target === 'agents-md') {
159
+ return installAgentsMd(sourceDir, targetPath, options);
160
+ }
161
+ if (options?.dryRun) {
162
+ return {
163
+ target,
164
+ path: targetPath,
165
+ action: exists ? 'would-update' : 'would-create',
166
+ };
167
+ }
168
+ if (exists && !options?.overwrite) {
169
+ throw new Error(`${targetPath} already exists. Pass --yes to replace it.`);
170
+ }
171
+ copySkillTree(sourceDir, targetPath);
172
+ return {
173
+ target,
174
+ path: targetPath,
175
+ action: exists ? 'updated' : 'created',
176
+ };
177
+ }
178
+ export function isSkillInstallTarget(value) {
179
+ return SKILL_INSTALL_TARGETS.includes(value);
180
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orizu",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,16 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "tsc -p tsconfig.json",
19
- "prepack": "node scripts/vendor-gepa-python.mjs",
20
- "postpack": "node scripts/vendor-gepa-python.mjs --clean"
19
+ "prepack": "node scripts/vendor-gepa-python.mjs && node scripts/vendor-orizu-skill.mjs",
20
+ "postpack": "node scripts/vendor-gepa-python.mjs --clean && node scripts/vendor-orizu-skill.mjs --clean"
21
+ },
22
+ "dependencies": {
23
+ "@playwright/test": "^1.60.0",
24
+ "@tailwindcss/postcss": "^4.1.7",
25
+ "esbuild": "^0.25.8",
26
+ "postcss": "^8.5.6",
27
+ "react": "19.2.6",
28
+ "react-dom": "19.2.6",
29
+ "tailwindcss": "^4.1.10"
21
30
  }
22
31
  }
@@ -0,0 +1,54 @@
1
+ import { cpSync, existsSync, mkdirSync, rmSync } from 'node:fs'
2
+ import { dirname, isAbsolute, relative, resolve } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+
5
+ const scriptDir = dirname(fileURLToPath(import.meta.url))
6
+ const cliRoot = resolve(scriptDir, '..')
7
+ const repoRoot = resolve(cliRoot, '..', '..')
8
+ const sourceRoot = resolve(repoRoot, 'skills', 'orizu-cli')
9
+ const vendorRoot = resolve(cliRoot, 'vendor', 'skills', 'orizu-cli')
10
+ const shouldClean = process.argv.includes('--clean')
11
+ const hasSourceSkill = existsSync(resolve(sourceRoot, 'SKILL.md'))
12
+ const hasVendoredSkill = existsSync(resolve(vendorRoot, 'SKILL.md'))
13
+
14
+ function isSafeRelativeSkillPath(rel) {
15
+ return rel !== '..' && !rel.startsWith('../') && !isAbsolute(rel)
16
+ }
17
+
18
+ function shouldCopyPath(sourcePath) {
19
+ const rel = relative(sourceRoot, sourcePath).replace(/\\/g, '/')
20
+ if (!rel) {
21
+ return true
22
+ }
23
+ if (!isSafeRelativeSkillPath(rel)) {
24
+ return false
25
+ }
26
+
27
+ const parts = rel.split('/')
28
+ return !parts.some(part =>
29
+ part === '.DS_Store' ||
30
+ part === '__pycache__' ||
31
+ part === '.pytest_cache'
32
+ ) && !rel.endsWith('.pyc') && !rel.endsWith('.pyo')
33
+ }
34
+
35
+ if (shouldClean) {
36
+ if (hasSourceSkill) {
37
+ rmSync(vendorRoot, { recursive: true, force: true })
38
+ }
39
+ process.exit(0)
40
+ }
41
+
42
+ if (!hasSourceSkill) {
43
+ if (hasVendoredSkill) {
44
+ process.exit(0)
45
+ }
46
+ throw new Error(`Unable to vendor orizu-cli skill: source skill not found at ${sourceRoot}`)
47
+ }
48
+
49
+ rmSync(vendorRoot, { recursive: true, force: true })
50
+ mkdirSync(vendorRoot, { recursive: true })
51
+ cpSync(sourceRoot, vendorRoot, {
52
+ recursive: true,
53
+ filter: shouldCopyPath,
54
+ })