@codemieai/cdk 0.1.665 → 0.1.666
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 +157 -1
- package/dist/cli/index.js +1332 -376
- package/dist/index.d.ts +32 -3
- package/dist/index.js +1311 -387
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import ora from 'ora';
|
|
3
3
|
import * as crypto from 'crypto';
|
|
4
|
+
import * as fs13 from 'fs';
|
|
5
|
+
import * as path13 from 'path';
|
|
6
|
+
import path13__default from 'path';
|
|
4
7
|
import { DataSourceType, CodeMieClient, SkillVisibility } from 'codemie-sdk';
|
|
5
|
-
import * as
|
|
6
|
-
import * as path16 from 'path';
|
|
7
|
-
import path16__default from 'path';
|
|
8
|
-
import * as yaml6 from 'yaml';
|
|
8
|
+
import * as yaml7 from 'yaml';
|
|
9
9
|
import { program } from '@commander-js/extra-typings';
|
|
10
10
|
import { z } from 'zod';
|
|
11
11
|
import 'dotenv/config';
|
|
@@ -406,13 +406,116 @@ function calculateSkillConfigChecksum(skill) {
|
|
|
406
406
|
const filtered = buildChecksumObject(skill, SKILL_EXCLUDED_FIELDS);
|
|
407
407
|
return calculateChecksum(JSON.stringify(filtered));
|
|
408
408
|
}
|
|
409
|
+
function calculateCompanionFilesChecksum(files) {
|
|
410
|
+
const sortedFiles = [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
411
|
+
const companionFileHashes = {};
|
|
412
|
+
for (const file of sortedFiles) {
|
|
413
|
+
companionFileHashes[file.path] = calculateChecksum(file.content);
|
|
414
|
+
}
|
|
415
|
+
const aggregateEntries = sortedFiles.map((file) => ({
|
|
416
|
+
path: file.path,
|
|
417
|
+
mime_type: file.mime_type,
|
|
418
|
+
encoding: file.encoding,
|
|
419
|
+
size_bytes: file.size_bytes,
|
|
420
|
+
contentHash: companionFileHashes[file.path]
|
|
421
|
+
}));
|
|
422
|
+
const companionFilesChecksum = calculateChecksum(JSON.stringify(aggregateEntries));
|
|
423
|
+
return { companionFilesChecksum, companionFileHashes };
|
|
424
|
+
}
|
|
409
425
|
var DATASOURCE_EXCLUDED_FIELDS, WORKFLOW_EXCLUDED_FIELDS, SKILL_EXCLUDED_FIELDS;
|
|
410
426
|
var init_codemieConfigChecksums = __esm({
|
|
411
427
|
"src/lib/codemieConfigChecksums.ts"() {
|
|
412
428
|
init_checksumUtils();
|
|
413
429
|
DATASOURCE_EXCLUDED_FIELDS = createExcludeSet(["force_reindex"]);
|
|
414
430
|
WORKFLOW_EXCLUDED_FIELDS = createExcludeSet(["definition"]);
|
|
415
|
-
SKILL_EXCLUDED_FIELDS = createExcludeSet([
|
|
431
|
+
SKILL_EXCLUDED_FIELDS = createExcludeSet([
|
|
432
|
+
"file",
|
|
433
|
+
"source_dir",
|
|
434
|
+
"ignore_file",
|
|
435
|
+
"content",
|
|
436
|
+
"group"
|
|
437
|
+
]);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
function sanitizeFileName(name, maxLength = 255) {
|
|
441
|
+
const nameWithHyphens = name.replaceAll(/[/\\]/g, "-");
|
|
442
|
+
const sanitized = nameWithHyphens.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-").replaceAll(/^-+|-+$/g, "").slice(0, maxLength);
|
|
443
|
+
if (!sanitized) {
|
|
444
|
+
throw new Error(`Sanitized filename is empty for input: "${name}"`);
|
|
445
|
+
}
|
|
446
|
+
return sanitized;
|
|
447
|
+
}
|
|
448
|
+
function skillFileBaseName(name) {
|
|
449
|
+
return sanitizeFileName(name);
|
|
450
|
+
}
|
|
451
|
+
function skillDirRelativePath(name) {
|
|
452
|
+
return `skills/${skillFileBaseName(name)}`;
|
|
453
|
+
}
|
|
454
|
+
function skillFlatFileRelativePath(name) {
|
|
455
|
+
return `skills/${skillFileBaseName(name)}.skill.md`;
|
|
456
|
+
}
|
|
457
|
+
function skillMarkdownRelativePath(name) {
|
|
458
|
+
return `${skillDirRelativePath(name)}/${SKILL_MD_FILENAME}`;
|
|
459
|
+
}
|
|
460
|
+
function resolvePathWithinDirectory(baseDir, candidatePath) {
|
|
461
|
+
const resolvedBase = path13.resolve(baseDir);
|
|
462
|
+
const resolved = path13.resolve(resolvedBase, candidatePath);
|
|
463
|
+
if (!resolved.startsWith(resolvedBase + path13.sep)) {
|
|
464
|
+
throw new Error(`Refusing to write "${candidatePath}": it resolves to "${resolved}", outside "${resolvedBase}"`);
|
|
465
|
+
}
|
|
466
|
+
return resolved;
|
|
467
|
+
}
|
|
468
|
+
function validateBackupDirectory(backupDir, minSpaceGB = 1) {
|
|
469
|
+
try {
|
|
470
|
+
const parentDir = path13.dirname(backupDir);
|
|
471
|
+
if (!fs13.existsSync(parentDir)) {
|
|
472
|
+
fs13.mkdirSync(parentDir, { recursive: true });
|
|
473
|
+
}
|
|
474
|
+
const testFile = path13.join(parentDir, ".write-test");
|
|
475
|
+
fs13.writeFileSync(testFile, "test");
|
|
476
|
+
fs13.unlinkSync(testFile);
|
|
477
|
+
try {
|
|
478
|
+
const stats = fs13.statfsSync(parentDir);
|
|
479
|
+
const availableGB = stats.bavail * stats.bsize / BYTES_IN_GB;
|
|
480
|
+
if (availableGB < minSpaceGB) {
|
|
481
|
+
throw new Error(`Insufficient disk space: ${availableGB.toFixed(2)}GB available, need ${minSpaceGB}GB`);
|
|
482
|
+
}
|
|
483
|
+
} catch (error) {
|
|
484
|
+
if (error.code !== "ERR_METHOD_NOT_SUPPORTED") {
|
|
485
|
+
throw error;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
} catch (error) {
|
|
489
|
+
throw new Error(`Cannot write to backup directory: ${error instanceof Error ? error.message : String(error)}`);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function moveAtomically(tempPath, finalPath) {
|
|
493
|
+
try {
|
|
494
|
+
fs13.renameSync(tempPath, finalPath);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
const err = error;
|
|
497
|
+
if (err.code === "EEXIST") {
|
|
498
|
+
throw new Error(`Destination already exists: ${finalPath}`);
|
|
499
|
+
}
|
|
500
|
+
throw error;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function cleanupDirectory(dirPath) {
|
|
504
|
+
if (fs13.existsSync(dirPath)) {
|
|
505
|
+
fs13.rmSync(dirPath, { recursive: true, force: true });
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function ensureDirectoryExists(filePath) {
|
|
509
|
+
const dir = path13.dirname(filePath);
|
|
510
|
+
if (!fs13.existsSync(dir)) {
|
|
511
|
+
fs13.mkdirSync(dir, { recursive: true });
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
var BYTES_IN_GB, SKILL_MD_FILENAME;
|
|
515
|
+
var init_fileUtils = __esm({
|
|
516
|
+
"src/lib/fileUtils.ts"() {
|
|
517
|
+
BYTES_IN_GB = 1024 ** 3;
|
|
518
|
+
SKILL_MD_FILENAME = "SKILL.md";
|
|
416
519
|
}
|
|
417
520
|
});
|
|
418
521
|
|
|
@@ -635,11 +738,12 @@ function workflowResponseToResource(workflow) {
|
|
|
635
738
|
};
|
|
636
739
|
}
|
|
637
740
|
function skillResponseToResource(skill) {
|
|
638
|
-
const fileName = skill.name.toLowerCase().replaceAll(/\s+/g, "-");
|
|
639
741
|
return {
|
|
640
742
|
name: skill.name,
|
|
641
743
|
description: skill.description || "",
|
|
642
|
-
|
|
744
|
+
// Derived from the one shared helper the backup and import writers use, so the path in the
|
|
745
|
+
// generated YAML is always the path that was actually written to disk.
|
|
746
|
+
file: skillFlatFileRelativePath(skill.name),
|
|
643
747
|
...skill.categories && skill.categories.length > 0 && { categories: skill.categories },
|
|
644
748
|
...skill.visibility && skill.visibility !== "project" && { visibility: skill.visibility }
|
|
645
749
|
};
|
|
@@ -734,6 +838,7 @@ var CHUNK_SUMMARY_ALIASES, FILE_SUMMARY_ALIASES;
|
|
|
734
838
|
var init_converters = __esm({
|
|
735
839
|
"src/lib/converters.ts"() {
|
|
736
840
|
init_checksumUtils();
|
|
841
|
+
init_fileUtils();
|
|
737
842
|
init_logger();
|
|
738
843
|
init_mcpSanitizer();
|
|
739
844
|
init_typeGuards();
|
|
@@ -741,64 +846,232 @@ var init_converters = __esm({
|
|
|
741
846
|
FILE_SUMMARY_ALIASES = /* @__PURE__ */ new Set(["file_summary", "file-summary", "file-summay"]);
|
|
742
847
|
}
|
|
743
848
|
});
|
|
744
|
-
function
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
if (!sanitized) {
|
|
748
|
-
throw new Error(`Sanitized filename is empty for input: "${name}"`);
|
|
849
|
+
function hasCompanionFileLayout(skill) {
|
|
850
|
+
if (!skill.file) {
|
|
851
|
+
return false;
|
|
749
852
|
}
|
|
750
|
-
return
|
|
853
|
+
return path13.basename(skill.file) === SKILL_MD_FILENAME2;
|
|
751
854
|
}
|
|
752
|
-
function
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
855
|
+
function findBalancedBraceIndices(pattern) {
|
|
856
|
+
const openIndices = [];
|
|
857
|
+
const balanced = /* @__PURE__ */ new Set();
|
|
858
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
859
|
+
if (pattern[i] === "{") {
|
|
860
|
+
openIndices.push(i);
|
|
861
|
+
continue;
|
|
757
862
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const availableGB = stats.bavail * stats.bsize / BYTES_IN_GB;
|
|
764
|
-
if (availableGB < minSpaceGB) {
|
|
765
|
-
throw new Error(`Insufficient disk space: ${availableGB.toFixed(2)}GB available, need ${minSpaceGB}GB`);
|
|
863
|
+
if (pattern[i] === "}") {
|
|
864
|
+
const openIndex = openIndices.pop();
|
|
865
|
+
if (openIndex !== void 0) {
|
|
866
|
+
balanced.add(openIndex);
|
|
867
|
+
balanced.add(i);
|
|
766
868
|
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
return balanced;
|
|
872
|
+
}
|
|
873
|
+
function hasUnbalancedBraces(pattern) {
|
|
874
|
+
const balanced = findBalancedBraceIndices(pattern);
|
|
875
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
876
|
+
if ((pattern[i] === "{" || pattern[i] === "}") && !balanced.has(i)) {
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return false;
|
|
881
|
+
}
|
|
882
|
+
function translatePatternToRegexSource(pattern) {
|
|
883
|
+
const balancedBraces = findBalancedBraceIndices(pattern);
|
|
884
|
+
let source = "";
|
|
885
|
+
let braceDepth = 0;
|
|
886
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
887
|
+
const char = pattern[i];
|
|
888
|
+
if (char === "*" && pattern[i + 1] === "*") {
|
|
889
|
+
source += ".*";
|
|
890
|
+
i++;
|
|
891
|
+
continue;
|
|
892
|
+
}
|
|
893
|
+
if (char === "*") {
|
|
894
|
+
source += "[^/]*";
|
|
895
|
+
continue;
|
|
896
|
+
}
|
|
897
|
+
if (char === "?") {
|
|
898
|
+
source += "[^/]";
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
if (char === "{") {
|
|
902
|
+
if (!balancedBraces.has(i)) {
|
|
903
|
+
source += "\\{";
|
|
904
|
+
continue;
|
|
770
905
|
}
|
|
906
|
+
braceDepth++;
|
|
907
|
+
source += "(?:";
|
|
908
|
+
continue;
|
|
771
909
|
}
|
|
772
|
-
|
|
773
|
-
|
|
910
|
+
if (char === "}") {
|
|
911
|
+
if (!balancedBraces.has(i)) {
|
|
912
|
+
source += "\\}";
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
braceDepth = Math.max(0, braceDepth - 1);
|
|
916
|
+
source += ")";
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
if (char === "," && braceDepth > 0) {
|
|
920
|
+
source += "|";
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
if (/[.+^$()|[\]\\]/.test(char)) {
|
|
924
|
+
source += `\\${char}`;
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
source += char;
|
|
774
928
|
}
|
|
929
|
+
return source;
|
|
775
930
|
}
|
|
776
|
-
function
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
931
|
+
function matchesExcludePattern(relPath, pattern) {
|
|
932
|
+
const isDirectoryPrefix = pattern.endsWith("/");
|
|
933
|
+
const normalizedPattern = isDirectoryPrefix ? pattern.slice(0, -1) : pattern;
|
|
934
|
+
const source = translatePatternToRegexSource(normalizedPattern);
|
|
935
|
+
if (isDirectoryPrefix) {
|
|
936
|
+
const regex2 = new RegExp(`^${source}/.*$`);
|
|
937
|
+
return regex2.test(relPath);
|
|
938
|
+
}
|
|
939
|
+
if (normalizedPattern.includes("/")) {
|
|
940
|
+
const regex2 = new RegExp(`^${source}(?:/.*)?$`);
|
|
941
|
+
return regex2.test(relPath);
|
|
942
|
+
}
|
|
943
|
+
const regex = new RegExp(`^${source}$`);
|
|
944
|
+
const segments = relPath.split("/");
|
|
945
|
+
const basename2 = segments[segments.length - 1];
|
|
946
|
+
return regex.test(basename2);
|
|
947
|
+
}
|
|
948
|
+
function readExcludePatterns(skillDir) {
|
|
949
|
+
const excludePath = path13.join(skillDir, EXCLUDE_FILE_NAME);
|
|
950
|
+
if (!fs13.existsSync(excludePath)) {
|
|
951
|
+
return [];
|
|
952
|
+
}
|
|
953
|
+
const raw = fs13.readFileSync(excludePath, "utf8");
|
|
954
|
+
const patterns = raw.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
955
|
+
for (const pattern of patterns) {
|
|
956
|
+
if (hasUnbalancedBraces(pattern)) {
|
|
957
|
+
logger.warn(
|
|
958
|
+
` \u26A0\uFE0F Unbalanced brace in exclude pattern "${pattern}" (${excludePath}) \u2014 the brace is matched as a literal character. Use {a,b} for alternation.`
|
|
959
|
+
);
|
|
783
960
|
}
|
|
784
|
-
throw error;
|
|
785
961
|
}
|
|
962
|
+
return patterns;
|
|
786
963
|
}
|
|
787
|
-
function
|
|
788
|
-
if (
|
|
789
|
-
|
|
964
|
+
function isBinaryBuffer(buffer) {
|
|
965
|
+
if (buffer.includes(0)) {
|
|
966
|
+
return true;
|
|
790
967
|
}
|
|
968
|
+
return !Buffer.from(buffer.toString("utf8"), "utf8").equals(buffer);
|
|
791
969
|
}
|
|
792
|
-
function
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
970
|
+
function toPosixPath(relPath) {
|
|
971
|
+
return relPath.split(path13.sep).join("/");
|
|
972
|
+
}
|
|
973
|
+
function buildCompanionFile(absPath, relPath) {
|
|
974
|
+
const buffer = fs13.readFileSync(absPath);
|
|
975
|
+
const binary = isBinaryBuffer(buffer);
|
|
976
|
+
const ext = path13.extname(relPath).toLowerCase();
|
|
977
|
+
const mimeType = MIME_TYPES[ext] ?? DEFAULT_MIME_TYPE;
|
|
978
|
+
return {
|
|
979
|
+
path: relPath,
|
|
980
|
+
content: binary ? buffer.toString("base64") : buffer.toString("utf8"),
|
|
981
|
+
mime_type: mimeType,
|
|
982
|
+
encoding: binary ? "base64" : "text",
|
|
983
|
+
size_bytes: buffer.length
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
function walk(currentDir, skillDir, excludePatterns, results) {
|
|
987
|
+
const entries = fs13.readdirSync(currentDir, { withFileTypes: true });
|
|
988
|
+
for (const entry of entries) {
|
|
989
|
+
const absPath = path13.join(currentDir, entry.name);
|
|
990
|
+
const relPath = toPosixPath(path13.relative(skillDir, absPath));
|
|
991
|
+
if (entry.isSymbolicLink()) {
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
if (entry.isDirectory()) {
|
|
995
|
+
if (ALWAYS_SKIPPED_DIRS.has(entry.name)) {
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
const directoryCandidates = [relPath, `${relPath}/`];
|
|
999
|
+
if (excludePatterns.some((pattern) => directoryCandidates.some((cand) => matchesExcludePattern(cand, pattern)))) {
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
walk(absPath, skillDir, excludePatterns, results);
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
if (!entry.isFile()) {
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
if (entry.name === SKILL_MD_FILENAME2 || entry.name === EXCLUDE_FILE_NAME) {
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
if (ALWAYS_SKIPPED_LOCKFILES.has(entry.name)) {
|
|
1012
|
+
continue;
|
|
1013
|
+
}
|
|
1014
|
+
if (excludePatterns.some((pattern) => matchesExcludePattern(relPath, pattern))) {
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
results.push(buildCompanionFile(absPath, relPath));
|
|
796
1018
|
}
|
|
797
1019
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
1020
|
+
function collectCompanionFiles(skillDir) {
|
|
1021
|
+
const excludePatterns = readExcludePatterns(skillDir);
|
|
1022
|
+
const results = [];
|
|
1023
|
+
walk(skillDir, skillDir, excludePatterns, results);
|
|
1024
|
+
results.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
1025
|
+
return results;
|
|
1026
|
+
}
|
|
1027
|
+
function stateHasCompanionFiles(existingState) {
|
|
1028
|
+
return Object.keys(existingState?.companionFileHashes ?? {}).length > 0;
|
|
1029
|
+
}
|
|
1030
|
+
var SKILL_MD_FILENAME2, EXCLUDE_FILE_NAME, ALWAYS_SKIPPED_DIRS, ALWAYS_SKIPPED_LOCKFILES, DEFAULT_MIME_TYPE, MIME_TYPES;
|
|
1031
|
+
var init_skillCompanionFiles = __esm({
|
|
1032
|
+
"src/lib/skillCompanionFiles.ts"() {
|
|
1033
|
+
init_logger();
|
|
1034
|
+
SKILL_MD_FILENAME2 = "SKILL.md";
|
|
1035
|
+
EXCLUDE_FILE_NAME = ".codemie-exclude";
|
|
1036
|
+
ALWAYS_SKIPPED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "evals"]);
|
|
1037
|
+
ALWAYS_SKIPPED_LOCKFILES = /* @__PURE__ */ new Set([
|
|
1038
|
+
"package-lock.json",
|
|
1039
|
+
"npm-shrinkwrap.json",
|
|
1040
|
+
"yarn.lock",
|
|
1041
|
+
"pnpm-lock.yaml",
|
|
1042
|
+
"bun.lockb",
|
|
1043
|
+
"composer.lock",
|
|
1044
|
+
"Gemfile.lock",
|
|
1045
|
+
"Cargo.lock",
|
|
1046
|
+
"poetry.lock"
|
|
1047
|
+
]);
|
|
1048
|
+
DEFAULT_MIME_TYPE = "application/octet-stream";
|
|
1049
|
+
MIME_TYPES = {
|
|
1050
|
+
".md": "text/markdown",
|
|
1051
|
+
".txt": "text/plain",
|
|
1052
|
+
".json": "application/json",
|
|
1053
|
+
".yaml": "application/yaml",
|
|
1054
|
+
".yml": "application/yaml",
|
|
1055
|
+
".js": "text/javascript",
|
|
1056
|
+
".mjs": "text/javascript",
|
|
1057
|
+
".ts": "text/plain",
|
|
1058
|
+
".py": "text/x-python",
|
|
1059
|
+
".html": "text/html",
|
|
1060
|
+
".htm": "text/html",
|
|
1061
|
+
".css": "text/css",
|
|
1062
|
+
".csv": "text/csv",
|
|
1063
|
+
".xml": "application/xml",
|
|
1064
|
+
".sh": "text/x-sh",
|
|
1065
|
+
".png": "image/png",
|
|
1066
|
+
".jpg": "image/jpeg",
|
|
1067
|
+
".jpeg": "image/jpeg",
|
|
1068
|
+
".gif": "image/gif",
|
|
1069
|
+
".svg": "image/svg+xml",
|
|
1070
|
+
".webp": "image/webp",
|
|
1071
|
+
".ico": "image/x-icon",
|
|
1072
|
+
".pdf": "application/pdf",
|
|
1073
|
+
".zip": "application/zip"
|
|
1074
|
+
};
|
|
802
1075
|
}
|
|
803
1076
|
});
|
|
804
1077
|
|
|
@@ -931,7 +1204,7 @@ function prepareWorkflowForYaml(workflow, state, assistants, backupDir) {
|
|
|
931
1204
|
let finalYamlContent = yamlConfig || "";
|
|
932
1205
|
if (yamlConfig) {
|
|
933
1206
|
try {
|
|
934
|
-
const workflowYaml =
|
|
1207
|
+
const workflowYaml = yaml7.parse(yamlConfig);
|
|
935
1208
|
const transformedAssistants = workflowYaml.assistants?.map((assistant) => {
|
|
936
1209
|
if (assistant.assistant_id && typeof assistant.assistant_id === "string") {
|
|
937
1210
|
const assistantId = assistant.assistant_id;
|
|
@@ -946,10 +1219,10 @@ function prepareWorkflowForYaml(workflow, state, assistants, backupDir) {
|
|
|
946
1219
|
if (transformedAssistants) {
|
|
947
1220
|
const transformedYaml = { ...workflowYaml, assistants: transformedAssistants };
|
|
948
1221
|
const fileName = `${sanitizeFileName(workflow.name)}.yaml`;
|
|
949
|
-
const filePath =
|
|
1222
|
+
const filePath = path13.join(backupDir, "workflows", fileName);
|
|
950
1223
|
ensureDirectoryExists(filePath);
|
|
951
|
-
finalYamlContent =
|
|
952
|
-
|
|
1224
|
+
finalYamlContent = yaml7.stringify(transformedYaml);
|
|
1225
|
+
fs13.writeFileSync(filePath, finalYamlContent, "utf8");
|
|
953
1226
|
}
|
|
954
1227
|
} catch (error) {
|
|
955
1228
|
logger.warn(
|
|
@@ -995,8 +1268,18 @@ function prepareImportedSkillForYaml(skill) {
|
|
|
995
1268
|
id: skill.id
|
|
996
1269
|
};
|
|
997
1270
|
}
|
|
998
|
-
function prepareSkillForYaml(skill, state) {
|
|
1271
|
+
function prepareSkillForYaml(skill, state, backupDir) {
|
|
999
1272
|
const resource = skillResponseToResource(skill);
|
|
1273
|
+
let companionFiles = [];
|
|
1274
|
+
if (resource.file && (skill.companion_files?.length ?? 0) > 0) {
|
|
1275
|
+
resource.file = skillMarkdownRelativePath(skill.name);
|
|
1276
|
+
if (backupDir) {
|
|
1277
|
+
const skillDir = path13.join(backupDir, path13.dirname(resource.file));
|
|
1278
|
+
if (fs13.existsSync(skillDir)) {
|
|
1279
|
+
companionFiles = collectCompanionFiles(skillDir);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1000
1283
|
if (!state.resources.skills) {
|
|
1001
1284
|
state.resources.skills = {};
|
|
1002
1285
|
}
|
|
@@ -1004,7 +1287,9 @@ function prepareSkillForYaml(skill, state) {
|
|
|
1004
1287
|
id: skill.id,
|
|
1005
1288
|
lastDeployed: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1006
1289
|
contentChecksum: calculateChecksum(skill.content || ""),
|
|
1007
|
-
configChecksum: calculateSkillConfigChecksum(resource)
|
|
1290
|
+
configChecksum: calculateSkillConfigChecksum(resource),
|
|
1291
|
+
// Omitted entirely for a companion-less skill, so its state entry stays exactly as before.
|
|
1292
|
+
...companionFiles.length > 0 ? calculateCompanionFilesChecksum(companionFiles) : {}
|
|
1008
1293
|
};
|
|
1009
1294
|
return resource;
|
|
1010
1295
|
}
|
|
@@ -1016,6 +1301,7 @@ var init_backupTransformers = __esm({
|
|
|
1016
1301
|
init_fileUtils();
|
|
1017
1302
|
init_logger();
|
|
1018
1303
|
init_mcpSanitizer();
|
|
1304
|
+
init_skillCompanionFiles();
|
|
1019
1305
|
init_skillUtils();
|
|
1020
1306
|
init_typeGuards();
|
|
1021
1307
|
}
|
|
@@ -1023,7 +1309,7 @@ var init_backupTransformers = __esm({
|
|
|
1023
1309
|
|
|
1024
1310
|
// package.json
|
|
1025
1311
|
var package_default = {
|
|
1026
|
-
version: "0.1.
|
|
1312
|
+
version: "0.1.666"};
|
|
1027
1313
|
var appConfigSchema = z.object({
|
|
1028
1314
|
rootDir: z.string(),
|
|
1029
1315
|
codemieConfig: z.string(),
|
|
@@ -1049,12 +1335,12 @@ function loadAppConfig(userConfigPath, rootDir) {
|
|
|
1049
1335
|
const sanitizedUserConfig = removeEmptyFields(userConfig);
|
|
1050
1336
|
const merged = { ...defaultConfig, ...sanitizedUserConfig };
|
|
1051
1337
|
if (sanitizedUserConfig.rootDir === void 0 && rootDir) {
|
|
1052
|
-
merged.rootDir =
|
|
1338
|
+
merged.rootDir = path13.resolve(rootDir);
|
|
1053
1339
|
}
|
|
1054
1340
|
return appConfigSchema.parse(merged);
|
|
1055
1341
|
}
|
|
1056
1342
|
if (rootDir) {
|
|
1057
|
-
return { ...defaultConfig, rootDir:
|
|
1343
|
+
return { ...defaultConfig, rootDir: path13.resolve(rootDir) };
|
|
1058
1344
|
}
|
|
1059
1345
|
const detectedRoot = findProjectRoot(process.cwd());
|
|
1060
1346
|
if (detectedRoot) {
|
|
@@ -1064,26 +1350,26 @@ function loadAppConfig(userConfigPath, rootDir) {
|
|
|
1064
1350
|
return defaultConfig;
|
|
1065
1351
|
}
|
|
1066
1352
|
function findProjectRoot(startDir) {
|
|
1067
|
-
let dir =
|
|
1353
|
+
let dir = path13.resolve(startDir);
|
|
1068
1354
|
while (true) {
|
|
1069
|
-
if (
|
|
1355
|
+
if (fs13.existsSync(path13.join(dir, PROJECT_MARKER_FILE))) {
|
|
1070
1356
|
return dir;
|
|
1071
1357
|
}
|
|
1072
|
-
const parentDir =
|
|
1073
|
-
if (parentDir === dir || dir ===
|
|
1358
|
+
const parentDir = path13.dirname(dir);
|
|
1359
|
+
if (parentDir === dir || dir === path13.parse(dir).root) {
|
|
1074
1360
|
return null;
|
|
1075
1361
|
}
|
|
1076
1362
|
dir = parentDir;
|
|
1077
1363
|
}
|
|
1078
1364
|
}
|
|
1079
1365
|
function loadUserConfig(configPath) {
|
|
1080
|
-
const resolvedPath =
|
|
1081
|
-
if (!
|
|
1366
|
+
const resolvedPath = path13.resolve(process.cwd(), configPath);
|
|
1367
|
+
if (!fs13.existsSync(resolvedPath)) {
|
|
1082
1368
|
throw new Error(`Config file not found: ${resolvedPath}`);
|
|
1083
1369
|
}
|
|
1084
1370
|
let raw;
|
|
1085
1371
|
try {
|
|
1086
|
-
raw =
|
|
1372
|
+
raw = fs13.readFileSync(resolvedPath, "utf8");
|
|
1087
1373
|
} catch (error) {
|
|
1088
1374
|
throw new Error(`Failed to read config file: ${resolvedPath}`, { cause: error });
|
|
1089
1375
|
}
|
|
@@ -1145,9 +1431,9 @@ var BackupTransaction = class {
|
|
|
1145
1431
|
isDirty = false;
|
|
1146
1432
|
saveTimer;
|
|
1147
1433
|
constructor(backupDir, transactionId) {
|
|
1148
|
-
this.transactionPath =
|
|
1434
|
+
this.transactionPath = path13.join(backupDir, "transaction.json");
|
|
1149
1435
|
try {
|
|
1150
|
-
const content =
|
|
1436
|
+
const content = fs13.readFileSync(this.transactionPath, "utf8");
|
|
1151
1437
|
this.data = JSON.parse(content);
|
|
1152
1438
|
logger.info(`\u{1F4C2} Resuming backup transaction ${this.data.id}`);
|
|
1153
1439
|
} catch (error) {
|
|
@@ -1179,9 +1465,9 @@ var BackupTransaction = class {
|
|
|
1179
1465
|
}
|
|
1180
1466
|
writeTransactionExclusively(data) {
|
|
1181
1467
|
try {
|
|
1182
|
-
const fd =
|
|
1183
|
-
|
|
1184
|
-
|
|
1468
|
+
const fd = fs13.openSync(this.transactionPath, "wx");
|
|
1469
|
+
fs13.writeSync(fd, JSON.stringify(data, null, 2));
|
|
1470
|
+
fs13.closeSync(fd);
|
|
1185
1471
|
} catch (writeError) {
|
|
1186
1472
|
const writeErr = writeError;
|
|
1187
1473
|
if (writeErr.code === "EEXIST") {
|
|
@@ -1200,7 +1486,7 @@ var BackupTransaction = class {
|
|
|
1200
1486
|
if (delayMs > 0) {
|
|
1201
1487
|
busyWaitDelay(delayMs);
|
|
1202
1488
|
}
|
|
1203
|
-
const content =
|
|
1489
|
+
const content = fs13.readFileSync(this.transactionPath, "utf8");
|
|
1204
1490
|
this.data = JSON.parse(content);
|
|
1205
1491
|
logger.info(`\u{1F4C2} Resuming backup transaction ${this.data.id} (created by concurrent process)`);
|
|
1206
1492
|
break;
|
|
@@ -1223,7 +1509,7 @@ var BackupTransaction = class {
|
|
|
1223
1509
|
*/
|
|
1224
1510
|
async save() {
|
|
1225
1511
|
ensureDirectoryExists(this.transactionPath);
|
|
1226
|
-
const savePromise =
|
|
1512
|
+
const savePromise = fs13.promises.writeFile(this.transactionPath, JSON.stringify(this.data, null, 2), "utf8");
|
|
1227
1513
|
let timeoutId;
|
|
1228
1514
|
const timeoutPromise = new Promise((_, reject) => {
|
|
1229
1515
|
timeoutId = setTimeout(
|
|
@@ -1249,7 +1535,7 @@ var BackupTransaction = class {
|
|
|
1249
1535
|
*/
|
|
1250
1536
|
saveSyncInternal() {
|
|
1251
1537
|
ensureDirectoryExists(this.transactionPath);
|
|
1252
|
-
|
|
1538
|
+
fs13.writeFileSync(this.transactionPath, JSON.stringify(this.data, null, 2), "utf8");
|
|
1253
1539
|
this.isDirty = false;
|
|
1254
1540
|
}
|
|
1255
1541
|
/**
|
|
@@ -1360,8 +1646,8 @@ var BackupTransaction = class {
|
|
|
1360
1646
|
* Clean up transaction file after successful completion
|
|
1361
1647
|
*/
|
|
1362
1648
|
cleanup() {
|
|
1363
|
-
if (
|
|
1364
|
-
|
|
1649
|
+
if (fs13.existsSync(this.transactionPath)) {
|
|
1650
|
+
fs13.unlinkSync(this.transactionPath);
|
|
1365
1651
|
}
|
|
1366
1652
|
}
|
|
1367
1653
|
};
|
|
@@ -1447,14 +1733,14 @@ function generateCodemieYaml(backup, projectName, backupDir, integrationSpecPath
|
|
|
1447
1733
|
(workflow) => prepareWorkflowForYaml(workflow, backup.state, backup.resources.assistants, backupDir)
|
|
1448
1734
|
),
|
|
1449
1735
|
...ownedSkills.length > 0 && {
|
|
1450
|
-
skills: ownedSkills.map((skill) => prepareSkillForYaml(skill, backup.state))
|
|
1736
|
+
skills: ownedSkills.map((skill) => prepareSkillForYaml(skill, backup.state, backupDir))
|
|
1451
1737
|
}
|
|
1452
1738
|
}
|
|
1453
1739
|
};
|
|
1454
|
-
return
|
|
1740
|
+
return yaml7.stringify(config);
|
|
1455
1741
|
}
|
|
1456
1742
|
function saveIntegrationOpenApiSpecs(backupData, backupDir) {
|
|
1457
|
-
const specsDir =
|
|
1743
|
+
const specsDir = path13.join(backupDir, "openapi_specs");
|
|
1458
1744
|
let specsCount = 0;
|
|
1459
1745
|
const integrationSpecPaths = /* @__PURE__ */ new Map();
|
|
1460
1746
|
for (const integration of backupData.resources.integrations) {
|
|
@@ -1467,8 +1753,8 @@ function saveIntegrationOpenApiSpecs(backupData, backupDir) {
|
|
|
1467
1753
|
if (specEntry && typeof specEntry.value === "string" && specEntry.value) {
|
|
1468
1754
|
const alias = integration.alias || integration.id;
|
|
1469
1755
|
const fileName = String(alias).toLowerCase().replaceAll(/[^a-z0-9]+/g, "-");
|
|
1470
|
-
if (!
|
|
1471
|
-
|
|
1756
|
+
if (!fs13.existsSync(specsDir)) {
|
|
1757
|
+
fs13.mkdirSync(specsDir, { recursive: true });
|
|
1472
1758
|
}
|
|
1473
1759
|
const specContent = specEntry.value;
|
|
1474
1760
|
let fileExtension = ".yaml";
|
|
@@ -1481,8 +1767,8 @@ function saveIntegrationOpenApiSpecs(backupData, backupDir) {
|
|
|
1481
1767
|
fileExtension = ".yaml";
|
|
1482
1768
|
}
|
|
1483
1769
|
const specFileName = `${fileName}${fileExtension}`;
|
|
1484
|
-
const specPath =
|
|
1485
|
-
|
|
1770
|
+
const specPath = path13.join(specsDir, specFileName);
|
|
1771
|
+
fs13.writeFileSync(specPath, contentToSave, "utf8");
|
|
1486
1772
|
integrationSpecPaths.set(integration.id, `openapi_specs/${specFileName}`);
|
|
1487
1773
|
specsCount++;
|
|
1488
1774
|
}
|
|
@@ -1495,15 +1781,15 @@ function saveIntegrationOpenApiSpecs(backupData, backupDir) {
|
|
|
1495
1781
|
function saveBackupFiles(backupData, backupDir, projectName) {
|
|
1496
1782
|
logger.info("\u{1F4BE} Writing backup files...\n");
|
|
1497
1783
|
const integrationSpecPaths = saveIntegrationOpenApiSpecs(backupData, backupDir);
|
|
1498
|
-
const codemieYamlPath =
|
|
1784
|
+
const codemieYamlPath = path13.join(backupDir, "codemie.yaml");
|
|
1499
1785
|
const codemieYaml = generateCodemieYaml(backupData, projectName, backupDir, integrationSpecPaths);
|
|
1500
|
-
|
|
1786
|
+
fs13.writeFileSync(codemieYamlPath, codemieYaml, "utf8");
|
|
1501
1787
|
logger.info(` \u2713 Saved config file: codemie.yaml`);
|
|
1502
|
-
const backupJsonPath =
|
|
1503
|
-
|
|
1788
|
+
const backupJsonPath = path13.join(backupDir, "backup.json");
|
|
1789
|
+
fs13.writeFileSync(backupJsonPath, JSON.stringify(backupData, null, 2), "utf8");
|
|
1504
1790
|
logger.info(` \u2713 Saved full backup: backup.json`);
|
|
1505
|
-
const statePath =
|
|
1506
|
-
|
|
1791
|
+
const statePath = path13.join(backupDir, "state.json");
|
|
1792
|
+
fs13.writeFileSync(statePath, JSON.stringify(backupData.state, null, 2), "utf8");
|
|
1507
1793
|
logger.info(` \u2713 Saved state file: state.json`);
|
|
1508
1794
|
}
|
|
1509
1795
|
async function createClient(config) {
|
|
@@ -1545,8 +1831,8 @@ function resolveImports(obj, baseDir, visitedFiles = /* @__PURE__ */ new Set())
|
|
|
1545
1831
|
const value = obj[key];
|
|
1546
1832
|
if (isPlainObject3(value) && "$import" in value) {
|
|
1547
1833
|
const importDirective = value;
|
|
1548
|
-
const importPath =
|
|
1549
|
-
const normalizedPath =
|
|
1834
|
+
const importPath = path13.join(baseDir, importDirective.$import);
|
|
1835
|
+
const normalizedPath = path13.resolve(importPath);
|
|
1550
1836
|
if (visitedFiles.has(normalizedPath)) {
|
|
1551
1837
|
throw new Error(
|
|
1552
1838
|
`Circular import detected: ${normalizedPath}
|
|
@@ -1556,7 +1842,7 @@ Import chain: ${[...visitedFiles].join(" \u2192 ")} \u2192 ${normalizedPath}`
|
|
|
1556
1842
|
visitedFiles.add(normalizedPath);
|
|
1557
1843
|
const imported = loadYamlFile(importPath);
|
|
1558
1844
|
obj[key] = imported;
|
|
1559
|
-
resolveImports(obj[key],
|
|
1845
|
+
resolveImports(obj[key], path13.dirname(importPath), visitedFiles);
|
|
1560
1846
|
visitedFiles.delete(normalizedPath);
|
|
1561
1847
|
} else if (Array.isArray(value)) {
|
|
1562
1848
|
obj[key] = resolveArrayImports(value, baseDir, visitedFiles);
|
|
@@ -1570,8 +1856,8 @@ function resolveArrayImports(arr, baseDir, visitedFiles = /* @__PURE__ */ new Se
|
|
|
1570
1856
|
for (const item of arr) {
|
|
1571
1857
|
if (isPlainObject3(item) && "$import" in item) {
|
|
1572
1858
|
const importDirective = item;
|
|
1573
|
-
const importPath =
|
|
1574
|
-
const normalizedPath =
|
|
1859
|
+
const importPath = path13.join(baseDir, importDirective.$import);
|
|
1860
|
+
const normalizedPath = path13.resolve(importPath);
|
|
1575
1861
|
if (visitedFiles.has(normalizedPath)) {
|
|
1576
1862
|
throw new Error(
|
|
1577
1863
|
`Circular import detected: ${normalizedPath}
|
|
@@ -1581,13 +1867,13 @@ Import chain: ${[...visitedFiles].join(" \u2192 ")} \u2192 ${normalizedPath}`
|
|
|
1581
1867
|
visitedFiles.add(normalizedPath);
|
|
1582
1868
|
const imported = loadYamlFile(importPath);
|
|
1583
1869
|
if (Array.isArray(imported)) {
|
|
1584
|
-
const resolvedArray = resolveArrayImports(imported,
|
|
1870
|
+
const resolvedArray = resolveArrayImports(imported, path13.dirname(importPath), visitedFiles);
|
|
1585
1871
|
for (const resolvedItem of resolvedArray) {
|
|
1586
1872
|
result.push(resolvedItem);
|
|
1587
1873
|
}
|
|
1588
1874
|
} else if (isPlainObject3(imported)) {
|
|
1589
1875
|
result.push(imported);
|
|
1590
|
-
resolveImports(imported,
|
|
1876
|
+
resolveImports(imported, path13.dirname(importPath), visitedFiles);
|
|
1591
1877
|
} else {
|
|
1592
1878
|
throw new TypeError(
|
|
1593
1879
|
`Import file ${importPath} must contain either an object or an array. Got: ${typeof imported}`
|
|
@@ -1604,12 +1890,12 @@ Import chain: ${[...visitedFiles].join(" \u2192 ")} \u2192 ${normalizedPath}`
|
|
|
1604
1890
|
return result;
|
|
1605
1891
|
}
|
|
1606
1892
|
function loadYamlFile(filePath) {
|
|
1607
|
-
if (!
|
|
1893
|
+
if (!fs13.existsSync(filePath)) {
|
|
1608
1894
|
throw new Error(`Import file not found: ${filePath}`);
|
|
1609
1895
|
}
|
|
1610
1896
|
try {
|
|
1611
|
-
const content =
|
|
1612
|
-
const parsed =
|
|
1897
|
+
const content = fs13.readFileSync(filePath, "utf8");
|
|
1898
|
+
const parsed = yaml7.parse(content);
|
|
1613
1899
|
if (parsed === null || parsed === void 0) {
|
|
1614
1900
|
throw new TypeError(`Import file ${filePath} is empty`);
|
|
1615
1901
|
}
|
|
@@ -1622,7 +1908,7 @@ function loadYamlFile(filePath) {
|
|
|
1622
1908
|
}
|
|
1623
1909
|
}
|
|
1624
1910
|
function findResourceDefinition(rootDir, codemieConfigPath, plural, name) {
|
|
1625
|
-
const configPath =
|
|
1911
|
+
const configPath = path13.join(rootDir, codemieConfigPath);
|
|
1626
1912
|
const config = loadYamlFile(configPath);
|
|
1627
1913
|
if (!isPlainObject3(config) || !isPlainObject3(config.resources)) {
|
|
1628
1914
|
return void 0;
|
|
@@ -1639,8 +1925,8 @@ function findResourceInList(items, baseDir, currentFile, name, visitedFiles) {
|
|
|
1639
1925
|
continue;
|
|
1640
1926
|
}
|
|
1641
1927
|
if (typeof item.$import === "string") {
|
|
1642
|
-
const importPath =
|
|
1643
|
-
const normalizedPath =
|
|
1928
|
+
const importPath = path13.join(baseDir, item.$import);
|
|
1929
|
+
const normalizedPath = path13.resolve(importPath);
|
|
1644
1930
|
if (visitedFiles.has(normalizedPath)) {
|
|
1645
1931
|
throw new Error(
|
|
1646
1932
|
`Circular import detected: ${normalizedPath}
|
|
@@ -1651,7 +1937,7 @@ Import chain: ${[...visitedFiles].join(" \u2192 ")} \u2192 ${normalizedPath}`
|
|
|
1651
1937
|
const loaded = loadYamlFile(importPath);
|
|
1652
1938
|
let found;
|
|
1653
1939
|
if (Array.isArray(loaded)) {
|
|
1654
|
-
found = findResourceInList(loaded,
|
|
1940
|
+
found = findResourceInList(loaded, path13.dirname(importPath), normalizedPath, name, visitedFiles);
|
|
1655
1941
|
} else if (isPlainObject3(loaded) && typeof loaded.name === "string" && namesEqual(loaded.name, name)) {
|
|
1656
1942
|
found = { file: normalizedPath, resource: loaded, inList: false };
|
|
1657
1943
|
}
|
|
@@ -1668,6 +1954,214 @@ Import chain: ${[...visitedFiles].join(" \u2192 ")} \u2192 ${normalizedPath}`
|
|
|
1668
1954
|
return void 0;
|
|
1669
1955
|
}
|
|
1670
1956
|
|
|
1957
|
+
// src/lib/validationUtils.ts
|
|
1958
|
+
var MIN_SKILL_DESCRIPTION_LENGTH = 10;
|
|
1959
|
+
var MAX_SKILL_DESCRIPTION_LENGTH = 1e3;
|
|
1960
|
+
function isAssistantWithSlug(obj) {
|
|
1961
|
+
return typeof obj === "object" && obj !== null && "slug" in obj && "name" in obj && typeof obj.slug === "string" && typeof obj.name === "string";
|
|
1962
|
+
}
|
|
1963
|
+
function isAssistant(obj) {
|
|
1964
|
+
return typeof obj === "object" && obj !== null && "id" in obj && "slug" in obj;
|
|
1965
|
+
}
|
|
1966
|
+
function validateSlugUniqueness(config) {
|
|
1967
|
+
const slugErrors = [];
|
|
1968
|
+
const slugMap = /* @__PURE__ */ new Map();
|
|
1969
|
+
if (config.resources.assistants) {
|
|
1970
|
+
for (const assistant of config.resources.assistants) {
|
|
1971
|
+
if (assistant.slug) {
|
|
1972
|
+
if (!slugMap.has(assistant.slug)) {
|
|
1973
|
+
slugMap.set(assistant.slug, []);
|
|
1974
|
+
}
|
|
1975
|
+
slugMap.get(assistant.slug).push(assistant.name);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
for (const [slug, names] of slugMap.entries()) {
|
|
1980
|
+
if (names.length > 1) {
|
|
1981
|
+
slugErrors.push(`Duplicate slug "${slug}" for assistants: ${names.join(", ")}`);
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
return slugErrors;
|
|
1985
|
+
}
|
|
1986
|
+
async function checkApiSlugConflicts({
|
|
1987
|
+
config,
|
|
1988
|
+
client,
|
|
1989
|
+
assistantState
|
|
1990
|
+
}) {
|
|
1991
|
+
const existingAssistants = await client.assistants.list({
|
|
1992
|
+
minimal_response: false,
|
|
1993
|
+
per_page: 100
|
|
1994
|
+
});
|
|
1995
|
+
const existingSlugs = /* @__PURE__ */ new Map();
|
|
1996
|
+
for (const assistant of existingAssistants) {
|
|
1997
|
+
if (isAssistantWithSlug(assistant) && assistant.slug) {
|
|
1998
|
+
existingSlugs.set(assistant.slug, assistant.name);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
const conflictErrors = [];
|
|
2002
|
+
const iacAssistantNames = new Set(Object.keys(assistantState));
|
|
2003
|
+
if (config.resources.assistants) {
|
|
2004
|
+
for (const assistant of config.resources.assistants) {
|
|
2005
|
+
if (!assistant.slug || iacAssistantNames.has(assistant.name)) {
|
|
2006
|
+
continue;
|
|
2007
|
+
}
|
|
2008
|
+
if (existingSlugs.has(assistant.slug)) {
|
|
2009
|
+
const existingName = existingSlugs.get(assistant.slug);
|
|
2010
|
+
const existingAssistant = existingAssistants.find((a) => isAssistant(a) && a.slug === assistant.slug);
|
|
2011
|
+
conflictErrors.push(
|
|
2012
|
+
`\u274C Slug "${assistant.slug}" for assistant "${assistant.name}" already exists in Codemie
|
|
2013
|
+
Existing assistant: "${existingName}" (ID: ${isAssistant(existingAssistant) ? existingAssistant.id : "unknown"})
|
|
2014
|
+
\u{1F4A1} Change slug to a unique value or omit slug (platform will generate)`
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
return conflictErrors;
|
|
2020
|
+
}
|
|
2021
|
+
function validateSkillDescriptions(skills) {
|
|
2022
|
+
const errors = [];
|
|
2023
|
+
for (const skill of skills) {
|
|
2024
|
+
const length = skill.description?.length ?? 0;
|
|
2025
|
+
if (length < MIN_SKILL_DESCRIPTION_LENGTH || length > MAX_SKILL_DESCRIPTION_LENGTH) {
|
|
2026
|
+
errors.push(
|
|
2027
|
+
`\u274C Skill "${skill.name}" description length is ${length} characters
|
|
2028
|
+
\u{1F4A1} Allowed range: ${MIN_SKILL_DESCRIPTION_LENGTH}-${MAX_SKILL_DESCRIPTION_LENGTH} characters`
|
|
2029
|
+
);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
return errors;
|
|
2033
|
+
}
|
|
2034
|
+
function validateSkillContentLengths(entries, limits) {
|
|
2035
|
+
const errors = [];
|
|
2036
|
+
for (const entry of entries) {
|
|
2037
|
+
const length = entry.content?.length ?? 0;
|
|
2038
|
+
if (length < limits.min_content_length || length > limits.max_content_length) {
|
|
2039
|
+
errors.push(
|
|
2040
|
+
`\u274C Skill "${entry.name}" content length is ${length} characters
|
|
2041
|
+
\u{1F4A1} Allowed range: ${limits.min_content_length}-${limits.max_content_length} characters`
|
|
2042
|
+
);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
return errors;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
// src/lib/skillSourceLoader.ts
|
|
2049
|
+
var SKILL_MD_FILENAME3 = "SKILL.md";
|
|
2050
|
+
var SKILL_NAME_PATTERN = /^[a-z0-9][a-z0-9-]{1,62}[a-z0-9]$/;
|
|
2051
|
+
var BOM = "\uFEFF";
|
|
2052
|
+
var FRONT_MATTER_PATTERN = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
2053
|
+
function stripBom(raw) {
|
|
2054
|
+
return raw.charCodeAt(0) === BOM.charCodeAt(0) ? raw.slice(1) : raw;
|
|
2055
|
+
}
|
|
2056
|
+
function parseSkillFrontMatter(raw, sourcePath = SKILL_MD_FILENAME3) {
|
|
2057
|
+
const content = stripBom(raw);
|
|
2058
|
+
const match = content.match(FRONT_MATTER_PATTERN);
|
|
2059
|
+
if (!match) {
|
|
2060
|
+
return { frontMatter: {}, body: content };
|
|
2061
|
+
}
|
|
2062
|
+
const [, yamlBlock, body] = match;
|
|
2063
|
+
let parsed;
|
|
2064
|
+
try {
|
|
2065
|
+
parsed = yaml7.parse(yamlBlock);
|
|
2066
|
+
} catch (error) {
|
|
2067
|
+
throw new Error(
|
|
2068
|
+
`Invalid YAML front matter in ${sourcePath}: ${error instanceof Error ? error.message : String(error)}`
|
|
2069
|
+
);
|
|
2070
|
+
}
|
|
2071
|
+
const frontMatter = parsed !== null && typeof parsed === "object" ? parsed : {};
|
|
2072
|
+
return { frontMatter, body };
|
|
2073
|
+
}
|
|
2074
|
+
function readIgnoreSet(rootDir, ignoreFile, sourceDir) {
|
|
2075
|
+
if (!ignoreFile) {
|
|
2076
|
+
return /* @__PURE__ */ new Set();
|
|
2077
|
+
}
|
|
2078
|
+
const resolvedIgnorePath = path13.join(rootDir, ignoreFile);
|
|
2079
|
+
if (!fs13.existsSync(resolvedIgnorePath)) {
|
|
2080
|
+
throw new Error(
|
|
2081
|
+
`Skill ignore file not found: ${resolvedIgnorePath} (from ignore_file "${ignoreFile}" in source_dir "${sourceDir}")`
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2084
|
+
let parsed;
|
|
2085
|
+
try {
|
|
2086
|
+
const content = fs13.readFileSync(resolvedIgnorePath, "utf8");
|
|
2087
|
+
parsed = yaml7.parse(content);
|
|
2088
|
+
} catch (error) {
|
|
2089
|
+
throw new Error(
|
|
2090
|
+
`Invalid YAML in skill ignore file ${resolvedIgnorePath} (from source_dir "${sourceDir}"): ${error instanceof Error ? error.message : String(error)}`
|
|
2091
|
+
);
|
|
2092
|
+
}
|
|
2093
|
+
return new Set(parsed?.skills ?? []);
|
|
2094
|
+
}
|
|
2095
|
+
function stringOrUndefined(value) {
|
|
2096
|
+
return typeof value === "string" ? value : void 0;
|
|
2097
|
+
}
|
|
2098
|
+
function expandOneSourceDir(entry, rootDir) {
|
|
2099
|
+
const sourceDir = entry.source_dir;
|
|
2100
|
+
const resolvedSourceDir = path13.join(rootDir, sourceDir);
|
|
2101
|
+
if (!fs13.existsSync(resolvedSourceDir) || !fs13.statSync(resolvedSourceDir).isDirectory()) {
|
|
2102
|
+
throw new Error(`Skill source directory not found: ${resolvedSourceDir} (from source_dir "${sourceDir}")`);
|
|
2103
|
+
}
|
|
2104
|
+
const ignoreSet = readIgnoreSet(rootDir, entry.ignore_file, sourceDir);
|
|
2105
|
+
const dirNames = fs13.readdirSync(resolvedSourceDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name).filter((dirName) => !ignoreSet.has(dirName)).sort();
|
|
2106
|
+
const expanded = [];
|
|
2107
|
+
for (const dirName of dirNames) {
|
|
2108
|
+
const skillMdPath = path13.join(resolvedSourceDir, dirName, SKILL_MD_FILENAME3);
|
|
2109
|
+
if (!fs13.existsSync(skillMdPath)) {
|
|
2110
|
+
continue;
|
|
2111
|
+
}
|
|
2112
|
+
const raw = fs13.readFileSync(skillMdPath, "utf8");
|
|
2113
|
+
const { frontMatter, body } = parseSkillFrontMatter(raw, skillMdPath);
|
|
2114
|
+
const name = stringOrUndefined(frontMatter.name) ?? dirName;
|
|
2115
|
+
const description = stringOrUndefined(frontMatter.description);
|
|
2116
|
+
if (!SKILL_NAME_PATTERN.test(name)) {
|
|
2117
|
+
throw new Error(
|
|
2118
|
+
`\u274C Skill "${name}" (from directory "${dirName}" in source_dir "${sourceDir}") has an invalid name
|
|
2119
|
+
\u{1F4A1} Names must be kebab-case, 3-64 characters, and start and end with a letter or digit`
|
|
2120
|
+
);
|
|
2121
|
+
}
|
|
2122
|
+
const resource = {
|
|
2123
|
+
name,
|
|
2124
|
+
description: description ?? "",
|
|
2125
|
+
file: path13.join(sourceDir, dirName, SKILL_MD_FILENAME3),
|
|
2126
|
+
content: body,
|
|
2127
|
+
...entry.categories !== void 0 ? { categories: entry.categories } : {},
|
|
2128
|
+
...entry.visibility !== void 0 ? { visibility: entry.visibility } : {},
|
|
2129
|
+
...entry.group !== void 0 ? { group: entry.group } : {}
|
|
2130
|
+
};
|
|
2131
|
+
expanded.push({ resource, origin: `directory "${dirName}" in source_dir "${sourceDir}"` });
|
|
2132
|
+
}
|
|
2133
|
+
return expanded;
|
|
2134
|
+
}
|
|
2135
|
+
function expandSkillSourceDirs(skills, rootDir) {
|
|
2136
|
+
const collected = [];
|
|
2137
|
+
const descriptionErrors = [];
|
|
2138
|
+
for (const skill of skills) {
|
|
2139
|
+
if (!skill.source_dir) {
|
|
2140
|
+
collected.push({ resource: skill, origin: `hand-written entry "${skill.name}"` });
|
|
2141
|
+
continue;
|
|
2142
|
+
}
|
|
2143
|
+
const expanded = expandOneSourceDir(skill, rootDir);
|
|
2144
|
+
descriptionErrors.push(...validateSkillDescriptions(expanded.map((item) => item.resource)));
|
|
2145
|
+
collected.push(...expanded);
|
|
2146
|
+
}
|
|
2147
|
+
if (descriptionErrors.length > 0) {
|
|
2148
|
+
throw new Error(descriptionErrors.join("\n\n"));
|
|
2149
|
+
}
|
|
2150
|
+
const originByName = /* @__PURE__ */ new Map();
|
|
2151
|
+
for (const { resource, origin } of collected) {
|
|
2152
|
+
const key = resource.name.toLowerCase();
|
|
2153
|
+
const previousOrigin = originByName.get(key);
|
|
2154
|
+
if (previousOrigin !== void 0) {
|
|
2155
|
+
throw new Error(
|
|
2156
|
+
`\u274C Duplicate skill name "${resource.name}": defined by ${previousOrigin} and ${origin}
|
|
2157
|
+
\u{1F4A1} Skill names must be unique across every source_dir and hand-written entry`
|
|
2158
|
+
);
|
|
2159
|
+
}
|
|
2160
|
+
originByName.set(key, origin);
|
|
2161
|
+
}
|
|
2162
|
+
return collected.map((item) => item.resource);
|
|
2163
|
+
}
|
|
2164
|
+
|
|
1671
2165
|
// src/lib/codemieConfigLoader.ts
|
|
1672
2166
|
var CodemieConfigLoader = class {
|
|
1673
2167
|
appConfig;
|
|
@@ -1679,14 +2173,17 @@ var CodemieConfigLoader = class {
|
|
|
1679
2173
|
*/
|
|
1680
2174
|
loadConfig() {
|
|
1681
2175
|
const { rootDir, codemieConfig } = this.appConfig;
|
|
1682
|
-
const configPath =
|
|
1683
|
-
if (!
|
|
2176
|
+
const configPath = path13.join(rootDir, codemieConfig);
|
|
2177
|
+
if (!fs13.existsSync(configPath)) {
|
|
1684
2178
|
throw new Error(`Configuration file not found: ${configPath}`);
|
|
1685
2179
|
}
|
|
1686
|
-
const content =
|
|
1687
|
-
const config =
|
|
2180
|
+
const content = fs13.readFileSync(configPath, "utf8");
|
|
2181
|
+
const config = yaml7.parse(content);
|
|
1688
2182
|
resolveImports(config, rootDir);
|
|
1689
2183
|
this.substituteEnvVars(config);
|
|
2184
|
+
if (config.resources.skills) {
|
|
2185
|
+
config.resources.skills = expandSkillSourceDirs(config.resources.skills, rootDir);
|
|
2186
|
+
}
|
|
1690
2187
|
this.applyDatasourceDefaults(config);
|
|
1691
2188
|
this.resolveReferencesRecursive(config, config);
|
|
1692
2189
|
this.validateDatasourceIntegrationReferences(config);
|
|
@@ -1697,34 +2194,48 @@ var CodemieConfigLoader = class {
|
|
|
1697
2194
|
*/
|
|
1698
2195
|
loadPrompt(promptPath) {
|
|
1699
2196
|
const { rootDir } = this.appConfig;
|
|
1700
|
-
const fullPath =
|
|
1701
|
-
if (!
|
|
2197
|
+
const fullPath = path13.join(rootDir, promptPath);
|
|
2198
|
+
if (!fs13.existsSync(fullPath)) {
|
|
1702
2199
|
throw new Error(`Prompt file not found: ${fullPath}`);
|
|
1703
2200
|
}
|
|
1704
|
-
return
|
|
2201
|
+
return fs13.readFileSync(fullPath, "utf8");
|
|
1705
2202
|
}
|
|
1706
2203
|
/**
|
|
1707
2204
|
* Load skill content file (.skill.md)
|
|
1708
2205
|
*/
|
|
1709
2206
|
loadSkillContent(contentPath) {
|
|
1710
2207
|
const { rootDir } = this.appConfig;
|
|
1711
|
-
const fullPath =
|
|
1712
|
-
if (!
|
|
2208
|
+
const fullPath = path13.join(rootDir, contentPath);
|
|
2209
|
+
if (!fs13.existsSync(fullPath)) {
|
|
1713
2210
|
throw new Error(`Skill content file not found: ${fullPath}`);
|
|
1714
2211
|
}
|
|
1715
|
-
return
|
|
2212
|
+
return fs13.readFileSync(fullPath, "utf8");
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Resolve a skill's content: prefers an already-loaded `content` (e.g. from an expanded
|
|
2216
|
+
* `source_dir` entry) and otherwise falls back to reading `file`. This is the single
|
|
2217
|
+
* content accessor for skills — every consumer routes through it.
|
|
2218
|
+
*/
|
|
2219
|
+
resolveSkillContent(skill) {
|
|
2220
|
+
if (skill.content !== void 0) {
|
|
2221
|
+
return skill.content;
|
|
2222
|
+
}
|
|
2223
|
+
if (skill.file) {
|
|
2224
|
+
return this.loadSkillContent(skill.file);
|
|
2225
|
+
}
|
|
2226
|
+
throw new Error(`Skill "${skill.name}" has neither 'content' nor 'file' to load content from`);
|
|
1716
2227
|
}
|
|
1717
2228
|
/**
|
|
1718
2229
|
* Load assistant configuration file
|
|
1719
2230
|
*/
|
|
1720
2231
|
loadAssistantConfig(configPath) {
|
|
1721
2232
|
const { rootDir } = this.appConfig;
|
|
1722
|
-
const fullPath =
|
|
1723
|
-
if (!
|
|
2233
|
+
const fullPath = path13.join(rootDir, configPath);
|
|
2234
|
+
if (!fs13.existsSync(fullPath)) {
|
|
1724
2235
|
throw new Error(`Config file not found: ${fullPath}`);
|
|
1725
2236
|
}
|
|
1726
|
-
const content =
|
|
1727
|
-
return
|
|
2237
|
+
const content = fs13.readFileSync(fullPath, "utf8");
|
|
2238
|
+
return yaml7.parse(content);
|
|
1728
2239
|
}
|
|
1729
2240
|
/**
|
|
1730
2241
|
* Validate that all referenced files exist
|
|
@@ -1736,12 +2247,12 @@ var CodemieConfigLoader = class {
|
|
|
1736
2247
|
for (const assistant of config.resources.assistants) {
|
|
1737
2248
|
if (!assistant.prompt) {
|
|
1738
2249
|
errors.push(`Missing 'prompt' for assistant: ${assistant.name}`);
|
|
1739
|
-
} else if (!
|
|
2250
|
+
} else if (!fs13.existsSync(path13.join(rootDir, assistant.prompt))) {
|
|
1740
2251
|
errors.push(`Prompt file not found for ${assistant.name}: ${assistant.prompt}`);
|
|
1741
2252
|
}
|
|
1742
2253
|
if (assistant.config) {
|
|
1743
|
-
const configPath =
|
|
1744
|
-
if (!
|
|
2254
|
+
const configPath = path13.join(rootDir, assistant.config);
|
|
2255
|
+
if (!fs13.existsSync(configPath)) {
|
|
1745
2256
|
errors.push(`Config file not found for ${assistant.name}: ${assistant.config}`);
|
|
1746
2257
|
}
|
|
1747
2258
|
}
|
|
@@ -1755,15 +2266,16 @@ var CodemieConfigLoader = class {
|
|
|
1755
2266
|
}
|
|
1756
2267
|
if (config.resources.skills) {
|
|
1757
2268
|
for (const skill of config.resources.skills) {
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
errors.push(`
|
|
2269
|
+
const hasFile = !!skill.file;
|
|
2270
|
+
const hasContent = skill.content !== void 0;
|
|
2271
|
+
if (!hasFile && !hasContent) {
|
|
2272
|
+
errors.push(`Skill '${skill.name}' must specify at least one of 'file' or 'content'`);
|
|
1762
2273
|
}
|
|
1763
|
-
if (!skill.
|
|
1764
|
-
errors.push(`
|
|
2274
|
+
if (hasFile && !fs13.existsSync(path13.join(rootDir, skill.file))) {
|
|
2275
|
+
errors.push(`Content file not found for skill ${skill.name}: ${skill.file}`);
|
|
1765
2276
|
}
|
|
1766
2277
|
}
|
|
2278
|
+
errors.push(...validateSkillDescriptions(config.resources.skills));
|
|
1767
2279
|
}
|
|
1768
2280
|
for (const skill of config.imported?.skills || []) {
|
|
1769
2281
|
if (!skill.name) {
|
|
@@ -1786,28 +2298,28 @@ var CodemieConfigLoader = class {
|
|
|
1786
2298
|
* @param rootConfig - Root config object (constant reference for resolving paths like "imported.integrations.xxx")
|
|
1787
2299
|
* @param path - Current path in config tree (for error messages, e.g., "resources.assistants[0].toolkits")
|
|
1788
2300
|
*/
|
|
1789
|
-
resolveReferencesRecursive(current, rootConfig,
|
|
2301
|
+
resolveReferencesRecursive(current, rootConfig, path19 = "") {
|
|
1790
2302
|
if (!current || typeof current !== "object") {
|
|
1791
2303
|
return;
|
|
1792
2304
|
}
|
|
1793
2305
|
if (Array.isArray(current)) {
|
|
1794
|
-
this.resolveArrayReferences(current, rootConfig,
|
|
2306
|
+
this.resolveArrayReferences(current, rootConfig, path19);
|
|
1795
2307
|
return;
|
|
1796
2308
|
}
|
|
1797
2309
|
if ("$ref" in current && typeof current.$ref === "string") {
|
|
1798
|
-
this.resolveObjectReference(current, rootConfig,
|
|
2310
|
+
this.resolveObjectReference(current, rootConfig, path19);
|
|
1799
2311
|
return;
|
|
1800
2312
|
}
|
|
1801
|
-
this.resolveObjectProperties(current, rootConfig,
|
|
2313
|
+
this.resolveObjectProperties(current, rootConfig, path19);
|
|
1802
2314
|
}
|
|
1803
2315
|
/**
|
|
1804
2316
|
* Resolve $ref items in arrays and flatten if they point to arrays
|
|
1805
2317
|
* Example: [{ $ref: "context_definitions.repos" }] where repos is [item1, item2]
|
|
1806
2318
|
* becomes [item1, item2]
|
|
1807
2319
|
*/
|
|
1808
|
-
resolveArrayReferences(arr, rootConfig,
|
|
2320
|
+
resolveArrayReferences(arr, rootConfig, path19) {
|
|
1809
2321
|
const result = arr.flatMap((item, i) => {
|
|
1810
|
-
const contextPath = `${
|
|
2322
|
+
const contextPath = `${path19}[${i}]`;
|
|
1811
2323
|
if (!this.isRefObject(item) || item.$ref.startsWith("#")) {
|
|
1812
2324
|
this.resolveReferencesRecursive(item, rootConfig, contextPath);
|
|
1813
2325
|
return [item];
|
|
@@ -1825,9 +2337,9 @@ var CodemieConfigLoader = class {
|
|
|
1825
2337
|
* Resolve object reference: { $ref: "path" }
|
|
1826
2338
|
* Replaces object with resolved data (in-place mutation)
|
|
1827
2339
|
*/
|
|
1828
|
-
resolveObjectReference(current, rootConfig,
|
|
2340
|
+
resolveObjectReference(current, rootConfig, path19) {
|
|
1829
2341
|
const refPath = current.$ref;
|
|
1830
|
-
const contextPath =
|
|
2342
|
+
const contextPath = path19 || "root";
|
|
1831
2343
|
if (refPath.startsWith("#")) {
|
|
1832
2344
|
return;
|
|
1833
2345
|
}
|
|
@@ -1837,24 +2349,24 @@ var CodemieConfigLoader = class {
|
|
|
1837
2349
|
delete current[key];
|
|
1838
2350
|
}
|
|
1839
2351
|
Object.assign(current, filteredResolved);
|
|
1840
|
-
this.resolveReferencesRecursive(current, rootConfig,
|
|
2352
|
+
this.resolveReferencesRecursive(current, rootConfig, path19);
|
|
1841
2353
|
}
|
|
1842
2354
|
/**
|
|
1843
2355
|
* Resolve object properties recursively
|
|
1844
2356
|
* Handles both nested objects and "$ref:path" string references
|
|
1845
2357
|
*/
|
|
1846
|
-
resolveObjectProperties(current, rootConfig,
|
|
2358
|
+
resolveObjectProperties(current, rootConfig, path19) {
|
|
1847
2359
|
for (const [key, value] of Object.entries(current)) {
|
|
1848
2360
|
if (typeof value === "string" && value.startsWith("$ref:")) {
|
|
1849
2361
|
const refPath = value.slice(5);
|
|
1850
2362
|
if (refPath.startsWith("#")) {
|
|
1851
2363
|
continue;
|
|
1852
2364
|
}
|
|
1853
|
-
const contextPath =
|
|
2365
|
+
const contextPath = path19 ? `${path19}.${key}` : key;
|
|
1854
2366
|
const resolved = this.resolveReference(rootConfig, refPath, contextPath);
|
|
1855
2367
|
current[key] = resolved;
|
|
1856
2368
|
} else {
|
|
1857
|
-
this.resolveReferencesRecursive(value, rootConfig,
|
|
2369
|
+
this.resolveReferencesRecursive(value, rootConfig, path19 ? `${path19}.${key}` : key);
|
|
1858
2370
|
}
|
|
1859
2371
|
}
|
|
1860
2372
|
}
|
|
@@ -1978,8 +2490,10 @@ var CodemieConfigLoader = class {
|
|
|
1978
2490
|
* - ${VAR_NAME:default} - optional with default value (simplified)
|
|
1979
2491
|
* - ${VAR_NAME:-} or ${VAR_NAME:} - optional with empty string default
|
|
1980
2492
|
*/
|
|
1981
|
-
substituteEnvVars(obj) {
|
|
2493
|
+
substituteEnvVars(obj, configPath = "") {
|
|
2494
|
+
const isArray = Array.isArray(obj);
|
|
1982
2495
|
for (const key in obj) {
|
|
2496
|
+
const childPath = isArray ? `${configPath}[${key}]` : configPath ? `${configPath}.${key}` : key;
|
|
1983
2497
|
if (typeof obj[key] === "string") {
|
|
1984
2498
|
obj[key] = obj[key].replaceAll(
|
|
1985
2499
|
/\$\{([^:}]+)(?::-?([^}]*))?\}/g,
|
|
@@ -1989,13 +2503,13 @@ var CodemieConfigLoader = class {
|
|
|
1989
2503
|
if (defaultValue !== void 0) {
|
|
1990
2504
|
return defaultValue;
|
|
1991
2505
|
}
|
|
1992
|
-
throw new Error(`Environment variable ${varName} is not set`);
|
|
2506
|
+
throw new Error(`Environment variable ${varName} is not set (referenced in ${childPath})`);
|
|
1993
2507
|
}
|
|
1994
2508
|
return value;
|
|
1995
2509
|
}
|
|
1996
2510
|
);
|
|
1997
|
-
} else if (this.isPlainObject(obj[key])) {
|
|
1998
|
-
this.substituteEnvVars(obj[key]);
|
|
2511
|
+
} else if (this.isPlainObject(obj[key]) || Array.isArray(obj[key])) {
|
|
2512
|
+
this.substituteEnvVars(obj[key], childPath);
|
|
1999
2513
|
}
|
|
2000
2514
|
}
|
|
2001
2515
|
}
|
|
@@ -2023,8 +2537,8 @@ async function withRetry(fn, operation, maxAttempts = RATE_LIMITING.RETRY_ATTEMP
|
|
|
2023
2537
|
}
|
|
2024
2538
|
const delayMs = RATE_LIMITING.RETRY_DELAY_MS * 2 ** (attempt - 1);
|
|
2025
2539
|
logger.warn(` \u26A0\uFE0F Retry ${attempt}/${maxAttempts} for ${operation} after ${delayMs}ms...`);
|
|
2026
|
-
await new Promise((
|
|
2027
|
-
setTimeout(
|
|
2540
|
+
await new Promise((resolve7) => {
|
|
2541
|
+
setTimeout(resolve7, delayMs);
|
|
2028
2542
|
});
|
|
2029
2543
|
}
|
|
2030
2544
|
}
|
|
@@ -2105,9 +2619,9 @@ async function saveAssistantToBackup(assistant, client, backupData, backupDir) {
|
|
|
2105
2619
|
backupData.resources.assistants.push(full);
|
|
2106
2620
|
if (full.system_prompt) {
|
|
2107
2621
|
const fileName = `${full.slug || sanitizeFileName(full.name)}.prompt.md`;
|
|
2108
|
-
const filePath =
|
|
2622
|
+
const filePath = path13.join(backupDir, "system_prompts", fileName);
|
|
2109
2623
|
ensureDirectoryExists(filePath);
|
|
2110
|
-
|
|
2624
|
+
fs13.writeFileSync(filePath, full.system_prompt, "utf8");
|
|
2111
2625
|
}
|
|
2112
2626
|
}
|
|
2113
2627
|
async function backupAssistants(client, backupData, backupDir, transaction) {
|
|
@@ -2233,9 +2747,9 @@ async function backupWorkflows(client, backupData, backupDir, transaction) {
|
|
|
2233
2747
|
backupData.resources.workflows.push(full);
|
|
2234
2748
|
if (full.yaml_config) {
|
|
2235
2749
|
const fileName = `${sanitizeFileName(full.name)}.yaml`;
|
|
2236
|
-
const filePath =
|
|
2750
|
+
const filePath = path13.join(backupDir, "workflows", fileName);
|
|
2237
2751
|
ensureDirectoryExists(filePath);
|
|
2238
|
-
|
|
2752
|
+
fs13.writeFileSync(filePath, full.yaml_config, "utf8");
|
|
2239
2753
|
}
|
|
2240
2754
|
transaction.markCompleted("workflows", workflow.id);
|
|
2241
2755
|
} catch (error) {
|
|
@@ -2335,15 +2849,33 @@ async function backupSkills(client, backupData, backupDir, transaction, projectN
|
|
|
2335
2849
|
logger.info(` \u21B7 Skipping unreferenced external skill ${skill.name} (owner: ${full.project})`);
|
|
2336
2850
|
return;
|
|
2337
2851
|
}
|
|
2338
|
-
backupData.resources.skills.push(full);
|
|
2339
2852
|
if (fullIsProjectOwned) {
|
|
2340
|
-
const
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2853
|
+
const companionFiles = await client.skills.listCompanionFiles(skill.id);
|
|
2854
|
+
full.companion_files = companionFiles;
|
|
2855
|
+
if (companionFiles.length > 0) {
|
|
2856
|
+
const skillDir = path13.join(backupDir, skillDirRelativePath(skill.name));
|
|
2857
|
+
const skillMdPath = path13.join(backupDir, skillMarkdownRelativePath(skill.name));
|
|
2858
|
+
ensureDirectoryExists(skillMdPath);
|
|
2859
|
+
fs13.writeFileSync(skillMdPath, full.content || "", "utf8");
|
|
2860
|
+
for (const companionMeta of companionFiles) {
|
|
2861
|
+
const companionPath = resolvePathWithinDirectory(skillDir, companionMeta.path);
|
|
2862
|
+
const companionFile = await client.skills.getCompanionFile(skill.id, companionMeta.path);
|
|
2863
|
+
ensureDirectoryExists(companionPath);
|
|
2864
|
+
if (companionFile.encoding === "base64") {
|
|
2865
|
+
fs13.writeFileSync(companionPath, Buffer.from(companionFile.content, "base64"));
|
|
2866
|
+
} else {
|
|
2867
|
+
fs13.writeFileSync(companionPath, companionFile.content, "utf8");
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
} else {
|
|
2871
|
+
const filePath = path13.join(backupDir, skillFlatFileRelativePath(skill.name));
|
|
2872
|
+
ensureDirectoryExists(filePath);
|
|
2873
|
+
fs13.writeFileSync(filePath, full.content || "", "utf8");
|
|
2874
|
+
}
|
|
2344
2875
|
} else {
|
|
2345
2876
|
logger.info(` \u21B7 Skipping content file for imported skill ${skill.name} (owner: ${full.project})`);
|
|
2346
2877
|
}
|
|
2878
|
+
backupData.resources.skills.push(full);
|
|
2347
2879
|
}, `Backup skill ${skill.name}`)
|
|
2348
2880
|
);
|
|
2349
2881
|
transaction.markCompleted("skills", skill.id);
|
|
@@ -2362,17 +2894,17 @@ async function backupSkills(client, backupData, backupDir, transaction, projectN
|
|
|
2362
2894
|
}
|
|
2363
2895
|
function getUniqueBackupDir(baseDir, timestamp) {
|
|
2364
2896
|
let counter = 0;
|
|
2365
|
-
let finalBackupDir =
|
|
2366
|
-
while (
|
|
2897
|
+
let finalBackupDir = path13.join(baseDir, timestamp);
|
|
2898
|
+
while (fs13.existsSync(finalBackupDir)) {
|
|
2367
2899
|
counter++;
|
|
2368
|
-
finalBackupDir =
|
|
2900
|
+
finalBackupDir = path13.join(baseDir, `${timestamp}-${counter}`);
|
|
2369
2901
|
}
|
|
2370
2902
|
const dirSuffix = counter > 0 ? `${timestamp}-${counter}` : timestamp;
|
|
2371
|
-
const tempBackupDir =
|
|
2903
|
+
const tempBackupDir = path13.join(baseDir, `${BACKUP.TEMP_DIR_PREFIX}${dirSuffix}`);
|
|
2372
2904
|
return { finalDir: finalBackupDir, tempDir: tempBackupDir };
|
|
2373
2905
|
}
|
|
2374
2906
|
function performCleanup(tempBackupDir, transaction) {
|
|
2375
|
-
if (
|
|
2907
|
+
if (fs13.existsSync(tempBackupDir)) {
|
|
2376
2908
|
try {
|
|
2377
2909
|
logger.info(`\u{1F9F9} Rolling back: cleaning up ${tempBackupDir}...`);
|
|
2378
2910
|
cleanupDirectory(tempBackupDir);
|
|
@@ -2401,7 +2933,7 @@ async function backupResources(options) {
|
|
|
2401
2933
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "").replaceAll(":", "-");
|
|
2402
2934
|
const { appConfig } = options;
|
|
2403
2935
|
const { rootDir, backupsDirectory } = appConfig;
|
|
2404
|
-
const backupBaseDir =
|
|
2936
|
+
const backupBaseDir = path13.join(rootDir, backupsDirectory);
|
|
2405
2937
|
const { finalDir: finalBackupDir, tempDir: tempBackupDir } = getUniqueBackupDir(backupBaseDir, timestamp);
|
|
2406
2938
|
let transaction = null;
|
|
2407
2939
|
try {
|
|
@@ -2411,8 +2943,8 @@ async function backupResources(options) {
|
|
|
2411
2943
|
logger.info("\u{1F50C} Connecting to Codemie API...");
|
|
2412
2944
|
const client = await createClient(config);
|
|
2413
2945
|
logger.info("\u2713 Connected to Codemie API\n");
|
|
2414
|
-
if (!
|
|
2415
|
-
|
|
2946
|
+
if (!fs13.existsSync(tempBackupDir)) {
|
|
2947
|
+
fs13.mkdirSync(tempBackupDir, { recursive: true });
|
|
2416
2948
|
}
|
|
2417
2949
|
logger.info(`\u{1F4C1} Temporary backup directory: ${tempBackupDir}
|
|
2418
2950
|
`);
|
|
@@ -2986,6 +3518,96 @@ function resolveSkillIds(skillNames, stateManager, config) {
|
|
|
2986
3518
|
return skillNames.map((name) => resolveSkillId(name, stateManager, config));
|
|
2987
3519
|
}
|
|
2988
3520
|
|
|
3521
|
+
// src/deploy.ts
|
|
3522
|
+
init_skillCompanionFiles();
|
|
3523
|
+
|
|
3524
|
+
// src/lib/skillReplacement.ts
|
|
3525
|
+
function getSkillNamesInGroup(skills, group) {
|
|
3526
|
+
return new Set((skills || []).filter((skill) => skill.group === group).map((skill) => skill.name));
|
|
3527
|
+
}
|
|
3528
|
+
function getSkillsInGroup(skills, group) {
|
|
3529
|
+
return (skills || []).filter((skill) => skill.group === group);
|
|
3530
|
+
}
|
|
3531
|
+
function collectSkillNamesForReplacement(skills, stateManager, group) {
|
|
3532
|
+
const groupSkillNames = getSkillNamesInGroup(skills, group);
|
|
3533
|
+
const namesToDelete = /* @__PURE__ */ new Set();
|
|
3534
|
+
for (const name of stateManager.getAllManagedResources().skills) {
|
|
3535
|
+
const state = stateManager.getSkillState(name);
|
|
3536
|
+
if (state?.group === group || groupSkillNames.has(name)) {
|
|
3537
|
+
namesToDelete.add(name);
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
return [...namesToDelete].sort((left, right) => left.localeCompare(right));
|
|
3541
|
+
}
|
|
3542
|
+
function filterAssistantsReferencingSkillGroup(assistants, skills, group) {
|
|
3543
|
+
const skillNames = getSkillNamesInGroup(skills, group);
|
|
3544
|
+
if (skillNames.size === 0) {
|
|
3545
|
+
return [];
|
|
3546
|
+
}
|
|
3547
|
+
const groupNames = [...skillNames];
|
|
3548
|
+
return (assistants || []).filter(
|
|
3549
|
+
(assistant) => assistant.skills?.some((skillName) => groupNames.some((groupName) => namesEqual(groupName, skillName)))
|
|
3550
|
+
);
|
|
3551
|
+
}
|
|
3552
|
+
function expandAssistantsWithDependencies(selected, allAssistants) {
|
|
3553
|
+
const byName = new Map((allAssistants || []).map((assistant) => [assistant.name, assistant]));
|
|
3554
|
+
const result = [];
|
|
3555
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3556
|
+
const visit = (assistant) => {
|
|
3557
|
+
if (seen.has(assistant.name)) {
|
|
3558
|
+
return;
|
|
3559
|
+
}
|
|
3560
|
+
seen.add(assistant.name);
|
|
3561
|
+
result.push(assistant);
|
|
3562
|
+
for (const subName of assistant.sub_assistants || []) {
|
|
3563
|
+
const subAssistant = byName.get(subName);
|
|
3564
|
+
if (subAssistant) {
|
|
3565
|
+
visit(subAssistant);
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
};
|
|
3569
|
+
for (const assistant of selected) {
|
|
3570
|
+
visit(assistant);
|
|
3571
|
+
}
|
|
3572
|
+
return result;
|
|
3573
|
+
}
|
|
3574
|
+
function collectAssistantIdsForDetach(stateManager, config) {
|
|
3575
|
+
const ids = [];
|
|
3576
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3577
|
+
const add = (id) => {
|
|
3578
|
+
if (id && !seen.has(id)) {
|
|
3579
|
+
seen.add(id);
|
|
3580
|
+
ids.push(id);
|
|
3581
|
+
}
|
|
3582
|
+
};
|
|
3583
|
+
for (const name of stateManager.getAllManagedResources().assistants) {
|
|
3584
|
+
add(stateManager.getIdByName("assistant", name));
|
|
3585
|
+
}
|
|
3586
|
+
for (const imported of config.imported?.assistants || []) {
|
|
3587
|
+
add(imported.id);
|
|
3588
|
+
}
|
|
3589
|
+
return ids;
|
|
3590
|
+
}
|
|
3591
|
+
function selectSkillGroupForReplacement(config, stateManager, group) {
|
|
3592
|
+
assertSkillGroupNotImported(config.imported?.skills, group);
|
|
3593
|
+
const namesToDelete = collectSkillNamesForReplacement(config.resources.skills, stateManager, group);
|
|
3594
|
+
const groupSkills = getSkillsInGroup(config.resources.skills, group);
|
|
3595
|
+
if (namesToDelete.length === 0 && groupSkills.length === 0) {
|
|
3596
|
+
throw new Error(
|
|
3597
|
+
`Skill group "${group}" matched no skills in state or in resources.skills. Group membership comes from the "group" field of a skill entry, never from its name.`
|
|
3598
|
+
);
|
|
3599
|
+
}
|
|
3600
|
+
return { namesToDelete, groupSkills };
|
|
3601
|
+
}
|
|
3602
|
+
function assertSkillGroupNotImported(importedSkills, group) {
|
|
3603
|
+
const conflict = (importedSkills || []).find((skill) => namesEqual(skill.name, group));
|
|
3604
|
+
if (conflict) {
|
|
3605
|
+
throw new Error(
|
|
3606
|
+
`Skill group "${group}" matches an entry in imported.skills ("${conflict.name}"). Imported skills are platform-managed and are never deleted or recreated by IaC. Rename the group or remove the imported.skills entry.`
|
|
3607
|
+
);
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
|
|
2989
3611
|
// src/lib/stateManager.ts
|
|
2990
3612
|
init_checksumUtils();
|
|
2991
3613
|
init_codemieConfigChecksums();
|
|
@@ -2993,16 +3615,16 @@ var StateManager = class {
|
|
|
2993
3615
|
statePath;
|
|
2994
3616
|
constructor(appConfig) {
|
|
2995
3617
|
const { rootDir, codemieState } = appConfig;
|
|
2996
|
-
this.statePath =
|
|
3618
|
+
this.statePath = path13.join(rootDir, codemieState);
|
|
2997
3619
|
}
|
|
2998
3620
|
/**
|
|
2999
3621
|
* Load state file
|
|
3000
3622
|
*/
|
|
3001
3623
|
loadState() {
|
|
3002
|
-
if (!
|
|
3624
|
+
if (!fs13.existsSync(this.statePath)) {
|
|
3003
3625
|
return this.createEmptyState();
|
|
3004
3626
|
}
|
|
3005
|
-
const content =
|
|
3627
|
+
const content = fs13.readFileSync(this.statePath, "utf8");
|
|
3006
3628
|
const state = JSON.parse(content);
|
|
3007
3629
|
if (!state.resources) {
|
|
3008
3630
|
state.resources = {
|
|
@@ -3030,12 +3652,12 @@ var StateManager = class {
|
|
|
3030
3652
|
* Save state file
|
|
3031
3653
|
*/
|
|
3032
3654
|
saveState(state) {
|
|
3033
|
-
const dir =
|
|
3034
|
-
if (!
|
|
3035
|
-
|
|
3655
|
+
const dir = path13.dirname(this.statePath);
|
|
3656
|
+
if (!fs13.existsSync(dir)) {
|
|
3657
|
+
fs13.mkdirSync(dir, { recursive: true });
|
|
3036
3658
|
}
|
|
3037
3659
|
state.lastSync = (/* @__PURE__ */ new Date()).toISOString();
|
|
3038
|
-
|
|
3660
|
+
fs13.writeFileSync(this.statePath, JSON.stringify(state, null, 2));
|
|
3039
3661
|
}
|
|
3040
3662
|
/**
|
|
3041
3663
|
* Create empty state structure
|
|
@@ -3206,7 +3828,7 @@ var StateManager = class {
|
|
|
3206
3828
|
/**
|
|
3207
3829
|
* Update skill state (keyed by NAME)
|
|
3208
3830
|
*/
|
|
3209
|
-
updateSkillState(name, id, content, skillResource) {
|
|
3831
|
+
updateSkillState(name, id, content, skillResource, companionFiles) {
|
|
3210
3832
|
const state = this.loadState();
|
|
3211
3833
|
if (!state.resources.skills) {
|
|
3212
3834
|
state.resources.skills = {};
|
|
@@ -3215,7 +3837,13 @@ var StateManager = class {
|
|
|
3215
3837
|
id,
|
|
3216
3838
|
lastDeployed: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3217
3839
|
contentChecksum: calculateChecksum(content),
|
|
3218
|
-
configChecksum: calculateSkillConfigChecksum(skillResource)
|
|
3840
|
+
configChecksum: calculateSkillConfigChecksum(skillResource),
|
|
3841
|
+
// Persisted for group selection (`deploy --replace-skill-group`) only. The group label stays out
|
|
3842
|
+
// of configChecksum on purpose, so relabelling a skill never marks it as changed.
|
|
3843
|
+
...skillResource.group !== void 0 ? { group: skillResource.group } : {},
|
|
3844
|
+
// Only written when companionFiles is passed, so an older/companion-less entry has
|
|
3845
|
+
// neither key at all — the absence itself is what Tasks 10/11 read as "no companion files".
|
|
3846
|
+
...companionFiles ? calculateCompanionFilesChecksum(companionFiles) : {}
|
|
3219
3847
|
};
|
|
3220
3848
|
this.saveState(state);
|
|
3221
3849
|
}
|
|
@@ -3504,7 +4132,35 @@ async function deployAssistants(config, client, loader, stateManager) {
|
|
|
3504
4132
|
}
|
|
3505
4133
|
return stats;
|
|
3506
4134
|
}
|
|
3507
|
-
|
|
4135
|
+
function companionFilesForCreate(companionFiles) {
|
|
4136
|
+
return companionFiles.length > 0 ? { companion_files: companionFiles } : {};
|
|
4137
|
+
}
|
|
4138
|
+
function stateKnowsCompanionFiles(existingState) {
|
|
4139
|
+
return existingState?.companionFileHashes !== void 0;
|
|
4140
|
+
}
|
|
4141
|
+
async function companionFilesForUpdate(client, skillId, skillName, companionFiles, existingState) {
|
|
4142
|
+
if (companionFiles.length > 0) {
|
|
4143
|
+
return { companion_files: companionFiles };
|
|
4144
|
+
}
|
|
4145
|
+
if (stateKnowsCompanionFiles(existingState)) {
|
|
4146
|
+
return stateHasCompanionFiles(existingState) ? { companion_files: [] } : {};
|
|
4147
|
+
}
|
|
4148
|
+
let platformCompanionFiles;
|
|
4149
|
+
try {
|
|
4150
|
+
platformCompanionFiles = await withTimeout(
|
|
4151
|
+
client.skills.listCompanionFiles(skillId),
|
|
4152
|
+
TIMEOUTS_MS.SKILL_FETCH,
|
|
4153
|
+
`Timeout listing companion files for skill "${skillId}"`
|
|
4154
|
+
);
|
|
4155
|
+
} catch (error) {
|
|
4156
|
+
logger.warn(
|
|
4157
|
+
` \u26A0\uFE0F Could not list companion files for skill "${skillName}": ${error instanceof Error ? error.message : String(error)}. Leaving any companion files on the platform untouched.`
|
|
4158
|
+
);
|
|
4159
|
+
return {};
|
|
4160
|
+
}
|
|
4161
|
+
return platformCompanionFiles.length > 0 ? { companion_files: [] } : {};
|
|
4162
|
+
}
|
|
4163
|
+
async function deploySkills(config, client, loader, stateManager, rootDir = process.cwd()) {
|
|
3508
4164
|
const stats = { created: 0, updated: 0, unchanged: 0, failed: 0 };
|
|
3509
4165
|
logger.info("\u{1F3AF} Processing skills...\n");
|
|
3510
4166
|
if (!config.resources.skills) {
|
|
@@ -3514,15 +4170,18 @@ async function deploySkills(config, client, loader, stateManager) {
|
|
|
3514
4170
|
for (const skill of config.resources.skills) {
|
|
3515
4171
|
try {
|
|
3516
4172
|
logger.info(`Processing: ${skill.name}`);
|
|
3517
|
-
const content = loader.
|
|
4173
|
+
const content = loader.resolveSkillContent(skill);
|
|
3518
4174
|
const contentChecksum = calculateChecksum(content);
|
|
3519
4175
|
const configChecksum = calculateSkillConfigChecksum(skill);
|
|
3520
4176
|
const visibility = skill.visibility ?? "project";
|
|
4177
|
+
const companionFiles = hasCompanionFileLayout(skill) ? collectCompanionFiles(path13.dirname(path13.join(rootDir, skill.file))) : [];
|
|
4178
|
+
const { companionFilesChecksum } = calculateCompanionFilesChecksum(companionFiles);
|
|
3521
4179
|
const existingState = stateManager.getSkillState(skill.name);
|
|
3522
4180
|
if (existingState) {
|
|
3523
4181
|
const existsOnPlatform = await checkSkillExists(client, skill.name, stateManager);
|
|
3524
4182
|
if (existsOnPlatform) {
|
|
3525
|
-
const
|
|
4183
|
+
const companionFilesChanged = companionFiles.length > 0 || stateHasCompanionFiles(existingState) ? existingState.companionFilesChecksum !== companionFilesChecksum : false;
|
|
4184
|
+
const hasChanged = existingState.contentChecksum !== contentChecksum || existingState.configChecksum !== configChecksum || companionFilesChanged;
|
|
3526
4185
|
if (hasChanged) {
|
|
3527
4186
|
logger.info(` Updating skill (ID: ${existingState.id})...`);
|
|
3528
4187
|
if (process.env.DEBUG_API) {
|
|
@@ -3540,10 +4199,12 @@ async function deploySkills(config, client, loader, stateManager) {
|
|
|
3540
4199
|
name: skill.name,
|
|
3541
4200
|
description: skill.description,
|
|
3542
4201
|
content,
|
|
3543
|
-
|
|
4202
|
+
visibility,
|
|
4203
|
+
categories: skill.categories,
|
|
4204
|
+
...await companionFilesForUpdate(client, existingState.id, skill.name, companionFiles, existingState)
|
|
3544
4205
|
});
|
|
3545
4206
|
logger.info(`\u2713 Updated skill: ${skill.name} (${existingState.id})`);
|
|
3546
|
-
stateManager.updateSkillState(skill.name, existingState.id, content, skill);
|
|
4207
|
+
stateManager.updateSkillState(skill.name, existingState.id, content, skill, companionFiles);
|
|
3547
4208
|
stats.updated++;
|
|
3548
4209
|
} else {
|
|
3549
4210
|
logger.info(` \u2713 No changes detected (ID: ${existingState.id})`);
|
|
@@ -3558,11 +4219,12 @@ async function deploySkills(config, client, loader, stateManager) {
|
|
|
3558
4219
|
content,
|
|
3559
4220
|
project: config.project.name,
|
|
3560
4221
|
visibility,
|
|
3561
|
-
categories: skill.categories
|
|
4222
|
+
categories: skill.categories,
|
|
4223
|
+
...companionFilesForCreate(companionFiles)
|
|
3562
4224
|
});
|
|
3563
4225
|
logger.info(`\u2713 Created skill: ${skill.name} (${result.id})`);
|
|
3564
4226
|
skillIndex.record(skill.name, result.id);
|
|
3565
|
-
stateManager.updateSkillState(skill.name, result.id, content, skill);
|
|
4227
|
+
stateManager.updateSkillState(skill.name, result.id, content, skill, companionFiles);
|
|
3566
4228
|
stats.created++;
|
|
3567
4229
|
}
|
|
3568
4230
|
} else {
|
|
@@ -3586,7 +4248,8 @@ async function deploySkills(config, client, loader, stateManager) {
|
|
|
3586
4248
|
content,
|
|
3587
4249
|
project: config.project.name,
|
|
3588
4250
|
visibility,
|
|
3589
|
-
categories: skill.categories
|
|
4251
|
+
categories: skill.categories,
|
|
4252
|
+
...companionFilesForCreate(companionFiles)
|
|
3590
4253
|
});
|
|
3591
4254
|
skillId = result.id;
|
|
3592
4255
|
logger.info(`\u2713 Created skill: ${skill.name} (${skillId})`);
|
|
@@ -3607,13 +4270,15 @@ async function deploySkills(config, client, loader, stateManager) {
|
|
|
3607
4270
|
name: skill.name,
|
|
3608
4271
|
description: skill.description,
|
|
3609
4272
|
content,
|
|
3610
|
-
|
|
4273
|
+
visibility,
|
|
4274
|
+
categories: skill.categories,
|
|
4275
|
+
...await companionFilesForUpdate(client, existingId, skill.name, companionFiles, void 0)
|
|
3611
4276
|
});
|
|
3612
4277
|
skillId = existingId;
|
|
3613
4278
|
logger.info(`\u2713 Recovered and updated skill: ${skill.name} (${skillId})`);
|
|
3614
4279
|
stats.updated++;
|
|
3615
4280
|
}
|
|
3616
|
-
stateManager.updateSkillState(skill.name, skillId, content, skill);
|
|
4281
|
+
stateManager.updateSkillState(skill.name, skillId, content, skill, companionFiles);
|
|
3617
4282
|
}
|
|
3618
4283
|
logger.info("");
|
|
3619
4284
|
} catch (error) {
|
|
@@ -3734,12 +4399,12 @@ async function deployWorkflows(config, client, stateManager, rootDir = process.c
|
|
|
3734
4399
|
for (const workflow of config.resources.workflows) {
|
|
3735
4400
|
try {
|
|
3736
4401
|
logger.info(`Processing: ${workflow.name}`);
|
|
3737
|
-
const yamlPath =
|
|
3738
|
-
if (!
|
|
4402
|
+
const yamlPath = path13.join(rootDir, workflow.definition);
|
|
4403
|
+
if (!fs13.existsSync(yamlPath)) {
|
|
3739
4404
|
throw new Error(`Workflow definition file not found: ${workflow.definition}`);
|
|
3740
4405
|
}
|
|
3741
|
-
const yamlConfigContent =
|
|
3742
|
-
const workflowYaml =
|
|
4406
|
+
const yamlConfigContent = fs13.readFileSync(yamlPath, "utf8");
|
|
4407
|
+
const workflowYaml = yaml7.parse(yamlConfigContent);
|
|
3743
4408
|
const referencesToResolve = [];
|
|
3744
4409
|
for (const assistant of workflowYaml.assistants ?? []) {
|
|
3745
4410
|
const isInline = !assistant.assistant_name && assistant.model && assistant.system_prompt;
|
|
@@ -3780,7 +4445,7 @@ async function deployWorkflows(config, client, stateManager, rootDir = process.c
|
|
|
3780
4445
|
});
|
|
3781
4446
|
}
|
|
3782
4447
|
}
|
|
3783
|
-
const yamlConfig =
|
|
4448
|
+
const yamlConfig = yaml7.stringify(workflowYaml);
|
|
3784
4449
|
const workflowYamlChecksum = calculateChecksum(yamlConfigContent);
|
|
3785
4450
|
const configChecksum = calculateWorkflowConfigChecksum(workflow);
|
|
3786
4451
|
const existingState = stateManager.getWorkflowState(workflow.name);
|
|
@@ -3857,19 +4522,168 @@ async function deployWorkflows(config, client, stateManager, rootDir = process.c
|
|
|
3857
4522
|
}
|
|
3858
4523
|
return stats;
|
|
3859
4524
|
}
|
|
4525
|
+
function isAlreadyGoneError(error) {
|
|
4526
|
+
const message = (error instanceof Error ? error.message : String(error)).toLowerCase();
|
|
4527
|
+
return message.includes("404") || message.includes("not found") || message.includes("not attached");
|
|
4528
|
+
}
|
|
4529
|
+
async function detachSkillsBeforeDelete(client, assistantIds, skills, group) {
|
|
4530
|
+
if (skills.length === 0 || assistantIds.length === 0) {
|
|
4531
|
+
return;
|
|
4532
|
+
}
|
|
4533
|
+
const targetIds = new Set(skills.map((skill) => skill.id));
|
|
4534
|
+
logger.info(`\u{1F517} Detaching ${skills.length} skill(s) from ${assistantIds.length} assistant(s)...`);
|
|
4535
|
+
for (const assistantId of assistantIds) {
|
|
4536
|
+
let attachedTargetIds;
|
|
4537
|
+
try {
|
|
4538
|
+
const currentSkills = await client.skills.getAssistantSkills(assistantId);
|
|
4539
|
+
attachedTargetIds = currentSkills.map((skill) => skill.id).filter((id) => targetIds.has(id));
|
|
4540
|
+
} catch (fetchError) {
|
|
4541
|
+
logger.warn(` \u26A0\uFE0F Could not list skills of assistant ${assistantId}, attempting every detach instead`);
|
|
4542
|
+
logger.debug(` ${fetchError instanceof Error ? fetchError.message : String(fetchError)}`);
|
|
4543
|
+
attachedTargetIds = [...targetIds];
|
|
4544
|
+
}
|
|
4545
|
+
for (const skillId of attachedTargetIds) {
|
|
4546
|
+
try {
|
|
4547
|
+
await client.skills.detachFromAssistant(assistantId, skillId);
|
|
4548
|
+
logger.info(` \u2713 Detached skill ${skillId} from assistant ${assistantId}`);
|
|
4549
|
+
} catch (detachError) {
|
|
4550
|
+
if (isAlreadyGoneError(detachError)) {
|
|
4551
|
+
logger.info(` \u2713 Skill ${skillId} already detached from assistant ${assistantId}`);
|
|
4552
|
+
continue;
|
|
4553
|
+
}
|
|
4554
|
+
const message = detachError instanceof Error ? detachError.message : String(detachError);
|
|
4555
|
+
throw new Error(
|
|
4556
|
+
`Failed to detach skill ${skillId} from assistant ${assistantId} while replacing skill group "${group}": ${message}. Nothing was deleted.`
|
|
4557
|
+
);
|
|
4558
|
+
}
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
logger.info("");
|
|
4562
|
+
}
|
|
4563
|
+
async function deleteSkillsForReplacement(client, stateManager, skills, group) {
|
|
4564
|
+
let deleted = 0;
|
|
4565
|
+
for (const { name, id } of skills) {
|
|
4566
|
+
try {
|
|
4567
|
+
await client.skills.delete(id);
|
|
4568
|
+
logger.info(` \u{1F5D1}\uFE0F Deleted skill: ${name} (${id})`);
|
|
4569
|
+
deleted++;
|
|
4570
|
+
} catch (deleteError) {
|
|
4571
|
+
if (isAlreadyGoneError(deleteError)) {
|
|
4572
|
+
logger.warn(` \u26A0\uFE0F Skill ${name} (${id}) not found on platform (already deleted) - removing from state`);
|
|
4573
|
+
} else {
|
|
4574
|
+
const message = deleteError instanceof Error ? deleteError.message : String(deleteError);
|
|
4575
|
+
throw new Error(
|
|
4576
|
+
`Failed to delete skill "${name}" (${id}) while replacing skill group "${group}": ${message}. No skills were recreated; rerun the command once the platform error is resolved.`
|
|
4577
|
+
);
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4580
|
+
stateManager.deleteSkillState(name);
|
|
4581
|
+
}
|
|
4582
|
+
logger.info("");
|
|
4583
|
+
return deleted;
|
|
4584
|
+
}
|
|
4585
|
+
async function replaceSkillGroupResources(config, client, loader, stateManager, group, rootDir = process.cwd()) {
|
|
4586
|
+
const { namesToDelete, groupSkills } = selectSkillGroupForReplacement(config, stateManager, group);
|
|
4587
|
+
logger.info(`\u267B\uFE0F Replacing skill group "${group}"...
|
|
4588
|
+
`);
|
|
4589
|
+
logger.info(` ${namesToDelete.length} skill(s) to delete, ${groupSkills.length} skill(s) to recreate
|
|
4590
|
+
`);
|
|
4591
|
+
const skillsToDelete = namesToDelete.map((name) => ({ name, id: stateManager.getIdByName("skill", name) })).filter((entry) => Boolean(entry.id));
|
|
4592
|
+
await detachSkillsBeforeDelete(client, collectAssistantIdsForDetach(stateManager, config), skillsToDelete, group);
|
|
4593
|
+
const deleted = await deleteSkillsForReplacement(client, stateManager, skillsToDelete, group);
|
|
4594
|
+
const skillStats = await deploySkills(
|
|
4595
|
+
{
|
|
4596
|
+
...config,
|
|
4597
|
+
resources: { ...config.resources, skills: groupSkills, assistants: [], workflows: [] }
|
|
4598
|
+
},
|
|
4599
|
+
client,
|
|
4600
|
+
loader,
|
|
4601
|
+
stateManager,
|
|
4602
|
+
rootDir
|
|
4603
|
+
);
|
|
4604
|
+
const referencingAssistants = expandAssistantsWithDependencies(
|
|
4605
|
+
filterAssistantsReferencingSkillGroup(config.resources.assistants, config.resources.skills, group),
|
|
4606
|
+
config.resources.assistants
|
|
4607
|
+
);
|
|
4608
|
+
logger.info(` ${referencingAssistants.length} assistant(s) reference the replaced skill group
|
|
4609
|
+
`);
|
|
4610
|
+
const assistantStats = await deployAssistants(
|
|
4611
|
+
{
|
|
4612
|
+
...config,
|
|
4613
|
+
resources: { ...config.resources, assistants: referencingAssistants, workflows: [] }
|
|
4614
|
+
},
|
|
4615
|
+
client,
|
|
4616
|
+
loader,
|
|
4617
|
+
stateManager
|
|
4618
|
+
);
|
|
4619
|
+
return {
|
|
4620
|
+
deleted,
|
|
4621
|
+
stats: {
|
|
4622
|
+
created: skillStats.created + assistantStats.created,
|
|
4623
|
+
updated: skillStats.updated + assistantStats.updated,
|
|
4624
|
+
unchanged: skillStats.unchanged + assistantStats.unchanged,
|
|
4625
|
+
failed: skillStats.failed + assistantStats.failed
|
|
4626
|
+
}
|
|
4627
|
+
};
|
|
4628
|
+
}
|
|
4629
|
+
function logDeploymentSummary(stats, deleted) {
|
|
4630
|
+
logger.info("=".repeat(50));
|
|
4631
|
+
logger.info("\u{1F4CA} Deployment Summary:\n");
|
|
4632
|
+
logger.info(` \u2705 Created: ${stats.created}`);
|
|
4633
|
+
logger.info(` \u{1F504} Updated: ${stats.updated}`);
|
|
4634
|
+
logger.info(` \u{1F4CB} Unchanged: ${stats.unchanged}`);
|
|
4635
|
+
if (deleted > 0) {
|
|
4636
|
+
logger.info(` \u{1F5D1}\uFE0F Deleted: ${deleted}`);
|
|
4637
|
+
}
|
|
4638
|
+
if (stats.failed > 0) {
|
|
4639
|
+
logger.info(` \u274C Failed: ${stats.failed}`);
|
|
4640
|
+
}
|
|
4641
|
+
logger.info("");
|
|
4642
|
+
}
|
|
3860
4643
|
async function deployResources(options) {
|
|
3861
4644
|
logger.info("\u{1F680} Deploying resources to Codemie...\n");
|
|
3862
4645
|
try {
|
|
3863
|
-
const { appConfig, prune = false, skipDatasources = false } = options;
|
|
4646
|
+
const { appConfig, prune = false, skipDatasources = false, replaceSkillGroup, yesReplaceSkills = false } = options;
|
|
4647
|
+
if (replaceSkillGroup && !yesReplaceSkills) {
|
|
4648
|
+
throw new Error(
|
|
4649
|
+
`Refusing to replace skill group "${replaceSkillGroup}" without --yes-replace-skills. Replacing a group deletes its skills and recreates them with new ids; nothing was touched.`
|
|
4650
|
+
);
|
|
4651
|
+
}
|
|
3864
4652
|
const loader = new CodemieConfigLoader(appConfig);
|
|
3865
4653
|
const stateManager = new StateManager(appConfig);
|
|
3866
4654
|
logger.info("\u{1F4C4} Loading configuration...");
|
|
3867
4655
|
const config = loader.loadConfig();
|
|
3868
4656
|
logger.info(`\u2713 Loaded config for project: ${config.project.name}
|
|
3869
4657
|
`);
|
|
4658
|
+
const skillDescriptionErrors = validateSkillDescriptions(config.resources.skills ?? []);
|
|
4659
|
+
if (skillDescriptionErrors.length > 0) {
|
|
4660
|
+
throw new Error(skillDescriptionErrors.join("\n"));
|
|
4661
|
+
}
|
|
3870
4662
|
logger.info("\u{1F50C} Connecting to Codemie API...");
|
|
3871
4663
|
const client = await createClient(config);
|
|
3872
4664
|
logger.info("\u2713 Connected to Codemie API\n");
|
|
4665
|
+
if (replaceSkillGroup) {
|
|
4666
|
+
if (prune) {
|
|
4667
|
+
logger.info("\u26A0\uFE0F --prune is ignored with --replace-skill-group\n");
|
|
4668
|
+
}
|
|
4669
|
+
if (skipDatasources) {
|
|
4670
|
+
logger.info("\u2139\uFE0F Datasources are skipped by --replace-skill-group anyway\n");
|
|
4671
|
+
}
|
|
4672
|
+
const replacement = await replaceSkillGroupResources(
|
|
4673
|
+
config,
|
|
4674
|
+
client,
|
|
4675
|
+
loader,
|
|
4676
|
+
stateManager,
|
|
4677
|
+
replaceSkillGroup,
|
|
4678
|
+
appConfig.rootDir
|
|
4679
|
+
);
|
|
4680
|
+
logDeploymentSummary(replacement.stats, replacement.deleted);
|
|
4681
|
+
if (replacement.stats.failed > 0) {
|
|
4682
|
+
throw new Error("Deployment completed with errors");
|
|
4683
|
+
}
|
|
4684
|
+
logger.info("\u2705 Deployment successful!");
|
|
4685
|
+
return;
|
|
4686
|
+
}
|
|
3873
4687
|
logger.info("\u{1F9F9} Checking for orphaned resources...");
|
|
3874
4688
|
const cleanupManager = new CleanupManager(client, stateManager);
|
|
3875
4689
|
const foundOrphaned = cleanupManager.findOrphanedResources(config);
|
|
@@ -3928,7 +4742,7 @@ async function deployResources(options) {
|
|
|
3928
4742
|
unchanged += datasourceStats.unchanged;
|
|
3929
4743
|
failed += datasourceStats.failed;
|
|
3930
4744
|
}
|
|
3931
|
-
const skillStats = await deploySkills(config, client, loader, stateManager);
|
|
4745
|
+
const skillStats = await deploySkills(config, client, loader, stateManager, appConfig.rootDir);
|
|
3932
4746
|
created += skillStats.created;
|
|
3933
4747
|
updated += skillStats.updated;
|
|
3934
4748
|
unchanged += skillStats.unchanged;
|
|
@@ -3958,18 +4772,7 @@ async function deployResources(options) {
|
|
|
3958
4772
|
`);
|
|
3959
4773
|
}
|
|
3960
4774
|
}
|
|
3961
|
-
|
|
3962
|
-
logger.info("\u{1F4CA} Deployment Summary:\n");
|
|
3963
|
-
logger.info(` \u2705 Created: ${created}`);
|
|
3964
|
-
logger.info(` \u{1F504} Updated: ${updated}`);
|
|
3965
|
-
logger.info(` \u{1F4CB} Unchanged: ${unchanged}`);
|
|
3966
|
-
if (deleted > 0) {
|
|
3967
|
-
logger.info(` \u{1F5D1}\uFE0F Deleted: ${deleted}`);
|
|
3968
|
-
}
|
|
3969
|
-
if (failed > 0) {
|
|
3970
|
-
logger.info(` \u274C Failed: ${failed}`);
|
|
3971
|
-
}
|
|
3972
|
-
logger.info("");
|
|
4775
|
+
logDeploymentSummary({ created, updated, unchanged, failed }, deleted);
|
|
3973
4776
|
if (failed > 0) {
|
|
3974
4777
|
throw new Error("Deployment completed with errors");
|
|
3975
4778
|
} else {
|
|
@@ -4002,8 +4805,8 @@ async function promptUser(question, defaultValue) {
|
|
|
4002
4805
|
});
|
|
4003
4806
|
const displayQuestion = defaultValue ? `${question} (${defaultValue}): ` : `${question}: `;
|
|
4004
4807
|
const answer = await pauseSpinnerWhile(
|
|
4005
|
-
() => new Promise((
|
|
4006
|
-
rl.question(displayQuestion,
|
|
4808
|
+
() => new Promise((resolve7) => {
|
|
4809
|
+
rl.question(displayQuestion, resolve7);
|
|
4007
4810
|
})
|
|
4008
4811
|
);
|
|
4009
4812
|
rl.close();
|
|
@@ -4129,6 +4932,7 @@ function pluralTypeOf(resourceType) {
|
|
|
4129
4932
|
}
|
|
4130
4933
|
|
|
4131
4934
|
// src/import.ts
|
|
4935
|
+
init_skillCompanionFiles();
|
|
4132
4936
|
init_skillUtils();
|
|
4133
4937
|
async function findAssistant(client, slug) {
|
|
4134
4938
|
if (UUID_RE.test(slug)) {
|
|
@@ -4189,6 +4993,38 @@ async function findSkill(client, name) {
|
|
|
4189
4993
|
const match = await findResourceByName2((params) => client.skills.list(params), name, "skill");
|
|
4190
4994
|
return withTimeout(client.skills.get(match.id), TIMEOUTS_MS.SKILL_FETCH, `Timeout fetching skill "${match.id}"`);
|
|
4191
4995
|
}
|
|
4996
|
+
async function fetchSkillCompanionFiles(client, skill) {
|
|
4997
|
+
const metadata = await withTimeout(
|
|
4998
|
+
client.skills.listCompanionFiles(skill.id),
|
|
4999
|
+
TIMEOUTS_MS.SKILL_FETCH,
|
|
5000
|
+
`Timeout listing companion files for skill "${skill.id}"`
|
|
5001
|
+
);
|
|
5002
|
+
skill.companion_files = metadata;
|
|
5003
|
+
const limit = createConcurrentLimiter();
|
|
5004
|
+
return Promise.all(
|
|
5005
|
+
metadata.map(
|
|
5006
|
+
(entry) => limit(
|
|
5007
|
+
() => withTimeout(
|
|
5008
|
+
client.skills.getCompanionFile(skill.id, entry.path),
|
|
5009
|
+
TIMEOUTS_MS.SKILL_FETCH,
|
|
5010
|
+
`Timeout fetching companion file "${entry.path}" of skill "${skill.id}"`
|
|
5011
|
+
)
|
|
5012
|
+
)
|
|
5013
|
+
)
|
|
5014
|
+
);
|
|
5015
|
+
}
|
|
5016
|
+
function writeCompanionFiles(skillDir, companionFiles) {
|
|
5017
|
+
for (const file of companionFiles) {
|
|
5018
|
+
const absPath = resolvePathWithinDirectory(skillDir, file.path);
|
|
5019
|
+
ensureDirectoryExists(absPath);
|
|
5020
|
+
if (file.encoding === "base64") {
|
|
5021
|
+
fs13.writeFileSync(absPath, Buffer.from(file.content, "base64"));
|
|
5022
|
+
} else {
|
|
5023
|
+
fs13.writeFileSync(absPath, file.content, "utf8");
|
|
5024
|
+
}
|
|
5025
|
+
logger.info(` \u{1F4CE} Saved companion file: ${file.path}`);
|
|
5026
|
+
}
|
|
5027
|
+
}
|
|
4192
5028
|
async function findResourceByName2(fetchPage, name, resourceType) {
|
|
4193
5029
|
const allResources = [];
|
|
4194
5030
|
let page = 0;
|
|
@@ -4261,7 +5097,7 @@ function assertResolvedNameIsFree(config, stateManager, resourceType, slug, reso
|
|
|
4261
5097
|
}
|
|
4262
5098
|
return managedName;
|
|
4263
5099
|
}
|
|
4264
|
-
function writeResourceFiles(rootDir, resourceType, resource, apiResponse) {
|
|
5100
|
+
function writeResourceFiles(rootDir, resourceType, resource, apiResponse, companionFiles = []) {
|
|
4265
5101
|
const safeName = sanitizeFileName(resource.name);
|
|
4266
5102
|
const target = resource;
|
|
4267
5103
|
if (resourceType === "workflow") {
|
|
@@ -4269,34 +5105,34 @@ function writeResourceFiles(rootDir, resourceType, resource, apiResponse) {
|
|
|
4269
5105
|
const workflowResource = resource;
|
|
4270
5106
|
if (workflow.yaml_config) {
|
|
4271
5107
|
const defFileName = `${safeName}.yaml`;
|
|
4272
|
-
const defPath =
|
|
5108
|
+
const defPath = path13.join(rootDir, "workflows", defFileName);
|
|
4273
5109
|
ensureDirectoryExists(defPath);
|
|
4274
|
-
|
|
5110
|
+
fs13.writeFileSync(defPath, workflow.yaml_config, "utf8");
|
|
4275
5111
|
logger.info(` \u{1F4CB} Saved workflow definition: workflows/${defFileName}`);
|
|
4276
5112
|
workflowResource.definition = `workflows/${defFileName}`;
|
|
4277
5113
|
} else {
|
|
4278
5114
|
delete target.definition;
|
|
4279
5115
|
}
|
|
4280
|
-
const configPath =
|
|
5116
|
+
const configPath = path13.join(rootDir, "configs", "workflows", `${safeName}.yaml`);
|
|
4281
5117
|
const relativeConfigPath = `configs/workflows/${safeName}.yaml`;
|
|
4282
5118
|
ensureDirectoryExists(configPath);
|
|
4283
|
-
const yamlContent2 =
|
|
4284
|
-
|
|
5119
|
+
const yamlContent2 = yaml7.stringify(workflowResource, { lineWidth: 120 });
|
|
5120
|
+
fs13.writeFileSync(configPath, yamlContent2, "utf8");
|
|
4285
5121
|
logger.info(` \u{1F4C4} Saved workflow config: ${relativeConfigPath}`);
|
|
4286
5122
|
return relativeConfigPath;
|
|
4287
5123
|
}
|
|
4288
5124
|
const pluralType = pluralTypeOf(resourceType);
|
|
4289
|
-
const resourceDir =
|
|
4290
|
-
const resourceFilePath =
|
|
5125
|
+
const resourceDir = path13.join(rootDir, "configs", "imported-resources", pluralType);
|
|
5126
|
+
const resourceFilePath = path13.join(resourceDir, `${safeName}.yaml`);
|
|
4291
5127
|
const relativeResourcePath = `configs/imported-resources/${pluralType}/${safeName}.yaml`;
|
|
4292
5128
|
if (resourceType === "assistant") {
|
|
4293
5129
|
const assistant = apiResponse;
|
|
4294
5130
|
const assistantResource = resource;
|
|
4295
5131
|
if (assistant.system_prompt) {
|
|
4296
5132
|
const promptFileName = assistant.slug || safeName;
|
|
4297
|
-
const promptPath =
|
|
5133
|
+
const promptPath = path13.join(rootDir, "system_prompts", `${promptFileName}.prompt.md`);
|
|
4298
5134
|
ensureDirectoryExists(promptPath);
|
|
4299
|
-
|
|
5135
|
+
fs13.writeFileSync(promptPath, assistant.system_prompt, "utf8");
|
|
4300
5136
|
logger.info(` \u{1F4DD} Saved prompt: system_prompts/${promptFileName}.prompt.md`);
|
|
4301
5137
|
assistantResource.prompt = `system_prompts/${promptFileName}.prompt.md`;
|
|
4302
5138
|
} else {
|
|
@@ -4306,19 +5142,23 @@ function writeResourceFiles(rootDir, resourceType, resource, apiResponse) {
|
|
|
4306
5142
|
const skill = apiResponse;
|
|
4307
5143
|
const skillResource = resource;
|
|
4308
5144
|
if (skill.content) {
|
|
4309
|
-
const
|
|
4310
|
-
const
|
|
5145
|
+
const hasCompanionFiles = companionFiles.length > 0;
|
|
5146
|
+
const relativeSkillPath = hasCompanionFiles ? skillMarkdownRelativePath(resource.name) : skillFlatFileRelativePath(resource.name);
|
|
5147
|
+
const skillPath = path13.join(rootDir, relativeSkillPath);
|
|
4311
5148
|
ensureDirectoryExists(skillPath);
|
|
4312
|
-
|
|
4313
|
-
logger.info(` \u{1F9E0} Saved skill content:
|
|
4314
|
-
|
|
5149
|
+
fs13.writeFileSync(skillPath, skill.content, "utf8");
|
|
5150
|
+
logger.info(` \u{1F9E0} Saved skill content: ${relativeSkillPath}`);
|
|
5151
|
+
if (hasCompanionFiles) {
|
|
5152
|
+
writeCompanionFiles(path13.dirname(skillPath), companionFiles);
|
|
5153
|
+
}
|
|
5154
|
+
skillResource.file = relativeSkillPath;
|
|
4315
5155
|
} else {
|
|
4316
5156
|
delete target.file;
|
|
4317
5157
|
}
|
|
4318
5158
|
}
|
|
4319
5159
|
ensureDirectoryExists(resourceFilePath);
|
|
4320
|
-
const yamlContent =
|
|
4321
|
-
|
|
5160
|
+
const yamlContent = yaml7.stringify(resource, { lineWidth: 120 });
|
|
5161
|
+
fs13.writeFileSync(resourceFilePath, yamlContent, "utf8");
|
|
4322
5162
|
logger.info(` \u{1F4C4} Saved resource config: ${relativeResourcePath}`);
|
|
4323
5163
|
return relativeResourcePath;
|
|
4324
5164
|
}
|
|
@@ -4334,7 +5174,7 @@ function planCompanionWrite(rootDir, target, key, configuredValue, content, defa
|
|
|
4334
5174
|
}
|
|
4335
5175
|
const relPath = configuredPath ?? defaultPath;
|
|
4336
5176
|
target[key] = relPath;
|
|
4337
|
-
return { absPath:
|
|
5177
|
+
return { absPath: path13.join(rootDir, relPath), content, log: ` ${label}: ${relPath}` };
|
|
4338
5178
|
}
|
|
4339
5179
|
var IN_LIST_ITEM_INDENT = 2;
|
|
4340
5180
|
function itemCarriesAnchorAliasOrMergeKey(node) {
|
|
@@ -4343,28 +5183,28 @@ function itemCarriesAnchorAliasOrMergeKey(node) {
|
|
|
4343
5183
|
}
|
|
4344
5184
|
return node.items.some((pair) => {
|
|
4345
5185
|
const key = pair.key;
|
|
4346
|
-
const keyValue =
|
|
5186
|
+
const keyValue = yaml7.isScalar(key) ? key.value : key;
|
|
4347
5187
|
if (keyValue === "<<") {
|
|
4348
5188
|
return true;
|
|
4349
5189
|
}
|
|
4350
5190
|
const value = pair.value;
|
|
4351
|
-
if (
|
|
5191
|
+
if (yaml7.isAlias(value)) {
|
|
4352
5192
|
return true;
|
|
4353
5193
|
}
|
|
4354
|
-
return
|
|
5194
|
+
return yaml7.isNode(value) && value.anchor !== void 0;
|
|
4355
5195
|
});
|
|
4356
5196
|
}
|
|
4357
5197
|
function spliceResourceIntoList(filePath, relativeResourcePath, resource, existingName) {
|
|
4358
|
-
const source =
|
|
4359
|
-
const doc =
|
|
5198
|
+
const source = fs13.readFileSync(filePath, "utf8");
|
|
5199
|
+
const doc = yaml7.parseDocument(source);
|
|
4360
5200
|
const refusal = (reason) => new Error(
|
|
4361
5201
|
`Cannot safely update "${existingName}" inside ${relativeResourcePath}: ${reason}. Update ${relativeResourcePath} manually.`
|
|
4362
5202
|
);
|
|
4363
|
-
if (!
|
|
5203
|
+
if (!yaml7.isSeq(doc.contents) || doc.contents.flow) {
|
|
4364
5204
|
throw refusal("the file is not a block-style YAML sequence");
|
|
4365
5205
|
}
|
|
4366
5206
|
const node = doc.contents.items.find((item) => {
|
|
4367
|
-
if (!
|
|
5207
|
+
if (!yaml7.isMap(item)) {
|
|
4368
5208
|
return false;
|
|
4369
5209
|
}
|
|
4370
5210
|
const itemName = item.get("name");
|
|
@@ -4384,13 +5224,13 @@ function spliceResourceIntoList(filePath, relativeResourcePath, resource, existi
|
|
|
4384
5224
|
if (indent !== IN_LIST_ITEM_INDENT) {
|
|
4385
5225
|
throw refusal(`its entry is indented by ${indent} spaces instead of ${IN_LIST_ITEM_INDENT}`);
|
|
4386
5226
|
}
|
|
4387
|
-
const rendered =
|
|
5227
|
+
const rendered = yaml7.stringify(resource, { lineWidth: 120 }).trimEnd();
|
|
4388
5228
|
const replacement = rendered.split("\n").map((line, index) => index === 0 || !line ? line : `${" ".repeat(IN_LIST_ITEM_INDENT)}${line}`).join("\n");
|
|
4389
5229
|
const tail = source.slice(valueEnd);
|
|
4390
5230
|
const separator = tail.startsWith("\n") ? "" : "\n";
|
|
4391
5231
|
return source.slice(0, start) + replacement + separator + tail;
|
|
4392
5232
|
}
|
|
4393
|
-
function updateResourceFiles(rootDir, resourceType, resource, apiResponse, existing) {
|
|
5233
|
+
function updateResourceFiles(rootDir, resourceType, resource, apiResponse, existing, companionFiles = []) {
|
|
4394
5234
|
const filePath = existing.file;
|
|
4395
5235
|
if (!filePath) {
|
|
4396
5236
|
throw new Error("updateResourceFiles requires an existing resource backed by a file");
|
|
@@ -4418,13 +5258,15 @@ function updateResourceFiles(rootDir, resourceType, resource, apiResponse, exist
|
|
|
4418
5258
|
);
|
|
4419
5259
|
} else if (resourceType === "skill") {
|
|
4420
5260
|
const skill = apiResponse;
|
|
5261
|
+
const hasCompanionFiles = companionFiles.length > 0;
|
|
5262
|
+
const defaultSkillPath = hasCompanionFiles ? skillMarkdownRelativePath(resource.name) : skillFlatFileRelativePath(resource.name);
|
|
4421
5263
|
companion = planCompanionWrite(
|
|
4422
5264
|
rootDir,
|
|
4423
5265
|
target,
|
|
4424
5266
|
"file",
|
|
4425
5267
|
existingResource.file,
|
|
4426
5268
|
skill.content,
|
|
4427
|
-
|
|
5269
|
+
defaultSkillPath,
|
|
4428
5270
|
"\u{1F9E0} Updated skill content"
|
|
4429
5271
|
);
|
|
4430
5272
|
} else if (resourceType === "workflow") {
|
|
@@ -4439,16 +5281,25 @@ function updateResourceFiles(rootDir, resourceType, resource, apiResponse, exist
|
|
|
4439
5281
|
"\u{1F4CB} Updated workflow definition"
|
|
4440
5282
|
);
|
|
4441
5283
|
}
|
|
4442
|
-
const relativeResourcePath =
|
|
4443
|
-
const newResourceFileContent = existing.inList ? spliceResourceIntoList(filePath, relativeResourcePath, resource, String(existingResource.name)) :
|
|
5284
|
+
const relativeResourcePath = path13.relative(rootDir, filePath);
|
|
5285
|
+
const newResourceFileContent = existing.inList ? spliceResourceIntoList(filePath, relativeResourcePath, resource, String(existingResource.name)) : yaml7.stringify(resource, { lineWidth: 120 });
|
|
5286
|
+
const companionFilesWritten = resourceType === "skill" && companionFiles.length > 0 && companion !== void 0 && hasCompanionFileLayout(resource);
|
|
4444
5287
|
if (companion) {
|
|
4445
5288
|
ensureDirectoryExists(companion.absPath);
|
|
4446
|
-
|
|
5289
|
+
fs13.writeFileSync(companion.absPath, companion.content, "utf8");
|
|
4447
5290
|
logger.info(companion.log);
|
|
5291
|
+
if (companionFilesWritten) {
|
|
5292
|
+
writeCompanionFiles(path13.dirname(companion.absPath), companionFiles);
|
|
5293
|
+
}
|
|
5294
|
+
}
|
|
5295
|
+
if (resourceType === "skill" && companionFiles.length > 0 && !companionFilesWritten) {
|
|
5296
|
+
logger.warn(
|
|
5297
|
+
` \u26A0\uFE0F Skill "${resource.name}" has ${companionFiles.length} companion file(s) on the platform, but none were written locally (configured file: "${resource.file ?? "(none)"}"): they stay on the platform and are not managed locally. Point the entry at a skills/<name>/SKILL.md layout to manage them.`
|
|
5298
|
+
);
|
|
4448
5299
|
}
|
|
4449
|
-
|
|
5300
|
+
fs13.writeFileSync(filePath, newResourceFileContent, "utf8");
|
|
4450
5301
|
logger.info(` \u{1F4C4} Updated resource config: ${relativeResourcePath}`);
|
|
4451
|
-
return relativeResourcePath;
|
|
5302
|
+
return { relativeResourcePath, companionFilesWritten };
|
|
4452
5303
|
}
|
|
4453
5304
|
function deleteStateEntry(stateManager, resourceType, name) {
|
|
4454
5305
|
switch (resourceType) {
|
|
@@ -4471,12 +5322,12 @@ function deleteStateEntry(stateManager, resourceType, name) {
|
|
|
4471
5322
|
}
|
|
4472
5323
|
}
|
|
4473
5324
|
function addImportToCodemieYaml(rootDir, codemieConfigPath, resourceType, relativeResourcePath) {
|
|
4474
|
-
const configPath =
|
|
4475
|
-
if (!
|
|
5325
|
+
const configPath = path13.join(rootDir, codemieConfigPath);
|
|
5326
|
+
if (!fs13.existsSync(configPath)) {
|
|
4476
5327
|
throw new Error(`Configuration file not found: ${configPath}`);
|
|
4477
5328
|
}
|
|
4478
|
-
const content =
|
|
4479
|
-
const doc =
|
|
5329
|
+
const content = fs13.readFileSync(configPath, "utf8");
|
|
5330
|
+
const doc = yaml7.parseDocument(content);
|
|
4480
5331
|
const pluralType = pluralTypeOf(resourceType);
|
|
4481
5332
|
let resourcesNode = doc.get("resources");
|
|
4482
5333
|
if (!resourcesNode) {
|
|
@@ -4490,7 +5341,7 @@ function addImportToCodemieYaml(rootDir, codemieConfigPath, resourceType, relati
|
|
|
4490
5341
|
}
|
|
4491
5342
|
const importDirective = { $import: relativeResourcePath };
|
|
4492
5343
|
const existingImports = typeArray.items.filter((item) => {
|
|
4493
|
-
if (
|
|
5344
|
+
if (yaml7.isMap(item)) {
|
|
4494
5345
|
const importValue = item.get("$import");
|
|
4495
5346
|
return importValue === relativeResourcePath;
|
|
4496
5347
|
}
|
|
@@ -4502,16 +5353,16 @@ function addImportToCodemieYaml(rootDir, codemieConfigPath, resourceType, relati
|
|
|
4502
5353
|
}
|
|
4503
5354
|
const newNode = doc.createNode(importDirective);
|
|
4504
5355
|
typeArray.add(newNode);
|
|
4505
|
-
|
|
5356
|
+
fs13.writeFileSync(configPath, doc.toString(), "utf8");
|
|
4506
5357
|
logger.info(` \u2705 Added $import to ${codemieConfigPath} \u2192 resources.${pluralType}`);
|
|
4507
5358
|
}
|
|
4508
5359
|
function addImportedSkillToCodemieYaml(rootDir, codemieConfigPath, skill) {
|
|
4509
|
-
const configPath =
|
|
4510
|
-
if (!
|
|
5360
|
+
const configPath = path13.join(rootDir, codemieConfigPath);
|
|
5361
|
+
if (!fs13.existsSync(configPath)) {
|
|
4511
5362
|
throw new Error(`Configuration file not found: ${configPath}`);
|
|
4512
5363
|
}
|
|
4513
|
-
const content =
|
|
4514
|
-
const doc =
|
|
5364
|
+
const content = fs13.readFileSync(configPath, "utf8");
|
|
5365
|
+
const doc = yaml7.parseDocument(content);
|
|
4515
5366
|
let importedNode = doc.get("imported");
|
|
4516
5367
|
if (!importedNode) {
|
|
4517
5368
|
importedNode = doc.createNode({ assistants: [], datasources: [], skills: [], integrations: [] });
|
|
@@ -4523,7 +5374,7 @@ function addImportedSkillToCodemieYaml(rootDir, codemieConfigPath, skill) {
|
|
|
4523
5374
|
doc.setIn(["imported", "skills"], skillsArray);
|
|
4524
5375
|
}
|
|
4525
5376
|
const existingSkill = skillsArray.items.find((item) => {
|
|
4526
|
-
if (!
|
|
5377
|
+
if (!yaml7.isMap(item)) {
|
|
4527
5378
|
return false;
|
|
4528
5379
|
}
|
|
4529
5380
|
const existingName = item.get("name");
|
|
@@ -4540,21 +5391,21 @@ function addImportedSkillToCodemieYaml(rootDir, codemieConfigPath, skill) {
|
|
|
4540
5391
|
return;
|
|
4541
5392
|
}
|
|
4542
5393
|
skillsArray.add(doc.createNode({ name: skill.name, id: skill.id }));
|
|
4543
|
-
|
|
5394
|
+
fs13.writeFileSync(configPath, doc.toString(), "utf8");
|
|
4544
5395
|
logger.info(` \u2705 Added skill to ${codemieConfigPath} \u2192 imported.skills`);
|
|
4545
5396
|
}
|
|
4546
5397
|
function updateImportedSkillInCodemieYaml(rootDir, codemieConfigPath, skill) {
|
|
4547
|
-
const configPath =
|
|
4548
|
-
if (!
|
|
5398
|
+
const configPath = path13.join(rootDir, codemieConfigPath);
|
|
5399
|
+
if (!fs13.existsSync(configPath)) {
|
|
4549
5400
|
throw new Error(`Configuration file not found: ${configPath}`);
|
|
4550
5401
|
}
|
|
4551
|
-
const content =
|
|
4552
|
-
const doc =
|
|
5402
|
+
const content = fs13.readFileSync(configPath, "utf8");
|
|
5403
|
+
const doc = yaml7.parseDocument(content);
|
|
4553
5404
|
const skillsArray = doc.getIn(["imported", "skills"]);
|
|
4554
5405
|
if (!skillsArray) {
|
|
4555
5406
|
return false;
|
|
4556
5407
|
}
|
|
4557
|
-
const items = skillsArray.items.filter((item) =>
|
|
5408
|
+
const items = skillsArray.items.filter((item) => yaml7.isMap(item));
|
|
4558
5409
|
const entryById = items.find((item) => {
|
|
4559
5410
|
const existingId = item.get("id");
|
|
4560
5411
|
return typeof existingId === "string" && existingId === skill.id;
|
|
@@ -4568,7 +5419,7 @@ function updateImportedSkillInCodemieYaml(rootDir, codemieConfigPath, skill) {
|
|
|
4568
5419
|
}
|
|
4569
5420
|
entry.set("name", skill.name);
|
|
4570
5421
|
entry.set("id", skill.id);
|
|
4571
|
-
|
|
5422
|
+
fs13.writeFileSync(configPath, doc.toString(), "utf8");
|
|
4572
5423
|
return true;
|
|
4573
5424
|
}
|
|
4574
5425
|
function upsertImportedSkill(rootDir, codemieConfigPath, skill, update) {
|
|
@@ -4590,7 +5441,15 @@ function ensureExternalSkillDoesNotConflictWithManagedSkill(config, skillName) {
|
|
|
4590
5441
|
`External skill "${skillName}" is already defined in resources.skills. Keep project-owned skills in resources.skills or external skills in imported.skills, not both.`
|
|
4591
5442
|
);
|
|
4592
5443
|
}
|
|
4593
|
-
function
|
|
5444
|
+
async function importReferencedProjectSkill(client, rootDir, codemieConfigPath, stateManager, skill) {
|
|
5445
|
+
const companionFiles = await fetchSkillCompanionFiles(client, skill);
|
|
5446
|
+
const skillResource = skillResponseToResource(skill);
|
|
5447
|
+
const relativeSkillPath = writeResourceFiles(rootDir, "skill", skillResource, skill, companionFiles);
|
|
5448
|
+
addImportToCodemieYaml(rootDir, codemieConfigPath, "skill", relativeSkillPath);
|
|
5449
|
+
updateState(stateManager, "skill", skillResource, skill, companionFiles);
|
|
5450
|
+
logger.info(` \u2713 Imported project-owned skill "${skill.name}" into resources.skills`);
|
|
5451
|
+
}
|
|
5452
|
+
function updateState(stateManager, resourceType, resource, apiResponse, companionFiles = []) {
|
|
4594
5453
|
switch (resourceType) {
|
|
4595
5454
|
case "assistant": {
|
|
4596
5455
|
const assistant = apiResponse;
|
|
@@ -4618,7 +5477,13 @@ function updateState(stateManager, resourceType, resource, apiResponse) {
|
|
|
4618
5477
|
case "skill": {
|
|
4619
5478
|
const skill = apiResponse;
|
|
4620
5479
|
const skillResource = resource;
|
|
4621
|
-
stateManager.updateSkillState(
|
|
5480
|
+
stateManager.updateSkillState(
|
|
5481
|
+
resource.name,
|
|
5482
|
+
skill.id,
|
|
5483
|
+
skill.content || "",
|
|
5484
|
+
skillResource,
|
|
5485
|
+
companionFiles.length > 0 ? companionFiles : void 0
|
|
5486
|
+
);
|
|
4622
5487
|
break;
|
|
4623
5488
|
}
|
|
4624
5489
|
}
|
|
@@ -4633,10 +5498,13 @@ function buildIntegrationAliasMap(config) {
|
|
|
4633
5498
|
return map;
|
|
4634
5499
|
}
|
|
4635
5500
|
async function importResource(options) {
|
|
4636
|
-
const { appConfig, resourceType, slug, update = false } = options;
|
|
5501
|
+
const { appConfig, resourceType, slug, update = false, withSkills = false } = options;
|
|
4637
5502
|
if (!VALID_RESOURCE_TYPES.includes(resourceType)) {
|
|
4638
5503
|
throw new Error(`Invalid resource type: "${resourceType}". Must be one of: ${VALID_RESOURCE_TYPES.join(", ")}`);
|
|
4639
5504
|
}
|
|
5505
|
+
if (withSkills && resourceType !== "assistant") {
|
|
5506
|
+
logger.warn(` \u26A0\uFE0F --with-skills only applies to assistants \u2014 ignoring it for ${resourceType}.`);
|
|
5507
|
+
}
|
|
4640
5508
|
const configLoader = new CodemieConfigLoader(appConfig);
|
|
4641
5509
|
const config = configLoader.loadConfig();
|
|
4642
5510
|
const rootDir = appConfig.rootDir;
|
|
@@ -4653,6 +5521,7 @@ async function importResource(options) {
|
|
|
4653
5521
|
let resource;
|
|
4654
5522
|
let apiResponse;
|
|
4655
5523
|
let managedName;
|
|
5524
|
+
let skillCompanionFiles = [];
|
|
4656
5525
|
switch (resourceType) {
|
|
4657
5526
|
case "assistant": {
|
|
4658
5527
|
logger.info(` Searching for assistant "${slug}"...`);
|
|
@@ -4684,6 +5553,7 @@ async function importResource(options) {
|
|
|
4684
5553
|
if (assistantData.skill_ids && assistantData.skill_ids.length > 0) {
|
|
4685
5554
|
logger.info(` Resolving ${assistantData.skill_ids.length} skill ID(s)...`);
|
|
4686
5555
|
const skillNames = [];
|
|
5556
|
+
const importedProjectSkills = /* @__PURE__ */ new Set();
|
|
4687
5557
|
for (const skillId of assistantData.skill_ids) {
|
|
4688
5558
|
let skill;
|
|
4689
5559
|
try {
|
|
@@ -4701,6 +5571,18 @@ async function importResource(options) {
|
|
|
4701
5571
|
if (!isProjectOwnedSkill(skill, config.project.name)) {
|
|
4702
5572
|
ensureExternalSkillDoesNotConflictWithManagedSkill(config, skill.name);
|
|
4703
5573
|
upsertImportedSkill(rootDir, appConfig.codemieConfig, { name: skill.name, id: skill.id }, update);
|
|
5574
|
+
continue;
|
|
5575
|
+
}
|
|
5576
|
+
if (withSkills && !checkResourceExists2(config, "skill", skill.name) && !importedProjectSkills.has(skill.name.toLowerCase())) {
|
|
5577
|
+
const managedSkillName = findManagedNameById(stateManager, "skill", skill.id);
|
|
5578
|
+
if (managedSkillName !== void 0) {
|
|
5579
|
+
logger.warn(
|
|
5580
|
+
` \u26A0\uFE0F Skill "${skill.name}" is already managed under the name "${managedSkillName}" \u2014 not imported. Run \`codemie import skill ${skill.id} --update\` to refresh it.`
|
|
5581
|
+
);
|
|
5582
|
+
continue;
|
|
5583
|
+
}
|
|
5584
|
+
await importReferencedProjectSkill(client, rootDir, appConfig.codemieConfig, stateManager, skill);
|
|
5585
|
+
importedProjectSkills.add(skill.name.toLowerCase());
|
|
4704
5586
|
}
|
|
4705
5587
|
}
|
|
4706
5588
|
if (skillNames.length > 0) {
|
|
@@ -4753,6 +5635,7 @@ async function importResource(options) {
|
|
|
4753
5635
|
if (isProjectOwnedSkill(skill, config.project.name)) {
|
|
4754
5636
|
logger.info(` Project-owned skill \u2014 importing into resources.skills`);
|
|
4755
5637
|
apiResponse = skill;
|
|
5638
|
+
skillCompanionFiles = await fetchSkillCompanionFiles(client, skill);
|
|
4756
5639
|
resource = skillResponseToResource(skill);
|
|
4757
5640
|
break;
|
|
4758
5641
|
}
|
|
@@ -4774,12 +5657,25 @@ async function importResource(options) {
|
|
|
4774
5657
|
);
|
|
4775
5658
|
}
|
|
4776
5659
|
logger.info(` \u267B\uFE0F Updating existing ${resourceType} config in place...`);
|
|
4777
|
-
|
|
5660
|
+
const { companionFilesWritten } = updateResourceFiles(
|
|
5661
|
+
rootDir,
|
|
5662
|
+
resourceType,
|
|
5663
|
+
resource,
|
|
5664
|
+
apiResponse,
|
|
5665
|
+
existing,
|
|
5666
|
+
skillCompanionFiles
|
|
5667
|
+
);
|
|
4778
5668
|
if (managedName !== void 0 && !namesEqual(managedName, resource.name)) {
|
|
4779
5669
|
logger.info(` \u{1F3F7}\uFE0F Renamed from "${managedName}" to "${resource.name}" \u2014 updating state.json`);
|
|
4780
5670
|
deleteStateEntry(stateManager, resourceType, managedName);
|
|
4781
5671
|
}
|
|
4782
|
-
updateState(
|
|
5672
|
+
updateState(
|
|
5673
|
+
stateManager,
|
|
5674
|
+
resourceType,
|
|
5675
|
+
resource,
|
|
5676
|
+
apiResponse,
|
|
5677
|
+
companionFilesWritten ? skillCompanionFiles : void 0
|
|
5678
|
+
);
|
|
4783
5679
|
logger.info(`
|
|
4784
5680
|
\u2705 Successfully imported ${resourceType} "${resource.name}"
|
|
4785
5681
|
`);
|
|
@@ -4787,9 +5683,9 @@ async function importResource(options) {
|
|
|
4787
5683
|
}
|
|
4788
5684
|
logger.info(` No existing ${resourceType} found in the configuration \u2014 importing as new`);
|
|
4789
5685
|
}
|
|
4790
|
-
const relativeResourcePath = writeResourceFiles(rootDir, resourceType, resource, apiResponse);
|
|
5686
|
+
const relativeResourcePath = writeResourceFiles(rootDir, resourceType, resource, apiResponse, skillCompanionFiles);
|
|
4791
5687
|
addImportToCodemieYaml(rootDir, appConfig.codemieConfig, resourceType, relativeResourcePath);
|
|
4792
|
-
updateState(stateManager, resourceType, resource, apiResponse);
|
|
5688
|
+
updateState(stateManager, resourceType, resource, apiResponse, skillCompanionFiles);
|
|
4793
5689
|
logger.info(`
|
|
4794
5690
|
\u2705 Successfully imported ${resourceType} "${resource.name}"
|
|
4795
5691
|
`);
|
|
@@ -4807,7 +5703,7 @@ async function main4(options) {
|
|
|
4807
5703
|
}
|
|
4808
5704
|
init_logger();
|
|
4809
5705
|
function fileExists(filePath) {
|
|
4810
|
-
return
|
|
5706
|
+
return fs13.existsSync(filePath);
|
|
4811
5707
|
}
|
|
4812
5708
|
function generateEnvTemplate() {
|
|
4813
5709
|
return `# Codemie API Configuration
|
|
@@ -4886,14 +5782,14 @@ function compareConfigWithDefaults(userConfig) {
|
|
|
4886
5782
|
}
|
|
4887
5783
|
async function saveConfigFile(config, defaultFilename = "config.json") {
|
|
4888
5784
|
const configFilename = await promptUser(`Enter config file path`, defaultFilename);
|
|
4889
|
-
const configPath =
|
|
5785
|
+
const configPath = path13.resolve(process.cwd(), configFilename);
|
|
4890
5786
|
if (fileExists(configPath)) {
|
|
4891
5787
|
const shouldOverwrite = await confirmOverwrite(configFilename);
|
|
4892
5788
|
if (!shouldOverwrite) {
|
|
4893
5789
|
throw new Error(`Cancelled: Configuration file not saved.`);
|
|
4894
5790
|
}
|
|
4895
5791
|
}
|
|
4896
|
-
|
|
5792
|
+
fs13.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
4897
5793
|
return configFilename;
|
|
4898
5794
|
}
|
|
4899
5795
|
function suggestConfigUsage(configFileName) {
|
|
@@ -4912,8 +5808,8 @@ async function initProject(options) {
|
|
|
4912
5808
|
logger.info("\u{1F680} Initialize Codemie IaC Project\n\n");
|
|
4913
5809
|
try {
|
|
4914
5810
|
const { appConfig } = options;
|
|
4915
|
-
const envPath =
|
|
4916
|
-
const configPath =
|
|
5811
|
+
const envPath = path13.resolve(appConfig.rootDir, ".env");
|
|
5812
|
+
const configPath = path13.resolve(appConfig.rootDir, appConfig.codemieConfig);
|
|
4917
5813
|
logger.info("This wizard will create the following files:");
|
|
4918
5814
|
logger.info(` \u{1F4C4} .env - Environment variables with API credentials`);
|
|
4919
5815
|
logger.info(` \u{1F4C4} ${appConfig.codemieConfig} - Codemie IaC configuration
|
|
@@ -4966,7 +5862,7 @@ async function initProject(options) {
|
|
|
4966
5862
|
logger.info("\n\u{1F4C1} Creating configuration files...\n");
|
|
4967
5863
|
if (shouldCreateEnv) {
|
|
4968
5864
|
const envContent = generateEnvTemplate();
|
|
4969
|
-
|
|
5865
|
+
fs13.writeFileSync(envPath, envContent, "utf-8");
|
|
4970
5866
|
logger.info(`\u2713 Created .env`);
|
|
4971
5867
|
logger.warn(` \u26A0\uFE0F Remember to fill in your actual credentials!`);
|
|
4972
5868
|
logger.warn(` \u26A0\uFE0F DO NOT commit .env to Git!
|
|
@@ -4974,7 +5870,7 @@ async function initProject(options) {
|
|
|
4974
5870
|
}
|
|
4975
5871
|
if (shouldCreateConfig) {
|
|
4976
5872
|
const configContent = generateMinimalCodemieYaml(projectName, projectDescription);
|
|
4977
|
-
|
|
5873
|
+
fs13.writeFileSync(configPath, configContent, "utf-8");
|
|
4978
5874
|
logger.info(`\u2713 Created ${appConfig.codemieConfig}`);
|
|
4979
5875
|
logger.info(` See examples/ directory for detailed configuration examples
|
|
4980
5876
|
|
|
@@ -5014,6 +5910,7 @@ init_logger();
|
|
|
5014
5910
|
init_checksumUtils();
|
|
5015
5911
|
init_codemieConfigChecksums();
|
|
5016
5912
|
init_converters();
|
|
5913
|
+
init_skillCompanionFiles();
|
|
5017
5914
|
async function previewResource(resource, resourceType, getState, checkExists, calculateChecksums, staleDetails) {
|
|
5018
5915
|
const existingState = getState(resource.name);
|
|
5019
5916
|
if (existingState) {
|
|
@@ -5088,12 +5985,67 @@ function previewOrphanedResources(orphaned, stateManager) {
|
|
|
5088
5985
|
}
|
|
5089
5986
|
return changes;
|
|
5090
5987
|
}
|
|
5091
|
-
|
|
5988
|
+
function previewSkillGroupReplacement(config, stateManager, group) {
|
|
5989
|
+
const { namesToDelete, groupSkills } = selectSkillGroupForReplacement(config, stateManager, group);
|
|
5990
|
+
const changes = [];
|
|
5991
|
+
for (const name of namesToDelete) {
|
|
5992
|
+
const skillState = stateManager.getSkillState(name);
|
|
5993
|
+
changes.push({
|
|
5994
|
+
type: "delete",
|
|
5995
|
+
resourceType: "skill",
|
|
5996
|
+
name,
|
|
5997
|
+
details: skillState ? `Replacing skill group "${group}" (ID: ${skillState.id})` : `Replacing skill group "${group}"`
|
|
5998
|
+
});
|
|
5999
|
+
}
|
|
6000
|
+
for (const skill of groupSkills) {
|
|
6001
|
+
changes.push({
|
|
6002
|
+
type: "create",
|
|
6003
|
+
resourceType: "skill",
|
|
6004
|
+
name: skill.name,
|
|
6005
|
+
details: `Recreated by --replace-skill-group "${group}" with a new platform id`
|
|
6006
|
+
});
|
|
6007
|
+
}
|
|
6008
|
+
return changes;
|
|
6009
|
+
}
|
|
6010
|
+
function describeCompanionFileChanges(currentHashes, previousHashes) {
|
|
6011
|
+
const added = [];
|
|
6012
|
+
const removed = [];
|
|
6013
|
+
const modified = [];
|
|
6014
|
+
const allPaths = /* @__PURE__ */ new Set([...Object.keys(currentHashes), ...Object.keys(previousHashes)]);
|
|
6015
|
+
for (const filePath of allPaths) {
|
|
6016
|
+
const inCurrent = Object.hasOwn(currentHashes, filePath);
|
|
6017
|
+
const inPrevious = Object.hasOwn(previousHashes, filePath);
|
|
6018
|
+
if (inCurrent && !inPrevious) {
|
|
6019
|
+
added.push(filePath);
|
|
6020
|
+
} else if (!inCurrent && inPrevious) {
|
|
6021
|
+
removed.push(filePath);
|
|
6022
|
+
} else if (currentHashes[filePath] !== previousHashes[filePath]) {
|
|
6023
|
+
modified.push(filePath);
|
|
6024
|
+
}
|
|
6025
|
+
}
|
|
6026
|
+
added.sort();
|
|
6027
|
+
removed.sort();
|
|
6028
|
+
modified.sort();
|
|
6029
|
+
const segments = [];
|
|
6030
|
+
if (added.length > 0) {
|
|
6031
|
+
segments.push(`added ${added.join(", ")}`);
|
|
6032
|
+
}
|
|
6033
|
+
if (removed.length > 0) {
|
|
6034
|
+
segments.push(`removed ${removed.join(", ")}`);
|
|
6035
|
+
}
|
|
6036
|
+
if (modified.length > 0) {
|
|
6037
|
+
segments.push(`modified ${modified.join(", ")}`);
|
|
6038
|
+
}
|
|
6039
|
+
return `Companion files changed: ${segments.join("; ")}`;
|
|
6040
|
+
}
|
|
6041
|
+
async function previewSkills(skills, loader, stateManager, client, rootDir = process.cwd()) {
|
|
5092
6042
|
const changes = [];
|
|
5093
6043
|
for (const skill of skills) {
|
|
5094
|
-
const content = loader.
|
|
6044
|
+
const content = loader.resolveSkillContent(skill);
|
|
5095
6045
|
const contentChecksum = calculateChecksum(content);
|
|
5096
6046
|
const configChecksum = calculateSkillConfigChecksum(skill);
|
|
6047
|
+
const companionFiles = hasCompanionFileLayout(skill) ? collectCompanionFiles(path13.dirname(path13.join(rootDir, skill.file))) : [];
|
|
6048
|
+
const { companionFilesChecksum, companionFileHashes } = calculateCompanionFilesChecksum(companionFiles);
|
|
5097
6049
|
const change = await previewResource(
|
|
5098
6050
|
skill,
|
|
5099
6051
|
"skill",
|
|
@@ -5101,10 +6053,22 @@ async function previewSkills(skills, loader, stateManager, client) {
|
|
|
5101
6053
|
() => checkSkillExists(client, skill.name, stateManager),
|
|
5102
6054
|
() => {
|
|
5103
6055
|
const existingState = stateManager.getSkillState(skill.name);
|
|
5104
|
-
|
|
6056
|
+
if (!existingState) {
|
|
6057
|
+
return { hasChanged: false };
|
|
6058
|
+
}
|
|
6059
|
+
const contentOrConfigChanged = existingState.contentChecksum !== contentChecksum || existingState.configChecksum !== configChecksum;
|
|
6060
|
+
const companionFilesChanged = companionFiles.length > 0 || stateHasCompanionFiles(existingState) ? existingState.companionFilesChecksum !== companionFilesChecksum : false;
|
|
6061
|
+
const hasChanged = contentOrConfigChanged || companionFilesChanged;
|
|
6062
|
+
const detailParts = [];
|
|
6063
|
+
if (contentOrConfigChanged) {
|
|
6064
|
+
detailParts.push("Content or configuration changed");
|
|
6065
|
+
}
|
|
6066
|
+
if (companionFilesChanged) {
|
|
6067
|
+
detailParts.push(describeCompanionFileChanges(companionFileHashes, existingState.companionFileHashes ?? {}));
|
|
6068
|
+
}
|
|
5105
6069
|
return {
|
|
5106
6070
|
hasChanged,
|
|
5107
|
-
updateDetails: "
|
|
6071
|
+
updateDetails: detailParts.length > 0 ? detailParts.join("; ") : void 0
|
|
5108
6072
|
};
|
|
5109
6073
|
}
|
|
5110
6074
|
);
|
|
@@ -5239,11 +6203,11 @@ async function previewWorkflows(workflows, stateManager, client, rootDir = proce
|
|
|
5239
6203
|
const projectClause = project ? ` in project ${project}` : "";
|
|
5240
6204
|
const staleDetails = `ID from state not found; will adopt a same-name workflow${projectClause} if one exists, otherwise create`;
|
|
5241
6205
|
for (const workflow of workflows) {
|
|
5242
|
-
const yamlPath =
|
|
5243
|
-
if (!
|
|
6206
|
+
const yamlPath = path13.join(rootDir, workflow.definition);
|
|
6207
|
+
if (!fs13.existsSync(yamlPath)) {
|
|
5244
6208
|
throw new Error(`Workflow definition file not found: ${workflow.definition}`);
|
|
5245
6209
|
}
|
|
5246
|
-
const yamlConfig =
|
|
6210
|
+
const yamlConfig = fs13.readFileSync(yamlPath, "utf8");
|
|
5247
6211
|
const change = await previewResource(
|
|
5248
6212
|
workflow,
|
|
5249
6213
|
"workflow",
|
|
@@ -5274,15 +6238,31 @@ async function previewChanges(appConfig, existingClient, options) {
|
|
|
5274
6238
|
const loader = new CodemieConfigLoader(appConfig);
|
|
5275
6239
|
const stateManager = new StateManager(appConfig);
|
|
5276
6240
|
const config = loader.loadConfig();
|
|
6241
|
+
const skillDescriptionErrors = validateSkillDescriptions(config.resources.skills ?? []);
|
|
6242
|
+
if (skillDescriptionErrors.length > 0) {
|
|
6243
|
+
throw new Error(skillDescriptionErrors.join("\n"));
|
|
6244
|
+
}
|
|
5277
6245
|
const client = existingClient || await createClient(config);
|
|
5278
6246
|
const changes = [];
|
|
6247
|
+
if (options?.replaceSkillGroup) {
|
|
6248
|
+
const group = options.replaceSkillGroup;
|
|
6249
|
+
changes.push(...previewSkillGroupReplacement(config, stateManager, group));
|
|
6250
|
+
const referencingAssistants = expandAssistantsWithDependencies(
|
|
6251
|
+
filterAssistantsReferencingSkillGroup(config.resources.assistants, config.resources.skills, group),
|
|
6252
|
+
config.resources.assistants
|
|
6253
|
+
);
|
|
6254
|
+
if (referencingAssistants.length > 0) {
|
|
6255
|
+
changes.push(...await previewAssistants(referencingAssistants, loader, stateManager, client, config));
|
|
6256
|
+
}
|
|
6257
|
+
return summarizeChanges(changes);
|
|
6258
|
+
}
|
|
5279
6259
|
const cleanupManager = new CleanupManager(client, stateManager);
|
|
5280
6260
|
const skipDatasources = options?.skipDatasources === true;
|
|
5281
6261
|
const foundOrphaned = cleanupManager.findOrphanedResources(config);
|
|
5282
6262
|
const orphaned = skipDatasources ? { ...foundOrphaned, datasources: [] } : foundOrphaned;
|
|
5283
6263
|
changes.push(...previewOrphanedResources(orphaned, stateManager));
|
|
5284
6264
|
if (config.resources.skills) {
|
|
5285
|
-
const skillChanges = await previewSkills(config.resources.skills, loader, stateManager, client);
|
|
6265
|
+
const skillChanges = await previewSkills(config.resources.skills, loader, stateManager, client, appConfig.rootDir);
|
|
5286
6266
|
changes.push(...skillChanges);
|
|
5287
6267
|
}
|
|
5288
6268
|
if (config.resources.assistants) {
|
|
@@ -5303,17 +6283,16 @@ async function previewChanges(appConfig, existingClient, options) {
|
|
|
5303
6283
|
);
|
|
5304
6284
|
changes.push(...workflowChanges);
|
|
5305
6285
|
}
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
const unchanged = changes.filter((c) => c.type === "no-change");
|
|
6286
|
+
return summarizeChanges(changes);
|
|
6287
|
+
}
|
|
6288
|
+
function summarizeChanges(changes) {
|
|
5310
6289
|
return {
|
|
5311
6290
|
changes,
|
|
5312
6291
|
summary: {
|
|
5313
|
-
deleted:
|
|
5314
|
-
created:
|
|
5315
|
-
updated:
|
|
5316
|
-
unchanged:
|
|
6292
|
+
deleted: changes.filter((c) => c.type === "delete").length,
|
|
6293
|
+
created: changes.filter((c) => c.type === "create").length,
|
|
6294
|
+
updated: changes.filter((c) => c.type === "update").length,
|
|
6295
|
+
unchanged: changes.filter((c) => c.type === "no-change").length,
|
|
5317
6296
|
total: changes.length
|
|
5318
6297
|
}
|
|
5319
6298
|
};
|
|
@@ -5342,8 +6321,15 @@ async function main6(options) {
|
|
|
5342
6321
|
if (options.skipDatasources) {
|
|
5343
6322
|
logger.info("\u23ED\uFE0F Datasources excluded from preview (--skip-datasources)\n");
|
|
5344
6323
|
}
|
|
6324
|
+
if (options.replaceSkillGroup) {
|
|
6325
|
+
logger.info(
|
|
6326
|
+
`\u267B\uFE0F Previewing replacement of skill group "${options.replaceSkillGroup}" (skills get new ids; datasources and workflows are skipped)
|
|
6327
|
+
`
|
|
6328
|
+
);
|
|
6329
|
+
}
|
|
5345
6330
|
const { changes, summary } = await previewChanges(appConfig, client, {
|
|
5346
|
-
skipDatasources: options.skipDatasources
|
|
6331
|
+
skipDatasources: options.skipDatasources,
|
|
6332
|
+
replaceSkillGroup: options.replaceSkillGroup
|
|
5347
6333
|
});
|
|
5348
6334
|
logPreviewSummary(changes, summary);
|
|
5349
6335
|
process.exit(0);
|
|
@@ -5431,10 +6417,10 @@ var DependencyValidator = class {
|
|
|
5431
6417
|
const errors = [];
|
|
5432
6418
|
const visited = /* @__PURE__ */ new Set();
|
|
5433
6419
|
const recursionStack = /* @__PURE__ */ new Set();
|
|
5434
|
-
const dfs = (name,
|
|
6420
|
+
const dfs = (name, path19) => {
|
|
5435
6421
|
if (recursionStack.has(name)) {
|
|
5436
|
-
const cycleStart =
|
|
5437
|
-
const cycle = [...
|
|
6422
|
+
const cycleStart = path19.indexOf(name);
|
|
6423
|
+
const cycle = [...path19.slice(cycleStart), name];
|
|
5438
6424
|
errors.push(`Cyclic dependency detected: ${cycle.join(" \u2192 ")}`);
|
|
5439
6425
|
return true;
|
|
5440
6426
|
}
|
|
@@ -5443,14 +6429,14 @@ var DependencyValidator = class {
|
|
|
5443
6429
|
}
|
|
5444
6430
|
visited.add(name);
|
|
5445
6431
|
recursionStack.add(name);
|
|
5446
|
-
|
|
6432
|
+
path19.push(name);
|
|
5447
6433
|
const assistant = assistantMap.get(name);
|
|
5448
6434
|
const subAssistantRefs = assistant?.sub_assistants || [];
|
|
5449
6435
|
for (const subRef of subAssistantRefs) {
|
|
5450
6436
|
if (!assistantMap.has(subRef)) {
|
|
5451
6437
|
continue;
|
|
5452
6438
|
}
|
|
5453
|
-
if (dfs(subRef, [...
|
|
6439
|
+
if (dfs(subRef, [...path19])) {
|
|
5454
6440
|
return true;
|
|
5455
6441
|
}
|
|
5456
6442
|
}
|
|
@@ -5509,7 +6495,7 @@ var DependencyValidator = class {
|
|
|
5509
6495
|
}
|
|
5510
6496
|
for (const workflow of workflows) {
|
|
5511
6497
|
try {
|
|
5512
|
-
const workflowYaml =
|
|
6498
|
+
const workflowYaml = yaml7.parse(workflow.definition);
|
|
5513
6499
|
if (!workflowYaml.assistants) {
|
|
5514
6500
|
continue;
|
|
5515
6501
|
}
|
|
@@ -5561,71 +6547,6 @@ var DependencyValidator = class {
|
|
|
5561
6547
|
|
|
5562
6548
|
// src/validate.ts
|
|
5563
6549
|
init_logger();
|
|
5564
|
-
|
|
5565
|
-
// src/lib/validationUtils.ts
|
|
5566
|
-
function isAssistantWithSlug(obj) {
|
|
5567
|
-
return typeof obj === "object" && obj !== null && "slug" in obj && "name" in obj && typeof obj.slug === "string" && typeof obj.name === "string";
|
|
5568
|
-
}
|
|
5569
|
-
function isAssistant(obj) {
|
|
5570
|
-
return typeof obj === "object" && obj !== null && "id" in obj && "slug" in obj;
|
|
5571
|
-
}
|
|
5572
|
-
function validateSlugUniqueness(config) {
|
|
5573
|
-
const slugErrors = [];
|
|
5574
|
-
const slugMap = /* @__PURE__ */ new Map();
|
|
5575
|
-
if (config.resources.assistants) {
|
|
5576
|
-
for (const assistant of config.resources.assistants) {
|
|
5577
|
-
if (assistant.slug) {
|
|
5578
|
-
if (!slugMap.has(assistant.slug)) {
|
|
5579
|
-
slugMap.set(assistant.slug, []);
|
|
5580
|
-
}
|
|
5581
|
-
slugMap.get(assistant.slug).push(assistant.name);
|
|
5582
|
-
}
|
|
5583
|
-
}
|
|
5584
|
-
}
|
|
5585
|
-
for (const [slug, names] of slugMap.entries()) {
|
|
5586
|
-
if (names.length > 1) {
|
|
5587
|
-
slugErrors.push(`Duplicate slug "${slug}" for assistants: ${names.join(", ")}`);
|
|
5588
|
-
}
|
|
5589
|
-
}
|
|
5590
|
-
return slugErrors;
|
|
5591
|
-
}
|
|
5592
|
-
async function checkApiSlugConflicts({
|
|
5593
|
-
config,
|
|
5594
|
-
client,
|
|
5595
|
-
assistantState
|
|
5596
|
-
}) {
|
|
5597
|
-
const existingAssistants = await client.assistants.list({
|
|
5598
|
-
minimal_response: false,
|
|
5599
|
-
per_page: 100
|
|
5600
|
-
});
|
|
5601
|
-
const existingSlugs = /* @__PURE__ */ new Map();
|
|
5602
|
-
for (const assistant of existingAssistants) {
|
|
5603
|
-
if (isAssistantWithSlug(assistant) && assistant.slug) {
|
|
5604
|
-
existingSlugs.set(assistant.slug, assistant.name);
|
|
5605
|
-
}
|
|
5606
|
-
}
|
|
5607
|
-
const conflictErrors = [];
|
|
5608
|
-
const iacAssistantNames = new Set(Object.keys(assistantState));
|
|
5609
|
-
if (config.resources.assistants) {
|
|
5610
|
-
for (const assistant of config.resources.assistants) {
|
|
5611
|
-
if (!assistant.slug || iacAssistantNames.has(assistant.name)) {
|
|
5612
|
-
continue;
|
|
5613
|
-
}
|
|
5614
|
-
if (existingSlugs.has(assistant.slug)) {
|
|
5615
|
-
const existingName = existingSlugs.get(assistant.slug);
|
|
5616
|
-
const existingAssistant = existingAssistants.find((a) => isAssistant(a) && a.slug === assistant.slug);
|
|
5617
|
-
conflictErrors.push(
|
|
5618
|
-
`\u274C Slug "${assistant.slug}" for assistant "${assistant.name}" already exists in Codemie
|
|
5619
|
-
Existing assistant: "${existingName}" (ID: ${isAssistant(existingAssistant) ? existingAssistant.id : "unknown"})
|
|
5620
|
-
\u{1F4A1} Change slug to a unique value or omit slug (platform will generate)`
|
|
5621
|
-
);
|
|
5622
|
-
}
|
|
5623
|
-
}
|
|
5624
|
-
}
|
|
5625
|
-
return conflictErrors;
|
|
5626
|
-
}
|
|
5627
|
-
|
|
5628
|
-
// src/validate.ts
|
|
5629
6550
|
async function validateConfig(options) {
|
|
5630
6551
|
const errors = [];
|
|
5631
6552
|
const { checkApi = false, appConfig } = options;
|
|
@@ -5649,12 +6570,12 @@ async function validateConfig(options) {
|
|
|
5649
6570
|
}
|
|
5650
6571
|
if (config.resources.workflows && config.resources.workflows.length > 0) {
|
|
5651
6572
|
const workflowsWithContent = config.resources.workflows.map((workflow) => {
|
|
5652
|
-
const workflowPath =
|
|
5653
|
-
if (!
|
|
6573
|
+
const workflowPath = path13.resolve(workflow.definition);
|
|
6574
|
+
if (!fs13.existsSync(workflowPath)) {
|
|
5654
6575
|
errors.push(`Workflow definition file not found: ${workflow.definition}`);
|
|
5655
6576
|
return { ...workflow, definition: "" };
|
|
5656
6577
|
}
|
|
5657
|
-
const definition =
|
|
6578
|
+
const definition = fs13.readFileSync(workflowPath, "utf8");
|
|
5658
6579
|
return { ...workflow, definition };
|
|
5659
6580
|
});
|
|
5660
6581
|
const workflowErrors = DependencyValidator.validateWorkflowAssistantReferences(
|
|
@@ -5670,6 +6591,16 @@ async function validateConfig(options) {
|
|
|
5670
6591
|
const state = stateManager.loadState();
|
|
5671
6592
|
const conflictErrors = await checkApiSlugConflicts({ config, client, assistantState: state.resources.assistants });
|
|
5672
6593
|
errors.push(...conflictErrors);
|
|
6594
|
+
const skills = config.resources.skills ?? [];
|
|
6595
|
+
if (skills.length > 0) {
|
|
6596
|
+
const limits = await client.skills.getConfig();
|
|
6597
|
+
const entries = skills.map((skill) => ({
|
|
6598
|
+
name: skill.name,
|
|
6599
|
+
content: loader.resolveSkillContent(skill)
|
|
6600
|
+
}));
|
|
6601
|
+
const contentLengthErrors = validateSkillContentLengths(entries, limits);
|
|
6602
|
+
errors.push(...contentLengthErrors);
|
|
6603
|
+
}
|
|
5673
6604
|
}
|
|
5674
6605
|
return { success: errors.length === 0, errors };
|
|
5675
6606
|
}
|
|
@@ -5719,61 +6650,86 @@ async function main7(options) {
|
|
|
5719
6650
|
// src/cli/index.ts
|
|
5720
6651
|
program.name("codemie").description("Infrastructure as Code for Codemie platform").version(package_default.version);
|
|
5721
6652
|
program.command("init").description("Initialize a new Codemie IaC project").option("-d, --root-dir <path>", "Project root directory (containing codemie.yaml)").action((options) => {
|
|
5722
|
-
const rootDir = options.rootDir ?
|
|
6653
|
+
const rootDir = options.rootDir ? path13__default.resolve(options.rootDir) : void 0;
|
|
5723
6654
|
const appConfig = loadAppConfig(void 0, rootDir ?? process.cwd());
|
|
5724
6655
|
void main5({ appConfig });
|
|
5725
6656
|
});
|
|
5726
|
-
program.command("deploy").description("Deploy resources to Codemie platform").option("-p, --prune", "Delete orphaned resources").option("--skip-datasources", "Skip the datasource stage entirely (no create/update/delete, no indexing)").option(
|
|
5727
|
-
|
|
5728
|
-
|
|
6657
|
+
program.command("deploy").description("Deploy resources to Codemie platform").option("-p, --prune", "Delete orphaned resources").option("--skip-datasources", "Skip the datasource stage entirely (no create/update/delete, no indexing)").option(
|
|
6658
|
+
"--replace-skill-group <group>",
|
|
6659
|
+
"Delete and recreate every skill labelled with this group (skills get new ids; datasources and workflows are skipped)"
|
|
6660
|
+
).option("--yes-replace-skills", "Confirm the destructive --replace-skill-group run").option("-d, --root-dir <path>", "Project root directory (containing codemie.yaml)").option("-c, --config <path>", "Configuration file").action(async (options) => {
|
|
6661
|
+
const configPath = options.config ? path13__default.resolve(options.config) : void 0;
|
|
6662
|
+
const rootDir = options.rootDir ? path13__default.resolve(options.rootDir) : void 0;
|
|
5729
6663
|
const appConfig = loadAppConfig(configPath, rootDir);
|
|
5730
6664
|
await runCommandWithSpinner(
|
|
5731
6665
|
"Deploying Codemie resources",
|
|
5732
|
-
() => main2({
|
|
6666
|
+
() => main2({
|
|
6667
|
+
appConfig,
|
|
6668
|
+
prune: options.prune,
|
|
6669
|
+
skipDatasources: options.skipDatasources,
|
|
6670
|
+
replaceSkillGroup: options.replaceSkillGroup,
|
|
6671
|
+
yesReplaceSkills: options.yesReplaceSkills
|
|
6672
|
+
})
|
|
5733
6673
|
);
|
|
5734
6674
|
});
|
|
5735
6675
|
program.command("backup").description("Backup all resources from Codemie platform").option("-d, --root-dir <path>", "Project root directory (containing codemie.yaml)").option("-c, --config <path>", "Configuration file").action(async (options) => {
|
|
5736
|
-
const configPath = options.config ?
|
|
5737
|
-
const rootDir = options.rootDir ?
|
|
6676
|
+
const configPath = options.config ? path13__default.resolve(options.config) : void 0;
|
|
6677
|
+
const rootDir = options.rootDir ? path13__default.resolve(options.rootDir) : void 0;
|
|
5738
6678
|
const appConfig = loadAppConfig(configPath, rootDir);
|
|
5739
6679
|
await runCommandWithSpinner("Backing up Codemie resources", () => main({ appConfig }));
|
|
5740
6680
|
});
|
|
5741
6681
|
program.command("destroy").description("Destroy all IaC-managed resources").option("-f, --force", "Skip confirmation prompt").option("-d, --root-dir <path>", "Project root directory (containing codemie.yaml)").option("-c, --config <path>", "Configuration file").action(async (options) => {
|
|
5742
|
-
const configPath = options.config ?
|
|
5743
|
-
const rootDir = options.rootDir ?
|
|
6682
|
+
const configPath = options.config ? path13__default.resolve(options.config) : void 0;
|
|
6683
|
+
const rootDir = options.rootDir ? path13__default.resolve(options.rootDir) : void 0;
|
|
5744
6684
|
const appConfig = loadAppConfig(configPath, rootDir);
|
|
5745
6685
|
await runCommandWithSpinner("Destroying Codemie resources", () => main3({ appConfig, force: options.force }));
|
|
5746
6686
|
});
|
|
5747
|
-
program.command("preview").description("Preview changes without applying them").option("--skip-datasources", "Exclude datasources from preview (mirrors deploy --skip-datasources)").option(
|
|
5748
|
-
|
|
5749
|
-
|
|
6687
|
+
program.command("preview").description("Preview changes without applying them").option("--skip-datasources", "Exclude datasources from preview (mirrors deploy --skip-datasources)").option(
|
|
6688
|
+
"--replace-skill-group <group>",
|
|
6689
|
+
"Preview the deletes and creates of deploy --replace-skill-group for this skill group"
|
|
6690
|
+
).option("-d, --root-dir <path>", "Project root directory (containing codemie.yaml)").option("-c, --config <path>", "Configuration file").action(async (options) => {
|
|
6691
|
+
const appConfigPath = options.config ? path13__default.resolve(options.config) : void 0;
|
|
6692
|
+
const rootDir = options.rootDir ? path13__default.resolve(options.rootDir) : void 0;
|
|
5750
6693
|
const appConfig = loadAppConfig(appConfigPath, rootDir);
|
|
5751
6694
|
await runCommandWithSpinner(
|
|
5752
6695
|
"Generating Codemie preview",
|
|
5753
|
-
() => main6({
|
|
6696
|
+
() => main6({
|
|
6697
|
+
appConfig,
|
|
6698
|
+
skipDatasources: options.skipDatasources,
|
|
6699
|
+
replaceSkillGroup: options.replaceSkillGroup
|
|
6700
|
+
})
|
|
5754
6701
|
);
|
|
5755
6702
|
});
|
|
5756
6703
|
program.command("validate").description("Validate configuration").option("-a, --check-api", "Check for API conflicts").option("-d, --root-dir <path>", "Project root directory (containing codemie.yaml)").option("-c, --config <path>", "Configuration file").action(async (options) => {
|
|
5757
|
-
const configPath = options.config ?
|
|
5758
|
-
const rootDir = options.rootDir ?
|
|
6704
|
+
const configPath = options.config ? path13__default.resolve(options.config) : void 0;
|
|
6705
|
+
const rootDir = options.rootDir ? path13__default.resolve(options.rootDir) : void 0;
|
|
5759
6706
|
const appConfig = loadAppConfig(configPath, rootDir);
|
|
5760
6707
|
await runCommandWithSpinner(
|
|
5761
6708
|
"Validating Codemie configuration",
|
|
5762
6709
|
() => main7({ appConfig, checkApi: options.checkApi })
|
|
5763
6710
|
);
|
|
5764
6711
|
});
|
|
5765
|
-
program.command("import").description("Import a single resource from the CodeMie platform into the local IaC configuration").argument("<type>", "Resource type: assistant, datasource, workflow, or skill").argument("<slug>", "Resource slug or name (a platform UUID also works for assistant and workflow)").option("-d, --root-dir <path>", "Project root directory (containing codemie.yaml)").option("-c, --config <path>", "Configuration file").option("-u, --update", "Refresh an already-managed resource in place instead of failing on a conflict").
|
|
6712
|
+
program.command("import").description("Import a single resource from the CodeMie platform into the local IaC configuration").argument("<type>", "Resource type: assistant, datasource, workflow, or skill").argument("<slug>", "Resource slug or name (a platform UUID also works for assistant and workflow)").option("-d, --root-dir <path>", "Project root directory (containing codemie.yaml)").option("-c, --config <path>", "Configuration file").option("-u, --update", "Refresh an already-managed resource in place instead of failing on a conflict").option(
|
|
6713
|
+
"--with-skills",
|
|
6714
|
+
"Assistants only: also import the project-owned skills it references that are not managed yet"
|
|
6715
|
+
).action(async (type, slug, options) => {
|
|
5766
6716
|
if (!VALID_RESOURCE_TYPES.includes(type)) {
|
|
5767
6717
|
logger.error(`\u274C Invalid resource type: "${type}". Must be one of: ${VALID_RESOURCE_TYPES.join(", ")}`);
|
|
5768
6718
|
process.exitCode = 1;
|
|
5769
6719
|
return;
|
|
5770
6720
|
}
|
|
5771
|
-
const configPath = options.config ?
|
|
5772
|
-
const rootDir = options.rootDir ?
|
|
6721
|
+
const configPath = options.config ? path13__default.resolve(options.config) : void 0;
|
|
6722
|
+
const rootDir = options.rootDir ? path13__default.resolve(options.rootDir) : void 0;
|
|
5773
6723
|
const appConfig = loadAppConfig(configPath, rootDir);
|
|
5774
6724
|
await runCommandWithSpinner(
|
|
5775
6725
|
`Importing ${type}`,
|
|
5776
|
-
() => main4({
|
|
6726
|
+
() => main4({
|
|
6727
|
+
appConfig,
|
|
6728
|
+
resourceType: type,
|
|
6729
|
+
slug,
|
|
6730
|
+
update: options.update,
|
|
6731
|
+
withSkills: options.withSkills
|
|
6732
|
+
})
|
|
5777
6733
|
);
|
|
5778
6734
|
});
|
|
5779
6735
|
program.parse();
|