teamcopilot 0.0.1
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/.env.example +10 -0
- package/LICENSE.md +21 -0
- package/README.md +131 -0
- package/bin/teamcopilot.js +281 -0
- package/dist/auth/index.js +189 -0
- package/dist/change-user-role.js +77 -0
- package/dist/chat/index.js +849 -0
- package/dist/constants.js +2 -0
- package/dist/create-user.js +98 -0
- package/dist/cronjob/index.js +16 -0
- package/dist/cronjob/resource-reconciliation.js +33 -0
- package/dist/delete-user.js +66 -0
- package/dist/frontend/assets/abap-CRCWOmpq.js +1 -0
- package/dist/frontend/assets/apex-DnsZk_dE.js +1 -0
- package/dist/frontend/assets/azcli-1IWB1ccx.js +1 -0
- package/dist/frontend/assets/bat-DPkNLes8.js +1 -0
- package/dist/frontend/assets/bicep-Corcdgou.js +2 -0
- package/dist/frontend/assets/cameligo-CGrWLZr3.js +1 -0
- package/dist/frontend/assets/clojure-D9WOWImG.js +1 -0
- package/dist/frontend/assets/codicon-DCmgc-ay.ttf +0 -0
- package/dist/frontend/assets/coffee-B7EJu28W.js +1 -0
- package/dist/frontend/assets/cpp-SEyurbux.js +1 -0
- package/dist/frontend/assets/csharp-BoL64M5l.js +1 -0
- package/dist/frontend/assets/csp-C46ZqvIl.js +1 -0
- package/dist/frontend/assets/css-DQU6DXDx.js +3 -0
- package/dist/frontend/assets/cssMode-BDT3WbVs.js +4 -0
- package/dist/frontend/assets/cypher-D84EuPTj.js +1 -0
- package/dist/frontend/assets/dart-D8lhlL1r.js +1 -0
- package/dist/frontend/assets/dockerfile-DLk6rpji.js +1 -0
- package/dist/frontend/assets/ecl-BO6FnfXk.js +1 -0
- package/dist/frontend/assets/editor.worker-B4pQIWZD.js +12 -0
- package/dist/frontend/assets/elixir-BRjLKONM.js +1 -0
- package/dist/frontend/assets/flow9-Cac8vKd7.js +1 -0
- package/dist/frontend/assets/freemarker2-C7-hEgID.js +3 -0
- package/dist/frontend/assets/fsharp-fd1GTHhf.js +1 -0
- package/dist/frontend/assets/go-O9LJTZXk.js +1 -0
- package/dist/frontend/assets/graphql-LQdxqEYJ.js +1 -0
- package/dist/frontend/assets/handlebars-4cwTkPir.js +1 -0
- package/dist/frontend/assets/hcl-DxDQ3s82.js +1 -0
- package/dist/frontend/assets/html-YNfE1Q0A.js +1 -0
- package/dist/frontend/assets/htmlMode-opTQ1HoB.js +4 -0
- package/dist/frontend/assets/index-DWyaVa1h.js +782 -0
- package/dist/frontend/assets/index-lXrsgeTF.css +1 -0
- package/dist/frontend/assets/ini-BvajGCUy.js +1 -0
- package/dist/frontend/assets/java-SYsfObOQ.js +1 -0
- package/dist/frontend/assets/javascript-BEwGzk7T.js +1 -0
- package/dist/frontend/assets/jsonMode-CGhIS5Al.js +10 -0
- package/dist/frontend/assets/julia-DQXNmw_w.js +1 -0
- package/dist/frontend/assets/kotlin-qQ0MG-9I.js +1 -0
- package/dist/frontend/assets/less-GGFNNJHn.js +2 -0
- package/dist/frontend/assets/lexon-Canl7DCW.js +1 -0
- package/dist/frontend/assets/liquid-QekTGCGJ.js +1 -0
- package/dist/frontend/assets/lua-D28Ae8-K.js +1 -0
- package/dist/frontend/assets/m3-DPitgjJI.js +1 -0
- package/dist/frontend/assets/markdown-B811l8j2.js +1 -0
- package/dist/frontend/assets/mdx-BAVDaB7v.js +1 -0
- package/dist/frontend/assets/mips-CdjsipkG.js +1 -0
- package/dist/frontend/assets/msdax-CYqgjx_P.js +1 -0
- package/dist/frontend/assets/mysql-BHd6q0vd.js +1 -0
- package/dist/frontend/assets/objective-c-B1aVtJYH.js +1 -0
- package/dist/frontend/assets/pascal-BhNW15KB.js +1 -0
- package/dist/frontend/assets/pascaligo-5jv8CcQD.js +1 -0
- package/dist/frontend/assets/perl-DlYyT36c.js +1 -0
- package/dist/frontend/assets/pgsql-Dy0bjov7.js +1 -0
- package/dist/frontend/assets/php-120yhfDK.js +1 -0
- package/dist/frontend/assets/pla-CjnFlu4u.js +1 -0
- package/dist/frontend/assets/postiats-CQpG440k.js +1 -0
- package/dist/frontend/assets/powerquery-DdJtto1Z.js +1 -0
- package/dist/frontend/assets/powershell-Bu_VLpJB.js +1 -0
- package/dist/frontend/assets/protobuf-IBS6jZEB.js +2 -0
- package/dist/frontend/assets/pug-kFxLfcjb.js +1 -0
- package/dist/frontend/assets/python-BQlHw7XO.js +1 -0
- package/dist/frontend/assets/qsharp-q7JyzKFN.js +1 -0
- package/dist/frontend/assets/r-BIFz-_sK.js +1 -0
- package/dist/frontend/assets/razor-Be3Wwc2E.js +1 -0
- package/dist/frontend/assets/redis-CHOsPHWR.js +1 -0
- package/dist/frontend/assets/redshift-CBifECDb.js +1 -0
- package/dist/frontend/assets/restructuredtext-CghPJEOS.js +1 -0
- package/dist/frontend/assets/ruby-CYWGW-b1.js +1 -0
- package/dist/frontend/assets/rust-DMDD0SHb.js +1 -0
- package/dist/frontend/assets/sb-BYAiYHFx.js +1 -0
- package/dist/frontend/assets/scala-Bqvq8jcR.js +1 -0
- package/dist/frontend/assets/scheme-Dhb-2j9p.js +1 -0
- package/dist/frontend/assets/scss-CTwUZ5N7.js +3 -0
- package/dist/frontend/assets/shell-CsDZo4DB.js +1 -0
- package/dist/frontend/assets/solidity-CME5AdoB.js +1 -0
- package/dist/frontend/assets/sophia-RYC1BQQz.js +1 -0
- package/dist/frontend/assets/sparql-KEyrF7De.js +1 -0
- package/dist/frontend/assets/sql-BdTr02Mf.js +1 -0
- package/dist/frontend/assets/st-C7iG7M4S.js +1 -0
- package/dist/frontend/assets/swift-D7IUmUK8.js +1 -0
- package/dist/frontend/assets/systemverilog-DgMryOEJ.js +1 -0
- package/dist/frontend/assets/tcl-PloMZuKG.js +1 -0
- package/dist/frontend/assets/tsMode-CIBFoN3z.js +11 -0
- package/dist/frontend/assets/twig-BfRIq3la.js +1 -0
- package/dist/frontend/assets/typescript-BuV9wEIE.js +1 -0
- package/dist/frontend/assets/typespec-CzxlYoT_.js +1 -0
- package/dist/frontend/assets/vb-BwAE3J76.js +1 -0
- package/dist/frontend/assets/wgsl-B_1kOXbF.js +298 -0
- package/dist/frontend/assets/xml-DcDKYaM4.js +1 -0
- package/dist/frontend/assets/yaml-CuBNmOuI.js +1 -0
- package/dist/frontend/index.html +14 -0
- package/dist/frontend/logo.svg +50 -0
- package/dist/index.js +169 -0
- package/dist/logging.js +30 -0
- package/dist/opencode-auth/index.js +122 -0
- package/dist/opencode-server.js +91 -0
- package/dist/prisma/client.js +38 -0
- package/dist/reset-password.js +73 -0
- package/dist/rotate-jwt-secret.js +20 -0
- package/dist/scripts/prisma-workspace.js +34 -0
- package/dist/skills/index.js +311 -0
- package/dist/types/permissions.js +2 -0
- package/dist/types/shared/permissions.js +17 -0
- package/dist/types/shared/skill.js +17 -0
- package/dist/types/shared/workflow-files.js +17 -0
- package/dist/types/shared/workflow.js +17 -0
- package/dist/types/skill.js +2 -0
- package/dist/types/workflow-files.js +2 -0
- package/dist/types/workflow.js +2 -0
- package/dist/users/index.js +22 -0
- package/dist/utils/approval-snapshot-common.js +596 -0
- package/dist/utils/assert.js +20 -0
- package/dist/utils/chat-session.js +44 -0
- package/dist/utils/cli-bootstrap.js +26 -0
- package/dist/utils/index.js +95 -0
- package/dist/utils/jwt-secret.js +63 -0
- package/dist/utils/opencode-auth.js +126 -0
- package/dist/utils/opencode-client.js +109 -0
- package/dist/utils/password-policy.js +12 -0
- package/dist/utils/permission-common.js +280 -0
- package/dist/utils/redact.js +108 -0
- package/dist/utils/resource-access.js +37 -0
- package/dist/utils/resource-file-routes.js +115 -0
- package/dist/utils/resource-files.js +572 -0
- package/dist/utils/runtime-paths.js +61 -0
- package/dist/utils/session-abort.js +52 -0
- package/dist/utils/skill-approval-snapshot.js +39 -0
- package/dist/utils/skill-files.js +17 -0
- package/dist/utils/skill-permissions.js +15 -0
- package/dist/utils/skill.js +217 -0
- package/dist/utils/user-role.js +14 -0
- package/dist/utils/workflow-approval-snapshot.js +38 -0
- package/dist/utils/workflow-files.js +17 -0
- package/dist/utils/workflow-interruption.js +50 -0
- package/dist/utils/workflow-permissions.js +27 -0
- package/dist/utils/workflow-runner.js +414 -0
- package/dist/utils/workflow.js +158 -0
- package/dist/utils/workspace-sync.js +204 -0
- package/dist/workflows/index.js +751 -0
- package/dist/workspace_files/.opencode/opencode.json +17 -0
- package/dist/workspace_files/.opencode/package.json +14 -0
- package/dist/workspace_files/.opencode/plugins/createSkill.ts +339 -0
- package/dist/workspace_files/.opencode/plugins/createWorkflow.ts +345 -0
- package/dist/workspace_files/.opencode/plugins/findSimilarWorkflow.ts +173 -0
- package/dist/workspace_files/.opencode/plugins/findSkill.ts +211 -0
- package/dist/workspace_files/.opencode/plugins/getSkillContent.ts +135 -0
- package/dist/workspace_files/.opencode/plugins/honeytoken-protection.ts +64 -0
- package/dist/workspace_files/.opencode/plugins/listAvailableSkills.ts +93 -0
- package/dist/workspace_files/.opencode/plugins/listAvailableWorkflows.ts +93 -0
- package/dist/workspace_files/.opencode/plugins/python-protection.ts +184 -0
- package/dist/workspace_files/.opencode/plugins/runWorkflow.ts +168 -0
- package/dist/workspace_files/.opencode/tsconfig.json +16 -0
- package/dist/workspace_files/AGENTS.md +483 -0
- package/dist/workspace_files/package-lock.json +167 -0
- package/dist/workspace_files/package.json +5 -0
- package/package.json +86 -0
- package/prisma/migrations/20260203040755_init/migration.sql +20 -0
- package/prisma/migrations/20260204034845_replace_google_auth_with_email_password/migration.sql +25 -0
- package/prisma/migrations/20260207022226_add_user_role/migration.sql +25 -0
- package/prisma/migrations/20260210161254_add_workflow_runs/migration.sql +16 -0
- package/prisma/migrations/20260211050606_adds_workflow_table/migration.sql +40 -0
- package/prisma/migrations/20260211050750_adds_fkey_constraint/migration.sql +21 -0
- package/prisma/migrations/20260211051912_removes_workflow_table/migration.sql +34 -0
- package/prisma/migrations/20260211052238_changes_workflow_id_to_slug/migration.sql +27 -0
- package/prisma/migrations/20260212051912_add_output_to_workflow_runs/migration.sql +2 -0
- package/prisma/migrations/20260213073006_add_chat_sessions/migration.sql +13 -0
- package/prisma/migrations/20260216053202_add_chat_sessions_opencode_session_id_idx/migration.sql +2 -0
- package/prisma/migrations/20260216053237_drop_redundant_chat_sessions_opencode_idx/migration.sql +2 -0
- package/prisma/migrations/20260219060705_makes/migration.sql +24 -0
- package/prisma/migrations/20260222040542_add_workflow_execution_permissions/migration.sql +18 -0
- package/prisma/migrations/20260222040815_remove_workflow_execution_permissions/migration.sql +10 -0
- package/prisma/migrations/20260222041348_add_workflow_execution_permissions_final/migration.sql +17 -0
- package/prisma/migrations/20260222041741_rename_to_tool_execution_permissions/migration.sql +30 -0
- package/prisma/migrations/20260222041826_simplify_tool_execution_permissions/migration.sql +29 -0
- package/prisma/migrations/20260222041950_add_fields_for_standalone_permissions/migration.sql +32 -0
- package/prisma/migrations/20260222042954_simplify_tool_permissions_table/migration.sql +27 -0
- package/prisma/migrations/20260223073902_add_workflow_run_permissions_tables/migration.sql +23 -0
- package/prisma/migrations/20260225025151_add_workflow_metadata/migration.sql +16 -0
- package/prisma/migrations/20260225031035_merge_workflow_permissions_into_metadata/migration.sql +44 -0
- package/prisma/migrations/20260225031752_removes_default_for_run_permission_mode/migration.sql +20 -0
- package/prisma/migrations/20260225033603_remove_workflow_metadata_user_fkeys/migration.sql +18 -0
- package/prisma/migrations/20260225043032_restore_workflow_metadata_user_fkeys/migration.sql +20 -0
- package/prisma/migrations/20260225091423_add_workflow_approved_snapshots/migration.sql +28 -0
- package/prisma/migrations/20260226032121_add_is_approved_to_workflow_metadata/migration.sql +21 -0
- package/prisma/migrations/20260226032444_undoes_last_db_change/migration.sql +26 -0
- package/prisma/migrations/20260227120000_remove_snapshot_hash_from_approved_snapshots/migration.sql +16 -0
- package/prisma/migrations/20260228071125_adds_workspace_path_to_snapshot_table/migration.sql +22 -0
- package/prisma/migrations/20260228071217_modifies_index_and_removes_default_value/migration.sql +22 -0
- package/prisma/migrations/20260228071710_undoes_previous/migration.sql +27 -0
- package/prisma/migrations/20260228105022_add_must_change_password_first_login/migration.sql +20 -0
- package/prisma/migrations/20260301115439_add_workflow_run_log_refs/migration.sql +8 -0
- package/prisma/migrations/20260301122557_add_workflow_aborted_sessions/migration.sql +5 -0
- package/prisma/migrations/20260302045545_move_workflow_run_log_refs_into_workflow_runs/migration.sql +17 -0
- package/prisma/migrations/20260303040318_add_skill_tables/migration.sql +61 -0
- package/prisma/migrations/20260303051533_unify_resource_permissions/migration.sql +97 -0
- package/prisma/migrations/20260303064255_unify_resource_metadata_and_snapshots/migration.sql +179 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +147 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectCurrentSkillSnapshot = collectCurrentSkillSnapshot;
|
|
4
|
+
exports.loadApprovedSkillSnapshotFromDb = loadApprovedSkillSnapshotFromDb;
|
|
5
|
+
exports.approveSkillWithSnapshot = approveSkillWithSnapshot;
|
|
6
|
+
exports.buildSkillApprovalDiffResponse = buildSkillApprovalDiffResponse;
|
|
7
|
+
exports.getSkillSnapshotApprovalState = getSkillSnapshotApprovalState;
|
|
8
|
+
exports.restoreSkillToApprovedSnapshot = restoreSkillToApprovedSnapshot;
|
|
9
|
+
const skill_1 = require("./skill");
|
|
10
|
+
const approval_snapshot_common_1 = require("./approval-snapshot-common");
|
|
11
|
+
function getSkillSnapshotConfig(slug) {
|
|
12
|
+
return {
|
|
13
|
+
resource_kind: "skill",
|
|
14
|
+
slug,
|
|
15
|
+
resource_label: "skill",
|
|
16
|
+
root_path: (0, skill_1.getSkillPath)(slug),
|
|
17
|
+
ensure_resource_exists: async () => {
|
|
18
|
+
await (0, skill_1.readSkillManifestAndEnsurePermissions)(slug);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function collectCurrentSkillSnapshot(slug) {
|
|
23
|
+
return (0, approval_snapshot_common_1.collectCurrentResourceSnapshot)(getSkillSnapshotConfig(slug));
|
|
24
|
+
}
|
|
25
|
+
async function loadApprovedSkillSnapshotFromDb(slug) {
|
|
26
|
+
return (0, approval_snapshot_common_1.loadApprovedSnapshotFromDb)("skill", slug);
|
|
27
|
+
}
|
|
28
|
+
async function approveSkillWithSnapshot(slug, userId) {
|
|
29
|
+
return (0, approval_snapshot_common_1.approveResourceWithSnapshot)(getSkillSnapshotConfig(slug), userId);
|
|
30
|
+
}
|
|
31
|
+
function buildSkillApprovalDiffResponse(previous, current) {
|
|
32
|
+
return (0, approval_snapshot_common_1.buildApprovalDiffResponse)(previous, current);
|
|
33
|
+
}
|
|
34
|
+
async function getSkillSnapshotApprovalState(slug) {
|
|
35
|
+
return (0, approval_snapshot_common_1.getResourceSnapshotApprovalState)(getSkillSnapshotConfig(slug));
|
|
36
|
+
}
|
|
37
|
+
async function restoreSkillToApprovedSnapshot(slug, userId) {
|
|
38
|
+
return (0, approval_snapshot_common_1.restoreResourceToApprovedSnapshot)(getSkillSnapshotConfig(slug), userId);
|
|
39
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteSkillPath = exports.renameSkillPath = exports.uploadSkillFileFromTempPath = exports.createSkillFileOrFolder = exports.saveSkillFileContent = exports.readSkillFileContent = exports.listSkillDirectory = void 0;
|
|
4
|
+
const resource_files_1 = require("./resource-files");
|
|
5
|
+
const skill_1 = require("./skill");
|
|
6
|
+
const skillFileManager = (0, resource_files_1.createResourceFileManager)({
|
|
7
|
+
getResourcePath: skill_1.getSkillPath,
|
|
8
|
+
resourceLabel: "skill",
|
|
9
|
+
editorLabel: "Skill",
|
|
10
|
+
});
|
|
11
|
+
exports.listSkillDirectory = skillFileManager.listDirectory;
|
|
12
|
+
exports.readSkillFileContent = skillFileManager.readFileContent;
|
|
13
|
+
exports.saveSkillFileContent = skillFileManager.saveFileContent;
|
|
14
|
+
exports.createSkillFileOrFolder = skillFileManager.createFileOrFolder;
|
|
15
|
+
exports.uploadSkillFileFromTempPath = skillFileManager.uploadFileFromTempPath;
|
|
16
|
+
exports.renameSkillPath = skillFileManager.renamePath;
|
|
17
|
+
exports.deleteSkillPath = skillFileManager.deletePath;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSkillAccessPermissionWithUsers = getSkillAccessPermissionWithUsers;
|
|
4
|
+
exports.setSkillAccessPermissions = setSkillAccessPermissions;
|
|
5
|
+
exports.addApproverToSkillAccessPermissionsIfRestricted = addApproverToSkillAccessPermissionsIfRestricted;
|
|
6
|
+
const permission_common_1 = require("./permission-common");
|
|
7
|
+
async function getSkillAccessPermissionWithUsers(slug) {
|
|
8
|
+
return (0, permission_common_1.getResourcePermissionWithUsers)("skill", slug, "Skill access");
|
|
9
|
+
}
|
|
10
|
+
async function setSkillAccessPermissions(slug, payload, ownerUserId) {
|
|
11
|
+
return (0, permission_common_1.setResourcePermissions)("skill", slug, payload, ownerUserId);
|
|
12
|
+
}
|
|
13
|
+
async function addApproverToSkillAccessPermissionsIfRestricted(slug, approverUserId, ownerUserId) {
|
|
14
|
+
await (0, permission_common_1.addUserToResourcePermissionsIfRestricted)("skill", slug, approverUserId, ownerUserId);
|
|
15
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getSkillPath = getSkillPath;
|
|
7
|
+
exports.deleteSkill = deleteSkill;
|
|
8
|
+
exports.listSkillSlugs = listSkillSlugs;
|
|
9
|
+
exports.createSkill = createSkill;
|
|
10
|
+
exports.getOrCreateSkillMetadataAndEnsurePermission = getOrCreateSkillMetadataAndEnsurePermission;
|
|
11
|
+
exports.readSkillManifestAndEnsurePermissions = readSkillManifestAndEnsurePermissions;
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const client_1 = __importDefault(require("../prisma/client"));
|
|
15
|
+
const workspace_sync_1 = require("./workspace-sync");
|
|
16
|
+
const permission_common_1 = require("./permission-common");
|
|
17
|
+
function getSkillsRootPath() {
|
|
18
|
+
return path_1.default.join((0, workspace_sync_1.getWorkspaceDirFromEnv)(), "custom-skills");
|
|
19
|
+
}
|
|
20
|
+
function getSkillPath(slug) {
|
|
21
|
+
return path_1.default.join(getSkillsRootPath(), slug);
|
|
22
|
+
}
|
|
23
|
+
function deleteSkillDirectory(slug) {
|
|
24
|
+
const skillPath = getSkillPath(slug);
|
|
25
|
+
if (!fs_1.default.existsSync(skillPath)) {
|
|
26
|
+
throw {
|
|
27
|
+
status: 404,
|
|
28
|
+
message: `Skill not found for slug: ${slug}`
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
fs_1.default.rmSync(skillPath, { recursive: true, force: false });
|
|
32
|
+
}
|
|
33
|
+
async function deleteSkill(slug) {
|
|
34
|
+
await client_1.default.resource_metadata.deleteMany({
|
|
35
|
+
where: {
|
|
36
|
+
resource_kind: "skill",
|
|
37
|
+
resource_slug: slug
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
await client_1.default.resource_permissions.deleteMany({
|
|
41
|
+
where: {
|
|
42
|
+
resource_kind: "skill",
|
|
43
|
+
resource_slug: slug
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (fs_1.default.existsSync(getSkillPath(slug))) {
|
|
47
|
+
deleteSkillDirectory(slug);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function getSkillManifestPath(slug) {
|
|
51
|
+
return path_1.default.join(getSkillPath(slug), "SKILL.md");
|
|
52
|
+
}
|
|
53
|
+
function assertSkillSlug(slug) {
|
|
54
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)) {
|
|
55
|
+
throw {
|
|
56
|
+
status: 400,
|
|
57
|
+
message: "Invalid skill slug. Expected lowercase letters/numbers with optional hyphens."
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function listSkillSlugs() {
|
|
62
|
+
const skillsDir = getSkillsRootPath();
|
|
63
|
+
if (!fs_1.default.existsSync(skillsDir)) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const entries = fs_1.default.readdirSync(skillsDir, { withFileTypes: true });
|
|
67
|
+
const slugs = [];
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
if (!entry.isDirectory())
|
|
70
|
+
continue;
|
|
71
|
+
const canonicalManifestPath = path_1.default.join(skillsDir, entry.name, "SKILL.md");
|
|
72
|
+
if (fs_1.default.existsSync(canonicalManifestPath)) {
|
|
73
|
+
slugs.push(entry.name);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return slugs;
|
|
77
|
+
}
|
|
78
|
+
function extractFrontmatterValue(frontmatter, key) {
|
|
79
|
+
const pattern = new RegExp(`^${key}\\s*:\\s*(.+)$`, "m");
|
|
80
|
+
const match = frontmatter.match(pattern);
|
|
81
|
+
if (!match) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return match[1]?.trim().replace(/^["']|["']$/g, "") ?? null;
|
|
85
|
+
}
|
|
86
|
+
function readSkillManifest(slug) {
|
|
87
|
+
const skillManifestPath = getSkillManifestPath(slug);
|
|
88
|
+
if (!fs_1.default.existsSync(skillManifestPath)) {
|
|
89
|
+
throw {
|
|
90
|
+
status: 404,
|
|
91
|
+
message: `Skill manifest not found for slug: ${slug}`
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const content = fs_1.default.readFileSync(skillManifestPath, "utf-8");
|
|
95
|
+
const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---\s*/);
|
|
96
|
+
const frontmatter = frontmatterMatch?.[1] ?? "";
|
|
97
|
+
const name = extractFrontmatterValue(frontmatter, "name") ?? slug;
|
|
98
|
+
const description = extractFrontmatterValue(frontmatter, "description") ?? "";
|
|
99
|
+
return {
|
|
100
|
+
name,
|
|
101
|
+
description,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function toSkillFrontmatterValue(value) {
|
|
105
|
+
return JSON.stringify(value.trim());
|
|
106
|
+
}
|
|
107
|
+
async function createSkill(input) {
|
|
108
|
+
const slug = input.slug.trim();
|
|
109
|
+
const name = input.slug.trim();
|
|
110
|
+
assertSkillSlug(slug);
|
|
111
|
+
if (!name) {
|
|
112
|
+
throw {
|
|
113
|
+
status: 400,
|
|
114
|
+
message: "Skill name is required"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (name !== slug) {
|
|
118
|
+
throw {
|
|
119
|
+
status: 400,
|
|
120
|
+
message: "Skill name and slug must be the same value"
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const existingMetadata = await client_1.default.resource_metadata.findUnique({
|
|
124
|
+
where: {
|
|
125
|
+
resource_kind_resource_slug: {
|
|
126
|
+
resource_kind: "skill",
|
|
127
|
+
resource_slug: slug
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
select: { resource_slug: true }
|
|
131
|
+
});
|
|
132
|
+
if (existingMetadata) {
|
|
133
|
+
throw {
|
|
134
|
+
status: 409,
|
|
135
|
+
message: `Skill with slug "${slug}" already exists`
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const skillPath = getSkillPath(slug);
|
|
139
|
+
if (fs_1.default.existsSync(skillPath)) {
|
|
140
|
+
throw {
|
|
141
|
+
status: 409,
|
|
142
|
+
message: `Skill with slug "${slug}" already exists`
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
fs_1.default.mkdirSync(skillPath, { recursive: false });
|
|
146
|
+
const skillMdPath = getSkillManifestPath(slug);
|
|
147
|
+
const body = `---\nname: ${toSkillFrontmatterValue(name)}\ndescription: ${toSkillFrontmatterValue("")}\n---\n\n# ${name}\n\nDescribe what this skill does.\n\n## Instructions\n\nAdd detailed, actionable instructions for the agent here.\n`;
|
|
148
|
+
fs_1.default.writeFileSync(skillMdPath, body, "utf-8");
|
|
149
|
+
const now = BigInt(Date.now());
|
|
150
|
+
await client_1.default.$transaction(async (tx) => {
|
|
151
|
+
await tx.resource_metadata.create({
|
|
152
|
+
data: {
|
|
153
|
+
resource_kind: "skill",
|
|
154
|
+
resource_slug: slug,
|
|
155
|
+
created_by_user_id: input.createdByUserId,
|
|
156
|
+
approved_by_user_id: null,
|
|
157
|
+
created_at: now,
|
|
158
|
+
updated_at: now,
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
await tx.resource_permissions.create({
|
|
162
|
+
data: {
|
|
163
|
+
resource_kind: "skill",
|
|
164
|
+
resource_slug: slug,
|
|
165
|
+
permission_mode: "restricted",
|
|
166
|
+
created_at: now,
|
|
167
|
+
updated_at: now,
|
|
168
|
+
allowedUsers: {
|
|
169
|
+
create: {
|
|
170
|
+
user_id: input.createdByUserId,
|
|
171
|
+
created_at: now
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async function getOrCreateSkillMetadataAndEnsurePermission(slug) {
|
|
179
|
+
readSkillManifest(slug);
|
|
180
|
+
const existing = await client_1.default.resource_metadata.findUnique({
|
|
181
|
+
where: {
|
|
182
|
+
resource_kind_resource_slug: {
|
|
183
|
+
resource_kind: "skill",
|
|
184
|
+
resource_slug: slug
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
if (existing) {
|
|
189
|
+
const metadata = {
|
|
190
|
+
skill_slug: existing.resource_slug,
|
|
191
|
+
created_by_user_id: existing.created_by_user_id,
|
|
192
|
+
approved_by_user_id: existing.approved_by_user_id,
|
|
193
|
+
};
|
|
194
|
+
await (0, permission_common_1.ensureResourcePermissions)("skill", slug, [metadata.created_by_user_id, metadata.approved_by_user_id].filter((id) => Boolean(id)));
|
|
195
|
+
return metadata;
|
|
196
|
+
}
|
|
197
|
+
const now = BigInt(Date.now());
|
|
198
|
+
const created = await client_1.default.resource_metadata.create({
|
|
199
|
+
data: {
|
|
200
|
+
resource_kind: "skill",
|
|
201
|
+
resource_slug: slug,
|
|
202
|
+
created_at: now,
|
|
203
|
+
updated_at: now,
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
await (0, permission_common_1.ensureResourcePermissions)("skill", slug, []);
|
|
207
|
+
return {
|
|
208
|
+
skill_slug: created.resource_slug,
|
|
209
|
+
created_by_user_id: created.created_by_user_id,
|
|
210
|
+
approved_by_user_id: created.approved_by_user_id,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async function readSkillManifestAndEnsurePermissions(slug) {
|
|
214
|
+
const manifest = readSkillManifest(slug);
|
|
215
|
+
const metadata = await getOrCreateSkillMetadataAndEnsurePermission(slug);
|
|
216
|
+
return { manifest, metadata };
|
|
217
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isEngineerUser = isEngineerUser;
|
|
7
|
+
const client_1 = __importDefault(require("../prisma/client"));
|
|
8
|
+
async function isEngineerUser(userId) {
|
|
9
|
+
const user = await client_1.default.users.findUnique({
|
|
10
|
+
where: { id: userId },
|
|
11
|
+
select: { role: true }
|
|
12
|
+
});
|
|
13
|
+
return user?.role === "Engineer";
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildApprovalDiffResponse = void 0;
|
|
4
|
+
exports.collectCurrentWorkflowSnapshot = collectCurrentWorkflowSnapshot;
|
|
5
|
+
exports.loadApprovedSnapshotFromDb = loadApprovedSnapshotFromDb;
|
|
6
|
+
exports.approveWorkflowWithSnapshot = approveWorkflowWithSnapshot;
|
|
7
|
+
exports.getWorkflowSnapshotApprovalState = getWorkflowSnapshotApprovalState;
|
|
8
|
+
exports.restoreWorkflowToApprovedSnapshot = restoreWorkflowToApprovedSnapshot;
|
|
9
|
+
const workflow_1 = require("./workflow");
|
|
10
|
+
const workflow_2 = require("./workflow");
|
|
11
|
+
const approval_snapshot_common_1 = require("./approval-snapshot-common");
|
|
12
|
+
Object.defineProperty(exports, "buildApprovalDiffResponse", { enumerable: true, get: function () { return approval_snapshot_common_1.buildApprovalDiffResponse; } });
|
|
13
|
+
function getWorkflowSnapshotConfig(slug) {
|
|
14
|
+
return {
|
|
15
|
+
resource_kind: "workflow",
|
|
16
|
+
slug,
|
|
17
|
+
resource_label: "workflow",
|
|
18
|
+
root_path: (0, workflow_2.getWorkflowPath)(slug),
|
|
19
|
+
ensure_resource_exists: async () => {
|
|
20
|
+
await (0, workflow_1.readWorkflowManifestAndEnsurePermissions)(slug);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function collectCurrentWorkflowSnapshot(slug) {
|
|
25
|
+
return (0, approval_snapshot_common_1.collectCurrentResourceSnapshot)(getWorkflowSnapshotConfig(slug));
|
|
26
|
+
}
|
|
27
|
+
async function loadApprovedSnapshotFromDb(slug) {
|
|
28
|
+
return (0, approval_snapshot_common_1.loadApprovedSnapshotFromDb)("workflow", slug);
|
|
29
|
+
}
|
|
30
|
+
async function approveWorkflowWithSnapshot(slug, userId) {
|
|
31
|
+
return (0, approval_snapshot_common_1.approveResourceWithSnapshot)(getWorkflowSnapshotConfig(slug), userId);
|
|
32
|
+
}
|
|
33
|
+
async function getWorkflowSnapshotApprovalState(slug) {
|
|
34
|
+
return (0, approval_snapshot_common_1.getResourceSnapshotApprovalState)(getWorkflowSnapshotConfig(slug));
|
|
35
|
+
}
|
|
36
|
+
async function restoreWorkflowToApprovedSnapshot(slug, userId) {
|
|
37
|
+
return (0, approval_snapshot_common_1.restoreResourceToApprovedSnapshot)(getWorkflowSnapshotConfig(slug), userId);
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteWorkflowPath = exports.renameWorkflowPath = exports.uploadWorkflowFileFromTempPath = exports.createWorkflowFileOrFolder = exports.saveWorkflowFileContent = exports.readWorkflowFileContent = exports.listWorkflowDirectory = void 0;
|
|
4
|
+
const resource_files_1 = require("./resource-files");
|
|
5
|
+
const workflow_1 = require("./workflow");
|
|
6
|
+
const workflowFileManager = (0, resource_files_1.createResourceFileManager)({
|
|
7
|
+
getResourcePath: workflow_1.getWorkflowPath,
|
|
8
|
+
resourceLabel: "workflow",
|
|
9
|
+
editorLabel: "Workflow",
|
|
10
|
+
});
|
|
11
|
+
exports.listWorkflowDirectory = workflowFileManager.listDirectory;
|
|
12
|
+
exports.readWorkflowFileContent = workflowFileManager.readFileContent;
|
|
13
|
+
exports.saveWorkflowFileContent = workflowFileManager.saveFileContent;
|
|
14
|
+
exports.createWorkflowFileOrFolder = workflowFileManager.createFileOrFolder;
|
|
15
|
+
exports.uploadWorkflowFileFromTempPath = workflowFileManager.uploadFileFromTempPath;
|
|
16
|
+
exports.renameWorkflowPath = workflowFileManager.renamePath;
|
|
17
|
+
exports.deleteWorkflowPath = workflowFileManager.deletePath;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isWorkflowSessionInterrupted = isWorkflowSessionInterrupted;
|
|
7
|
+
exports.markWorkflowSessionAborted = markWorkflowSessionAborted;
|
|
8
|
+
const client_1 = __importDefault(require("../prisma/client"));
|
|
9
|
+
const opencode_client_1 = require("./opencode-client");
|
|
10
|
+
async function isWorkflowSessionInterrupted(sessionId, workspaceDir) {
|
|
11
|
+
const isManualSession = sessionId.startsWith("manual-");
|
|
12
|
+
if (isManualSession) {
|
|
13
|
+
const aborted = await client_1.default.workflow_aborted_sessions.findUnique({
|
|
14
|
+
where: { session_id: sessionId }
|
|
15
|
+
});
|
|
16
|
+
return Boolean(aborted);
|
|
17
|
+
}
|
|
18
|
+
const port = (0, opencode_client_1.getOpencodePort)();
|
|
19
|
+
const response = await fetch(`http://localhost:${port}/session/status?directory=${encodeURIComponent(workspaceDir)}`);
|
|
20
|
+
if (response.ok) {
|
|
21
|
+
const statuses = await response.json();
|
|
22
|
+
const state = statuses[sessionId] ?? null;
|
|
23
|
+
const sessionType = typeof state?.type === "string" ? state.type : null;
|
|
24
|
+
// Opencode may remove a session from this status map right after abort/interrupt.
|
|
25
|
+
// If it is not explicitly "busy", treat it as interrupted.
|
|
26
|
+
return sessionType !== "busy";
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
async function markWorkflowSessionAborted(sessionId) {
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
const cutoff = now - (24 * 60 * 60 * 1000);
|
|
33
|
+
await client_1.default.workflow_aborted_sessions.deleteMany({
|
|
34
|
+
where: {
|
|
35
|
+
created_at: {
|
|
36
|
+
lt: BigInt(cutoff)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
await client_1.default.workflow_aborted_sessions.upsert({
|
|
41
|
+
where: { session_id: sessionId },
|
|
42
|
+
create: {
|
|
43
|
+
session_id: sessionId,
|
|
44
|
+
created_at: BigInt(now)
|
|
45
|
+
},
|
|
46
|
+
update: {
|
|
47
|
+
created_at: BigInt(now)
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureWorkflowRunPermissionsForMetadata = ensureWorkflowRunPermissionsForMetadata;
|
|
4
|
+
exports.initializeWorkflowRunPermissionsForCreator = initializeWorkflowRunPermissionsForCreator;
|
|
5
|
+
exports.addApproverToWorkflowRunPermissionsIfRestricted = addApproverToWorkflowRunPermissionsIfRestricted;
|
|
6
|
+
exports.getWorkflowRunPermissionWithUsers = getWorkflowRunPermissionWithUsers;
|
|
7
|
+
exports.setWorkflowRunPermissions = setWorkflowRunPermissions;
|
|
8
|
+
const permission_common_1 = require("./permission-common");
|
|
9
|
+
function getDefaultCandidateUserIds(metadata) {
|
|
10
|
+
const ids = [metadata.created_by_user_id, metadata.approved_by_user_id].filter((id) => Boolean(id));
|
|
11
|
+
return Array.from(new Set(ids));
|
|
12
|
+
}
|
|
13
|
+
async function ensureWorkflowRunPermissionsForMetadata(slug, metadata) {
|
|
14
|
+
await (0, permission_common_1.ensureResourcePermissions)("workflow", slug, getDefaultCandidateUserIds(metadata));
|
|
15
|
+
}
|
|
16
|
+
async function initializeWorkflowRunPermissionsForCreator(slug, creatorUserId) {
|
|
17
|
+
await (0, permission_common_1.initializeResourcePermissionsForCreator)("workflow", slug, creatorUserId);
|
|
18
|
+
}
|
|
19
|
+
async function addApproverToWorkflowRunPermissionsIfRestricted(slug, approverUserId, ownerUserId) {
|
|
20
|
+
await (0, permission_common_1.addUserToResourcePermissionsIfRestricted)("workflow", slug, approverUserId, ownerUserId);
|
|
21
|
+
}
|
|
22
|
+
async function getWorkflowRunPermissionWithUsers(slug) {
|
|
23
|
+
return (0, permission_common_1.getResourcePermissionWithUsers)("workflow", slug, "Workflow run");
|
|
24
|
+
}
|
|
25
|
+
async function setWorkflowRunPermissions(slug, payload, ownerUserId) {
|
|
26
|
+
return (0, permission_common_1.setResourcePermissions)("workflow", slug, payload, ownerUserId);
|
|
27
|
+
}
|