* feat: add GitHub workflows to sync agents/ to Devin Knowledge - Add parse-to-devin-knowledge.ts to convert agents/ markdown to Devin Knowledge JSON - Add validate-format.ts to validate rules have frontmatter and knowledge-base sections start with 'When...' - Add sync-to-devin.ts to sync knowledge entries to Devin API - Add export-devin-knowledge.sh to backup existing Devin knowledge - Add validate-agents-format.yml workflow to validate format on PRs - Add sync-agents-to-devin.yml workflow to sync on merge to main - Add devin-knowledge.json to .gitignore (generated file) Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: use tsx instead of ts-node for better ESM support in CI Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * docs: add missing knowledge entries from Devin backup Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * refactor: move agents scripts to scripts/ folder Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * refactor: rename scripts to devin-knowledge-* for clarity Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * refactor: move scripts to scripts/devin/ with clearer names Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * rename DEVIN_API_TOKEN to DEVIN_API_KEY * docs: fix usage comment script path Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: remove folder creation from sync script (API doesn't support it) Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: add -S flag to shebang for proper env execution Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * use pull_request_target * fix: add -S flag to shebang in sync-knowledge-to-devin.ts for proper env execution Co-Authored-By: unknown <> * restructure workflows * refactor: consolidate agent docs and split knowledge-base into modular rules - Delete knowledge-base.md, migrate content to 17 new rule files - Delete coding-standards.md (content duplicated in AGENTS.md and rules) - Add ci- and reference- prefixes to rules/_sections.md - Update AGENTS.md to reference new rule files - Update agents/README.md as rules index - Clean up parse-local-knowledge.ts (remove deleted file references) New rule files: - testing-playwright, testing-mocking, testing-timezone - ci-check-failures, ci-type-check-first, ci-git-workflow - data-prisma-migrations, data-prisma-feature-flags - quality-error-handling, quality-imports, quality-pr-creation, quality-code-comments - architecture-features-modules - patterns-workflow-triggers, patterns-app-store - reference-file-locations, reference-local-dev Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Revert "refactor: consolidate agent docs and split knowledge-base into modular rules" This reverts commit 8251b6b214c7c01a3bfe2137c6aa9292dd72427e. * refactor: reorganize agent docs - extract coding rules, keep domain knowledge - Slim down knowledge-base.md (356 → 96 lines) to domain knowledge only - Add Business rules section (managed events, orgs/teams, OAuth clients) - Delete coding-standards.md (content moved to rules) - Create 19 new rule files for coding guidelines: - quality-*: PR creation, error handling, imports, comments, code review - testing-*: playwright, mocking, timezone, incremental - ci-*: check failures, type-check-first, git workflow - data-prisma-*: migrations, feature flags - patterns-*: workflow triggers, app store - architecture-features-modules, reference-file-locations, reference-local-dev - Update agents/README.md as rules index (43 total rules) - Update _sections.md with CI/CD and Reference sections - Clean up parse-local-knowledge.ts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: rename knowledge-base sections to start with "When..." Update section headers to pass validation rules: - "Business Rules" → "When working with managed events, organizations, or OAuth clients" - "Product & Codebase Knowledge" → "When you need product or codebase context" Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: split knowledge-base business rules into separate sections Split the combined "When working with managed events, organizations, or OAuth clients" section into three distinct ## sections for better Devin triggering: - When working with managed event types - When working with organizations and teams - When working with OAuth clients Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify trigger description logic in parse-local-knowledge.ts Since validate-local-knowledge.ts enforces that all section titles must start with "When...", we can remove the manual fallback logic and just use the title directly as the trigger description. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify knowledge-base section validation Simplify the validation to only check that section titles start with "When..." since we've standardized on that pattern. Remove the special cases for error, file naming, PR, and repo note sections. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: add script to delete all Devin knowledge entries Add delete-all-devin-knowledge.ts script that: - Lists all knowledge entries before deletion - Requires interactive confirmation (Y) to proceed - Blocks execution in non-TTY environments (CI, piped input) - Shows progress while deleting entries Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: add API reference links to delete-all-devin-knowledge script Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: replace NOW() with CURRENT_TIMESTAMP in feature flag migration example Co-Authored-By: unknown <> * add -S * docs: consolidate agent documentation and add AI setup guide - Remove duplicated Project Structure & Tech Stack from agents/README.md - Condense Commands section in AGENTS.md, link to agents/commands.md - Add AI-Assisted Development section to root README.md explaining the agents/ folder structure and symlink configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: remove incorrect CLAUDE.md symlink claim from README Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
203 lines
5.3 KiB
TypeScript
203 lines
5.3 KiB
TypeScript
#!/usr/bin/env -S npx tsx
|
|
|
|
/**
|
|
* Syncs knowledge from the generated JSON file to Devin's Knowledge API.
|
|
* - Creates new knowledge entries
|
|
* - Updates existing entries (matched by name)
|
|
* - Optionally deletes entries that no longer exist in the source
|
|
*
|
|
* Note: The Devin API v1 does not support creating folders via API.
|
|
* Entries will be created without folder assignment. You can organize
|
|
* them into folders manually in the Devin UI if needed.
|
|
*
|
|
* Usage: DEVIN_API_KEY=your_token npx tsx scripts/devin/sync-knowledge-to-devin.ts [--delete-removed]
|
|
*/
|
|
|
|
import process from "node:process";
|
|
import * as fs from "fs";
|
|
import * as path from "path";
|
|
|
|
interface DevinKnowledgeEntry {
|
|
name: string;
|
|
body: string;
|
|
trigger_description: string;
|
|
}
|
|
|
|
interface DevinKnowledgeOutput {
|
|
knowledge: DevinKnowledgeEntry[];
|
|
}
|
|
|
|
interface ApiKnowledgeEntry {
|
|
id: string;
|
|
name: string;
|
|
body: string;
|
|
trigger_description: string;
|
|
created_at: string;
|
|
created_by?: {
|
|
full_name: string;
|
|
id: string;
|
|
};
|
|
parent_folder_id?: string;
|
|
}
|
|
|
|
interface ApiListResponse {
|
|
folders: { id: string; name: string }[];
|
|
knowledge: ApiKnowledgeEntry[];
|
|
}
|
|
|
|
const API_BASE = "https://api.devin.ai/v1";
|
|
|
|
async function apiRequest<T>(method: string, endpoint: string, body?: Record<string, unknown>): Promise<T> {
|
|
const token = process.env.DEVIN_API_KEY;
|
|
if (!token) {
|
|
throw new Error("DEVIN_API_KEY environment variable is not set");
|
|
}
|
|
|
|
const url = `${API_BASE}${endpoint}`;
|
|
const options: RequestInit = {
|
|
method,
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
};
|
|
|
|
if (body) {
|
|
options.body = JSON.stringify(body);
|
|
}
|
|
|
|
const response = await fetch(url, options);
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text();
|
|
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
}
|
|
|
|
if (response.status === 204) {
|
|
return {} as T;
|
|
}
|
|
|
|
return response.json() as Promise<T>;
|
|
}
|
|
|
|
async function listKnowledge(): Promise<ApiListResponse> {
|
|
return apiRequest<ApiListResponse>("GET", "/knowledge");
|
|
}
|
|
|
|
async function createKnowledge(
|
|
name: string,
|
|
body: string,
|
|
triggerDescription: string
|
|
): Promise<ApiKnowledgeEntry> {
|
|
return apiRequest<ApiKnowledgeEntry>("POST", "/knowledge", {
|
|
name,
|
|
body,
|
|
trigger_description: triggerDescription,
|
|
});
|
|
}
|
|
|
|
async function updateKnowledge(
|
|
noteId: string,
|
|
name: string,
|
|
body: string,
|
|
triggerDescription: string
|
|
): Promise<ApiKnowledgeEntry> {
|
|
return apiRequest<ApiKnowledgeEntry>("PUT", `/knowledge/${noteId}`, {
|
|
name,
|
|
body,
|
|
trigger_description: triggerDescription,
|
|
});
|
|
}
|
|
|
|
async function deleteKnowledge(noteId: string): Promise<void> {
|
|
await apiRequest<void>("DELETE", `/knowledge/${noteId}`);
|
|
}
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
const deleteRemoved = args.includes("--delete-removed");
|
|
|
|
const agentsDir = path.join(path.dirname(__filename), "..", "..", "agents");
|
|
const jsonPath = path.join(agentsDir, "devin-knowledge.json");
|
|
|
|
if (!fs.existsSync(jsonPath)) {
|
|
console.error("Error: devin-knowledge.json not found. Run parse-to-devin-knowledge.ts first.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const localData: DevinKnowledgeOutput = JSON.parse(fs.readFileSync(jsonPath, "utf-8"));
|
|
|
|
console.log("Fetching existing knowledge from Devin API...");
|
|
const remoteData = await listKnowledge();
|
|
|
|
console.log(
|
|
`Found ${remoteData.folders.length} folders and ${remoteData.knowledge.length} entries in Devin\n`
|
|
);
|
|
|
|
// Build knowledge name -> entry map for remote
|
|
const remoteKnowledgeMap = new Map<string, ApiKnowledgeEntry>();
|
|
for (const entry of remoteData.knowledge) {
|
|
remoteKnowledgeMap.set(entry.name, entry);
|
|
}
|
|
|
|
// Track which remote entries we've seen
|
|
const seenRemoteIds = new Set<string>();
|
|
|
|
// Sync knowledge entries
|
|
console.log("\nSyncing knowledge entries...");
|
|
let created = 0;
|
|
let updated = 0;
|
|
let unchanged = 0;
|
|
|
|
for (const entry of localData.knowledge) {
|
|
const existing = remoteKnowledgeMap.get(entry.name);
|
|
|
|
if (existing) {
|
|
seenRemoteIds.add(existing.id);
|
|
|
|
const bodyChanged = existing.body !== entry.body;
|
|
const triggerChanged = existing.trigger_description !== entry.trigger_description;
|
|
|
|
if (bodyChanged || triggerChanged) {
|
|
console.log(` Updating: ${entry.name}`);
|
|
await updateKnowledge(existing.id, entry.name, entry.body, entry.trigger_description);
|
|
updated++;
|
|
} else {
|
|
unchanged++;
|
|
}
|
|
} else {
|
|
console.log(` Creating: ${entry.name}`);
|
|
await createKnowledge(entry.name, entry.body, entry.trigger_description);
|
|
created++;
|
|
}
|
|
}
|
|
|
|
// Delete removed entries if flag is set
|
|
let deleted = 0;
|
|
if (deleteRemoved) {
|
|
console.log("\nChecking for entries to delete...");
|
|
for (const entry of remoteData.knowledge) {
|
|
if (!seenRemoteIds.has(entry.id)) {
|
|
console.log(` Deleting: ${entry.name}`);
|
|
await deleteKnowledge(entry.id);
|
|
deleted++;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Summary
|
|
console.log("\n--- Sync Summary ---");
|
|
console.log(` Created: ${created}`);
|
|
console.log(` Updated: ${updated}`);
|
|
console.log(` Unchanged: ${unchanged}`);
|
|
if (deleteRemoved) {
|
|
console.log(` Deleted: ${deleted}`);
|
|
}
|
|
console.log("Sync complete!");
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error("Error:", error.message);
|
|
process.exit(1);
|
|
});
|