kontexta 7.0.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/standalone/CHANGELOG.md +15 -0
- package/bundle/standalone/apps/web/.next/BUILD_ID +1 -1
- package/bundle/standalone/apps/web/.next/app-build-manifest.json +47 -47
- package/bundle/standalone/apps/web/.next/app-path-routes-manifest.json +10 -10
- package/bundle/standalone/apps/web/.next/build-manifest.json +2 -2
- package/bundle/standalone/apps/web/.next/prerender-manifest.json +15 -15
- package/bundle/standalone/apps/web/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/_not-found.html +1 -1
- package/bundle/standalone/apps/web/.next/server/app/_not-found.rsc +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/about/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/about/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/mcp/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/mcp/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/agents/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/agents/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/brain/machines/[machineId]/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/brain/machines/[machineId]/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/brain/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/brain/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/brain/share/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/brain/share/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/clip/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/clip/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/conflicts/[gid]/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/conflicts/[gid]/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/conflicts/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/conflicts/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/route.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/folders/route.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/folders/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/folders/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/hands/test-pattern/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/hands/test-pattern/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/hands/validate/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/hands/validate/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/health/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/profile/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/profile/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/publish/html/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/publish/html/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/publish/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/publish/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/refresh/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/refresh/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/reindex/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/reindex/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/search/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/search/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/tags/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/tags/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/version-check/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/version-check/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/welcome/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/welcome/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/ws-config/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/api/ws-config/route_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/apple-icon.png/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/brain/page.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/brain/page_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/calendar/page.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/calendar/page_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/conflicts/page.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/conflicts/page_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/favicon.ico/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/icon.png/route.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/login/page.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/page.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/page.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/page_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/preview/motifs/page.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/app/preview/motifs/page_client-reference-manifest.js +1 -1
- package/bundle/standalone/apps/web/.next/server/app/preview/motifs.html +2 -2
- package/bundle/standalone/apps/web/.next/server/app/preview/motifs.rsc +1 -1
- package/bundle/standalone/apps/web/.next/server/app-paths-manifest.json +10 -10
- package/bundle/standalone/apps/web/.next/server/pages/404.html +1 -1
- package/bundle/standalone/apps/web/.next/server/pages/500.html +1 -1
- package/bundle/standalone/apps/web/.next/server/pages/_app.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/pages/_document.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/pages/_error.js.nft.json +1 -1
- package/bundle/standalone/apps/web/.next/server/server-reference-manifest.json +1 -1
- package/bundle/standalone/apps/web/.next/static/chunks/app/{page-c6c62b21883416e0.js → page-a9582ca62bbb876e.js} +1 -1
- package/bundle/standalone/apps/web/package.json +4 -4
- package/bundle/standalone/node_modules/kontexta-mcp/dist/index.js +78 -31
- package/bundle/standalone/node_modules/kontexta-mcp/dist/index.js.map +1 -1
- package/bundle/standalone/node_modules/kontexta-mcp/dist/migrations/020-inline-content.sql +30 -0
- package/bundle/standalone/node_modules/kontexta-mcp/dist/transfer-cli.d.ts +3 -0
- package/bundle/standalone/node_modules/kontexta-mcp/dist/transfer-cli.d.ts.map +1 -0
- package/bundle/standalone/node_modules/kontexta-mcp/dist/transfer-cli.js +111 -0
- package/bundle/standalone/node_modules/kontexta-mcp/dist/transfer-cli.js.map +1 -0
- package/bundle/standalone/node_modules/kontexta-mcp/package.json +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/db/index.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/db/index.js +7 -0
- package/bundle/standalone/node_modules/kxta-core/dist/db/index.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/db/inline-migration.d.ts +6 -0
- package/bundle/standalone/node_modules/kxta-core/dist/db/inline-migration.d.ts.map +1 -0
- package/bundle/standalone/node_modules/kxta-core/dist/db/inline-migration.js +77 -0
- package/bundle/standalone/node_modules/kxta-core/dist/db/inline-migration.js.map +1 -0
- package/bundle/standalone/node_modules/kxta-core/dist/db/migrations/020-inline-content.sql +30 -0
- package/bundle/standalone/node_modules/kxta-core/dist/files/index.d.ts +6 -2
- package/bundle/standalone/node_modules/kxta-core/dist/files/index.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/files/index.js +213 -109
- package/bundle/standalone/node_modules/kxta-core/dist/files/index.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/git/index.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/git/index.js +38 -0
- package/bundle/standalone/node_modules/kxta-core/dist/git/index.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/index.d.ts +1 -0
- package/bundle/standalone/node_modules/kxta-core/dist/index.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/index.js +1 -0
- package/bundle/standalone/node_modules/kxta-core/dist/index.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.js +84 -15
- package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/journal/housekeep.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/journal/housekeep.js +12 -2
- package/bundle/standalone/node_modules/kxta-core/dist/journal/housekeep.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.js +26 -18
- package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/revisions/index.d.ts +52 -0
- package/bundle/standalone/node_modules/kxta-core/dist/revisions/index.d.ts.map +1 -0
- package/bundle/standalone/node_modules/kxta-core/dist/revisions/index.js +151 -0
- package/bundle/standalone/node_modules/kxta-core/dist/revisions/index.js.map +1 -0
- package/bundle/standalone/node_modules/kxta-core/dist/storage/apply.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/storage/apply.js +38 -16
- package/bundle/standalone/node_modules/kxta-core/dist/storage/apply.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/storage/conflicts.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/storage/conflicts.js +105 -49
- package/bundle/standalone/node_modules/kxta-core/dist/storage/conflicts.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/storage/journal-merge.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/storage/journal-merge.js +20 -5
- package/bundle/standalone/node_modules/kxta-core/dist/storage/journal-merge.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/transfer/index.d.ts +70 -0
- package/bundle/standalone/node_modules/kxta-core/dist/transfer/index.d.ts.map +1 -0
- package/bundle/standalone/node_modules/kxta-core/dist/transfer/index.js +197 -0
- package/bundle/standalone/node_modules/kxta-core/dist/transfer/index.js.map +1 -0
- package/bundle/standalone/node_modules/kxta-core/dist/types.d.ts +2 -0
- package/bundle/standalone/node_modules/kxta-core/dist/types.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/watcher/index.d.ts.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/dist/watcher/index.js +27 -4
- package/bundle/standalone/node_modules/kxta-core/dist/watcher/index.js.map +1 -1
- package/bundle/standalone/node_modules/kxta-core/package.json +1 -1
- package/bundle/standalone/node_modules/kxta-publish/package.json +2 -2
- package/bundle/standalone/package.json +1 -1
- package/dist/index.js +7 -0
- package/dist/transfer-4YWEYHIM.js +25 -0
- package/package.json +1 -1
- /package/bundle/standalone/apps/web/.next/static/{_69cGZl0_6kXnJ03xwWXc → GFFKAisptTfr4--zsTHM4}/_buildManifest.js +0 -0
- /package/bundle/standalone/apps/web/.next/static/{_69cGZl0_6kXnJ03xwWXc → GFFKAisptTfr4--zsTHM4}/_ssgManifest.js +0 -0
|
@@ -10,6 +10,7 @@ import { getDatabase } from "../db/index.js";
|
|
|
10
10
|
import { formatGid } from "../identity/gid.js";
|
|
11
11
|
import { getMachineId } from "../identity/machine.js";
|
|
12
12
|
import { commitFile, commitDelete } from "../git/index.js";
|
|
13
|
+
import { createRevision } from "../revisions/index.js";
|
|
13
14
|
import { assertPathInside, escapeLike, withLock, fileLockKey } from "../util/safety.js";
|
|
14
15
|
import { profileRelPath, repairProfile } from "../profile/index.js";
|
|
15
16
|
import { sanitizeHtml } from "../reports/sanitize.js";
|
|
@@ -23,9 +24,11 @@ import { gidOfRow } from "../storage/gids.js";
|
|
|
23
24
|
/**
|
|
24
25
|
* List all folders in a project (recursively)
|
|
25
26
|
*/
|
|
26
|
-
export function listProjectFolders(projectPath) {
|
|
27
|
-
const folders =
|
|
27
|
+
export function listProjectFolders(projectPath, opts) {
|
|
28
|
+
const folders = new Set();
|
|
28
29
|
function scan(dir, currentRel) {
|
|
30
|
+
if (!existsSync(dir))
|
|
31
|
+
return;
|
|
29
32
|
const entries = readdirSync(dir);
|
|
30
33
|
for (const entry of entries) {
|
|
31
34
|
if (entry.startsWith(".") || entry === "node_modules")
|
|
@@ -38,7 +41,7 @@ export function listProjectFolders(projectPath) {
|
|
|
38
41
|
if (lst.isSymbolicLink())
|
|
39
42
|
continue;
|
|
40
43
|
if (lst.isDirectory()) {
|
|
41
|
-
folders.
|
|
44
|
+
folders.add(relPath);
|
|
42
45
|
scan(fullPath, relPath);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -53,13 +56,34 @@ export function listProjectFolders(projectPath) {
|
|
|
53
56
|
catch (e) {
|
|
54
57
|
console.error("Failed to scan project folders:", e);
|
|
55
58
|
}
|
|
56
|
-
|
|
59
|
+
// Include virtual folders and folder prefixes from SQLite
|
|
60
|
+
try {
|
|
61
|
+
const db = getDatabase();
|
|
62
|
+
const vRows = db.prepare("SELECT path FROM virtual_folders").all();
|
|
63
|
+
for (const r of vRows) {
|
|
64
|
+
folders.add(r.path);
|
|
65
|
+
}
|
|
66
|
+
// Also include folders derived from file paths
|
|
67
|
+
const fileRows = db.prepare("SELECT path FROM files WHERE storage_type = 'local'").all();
|
|
68
|
+
const root = opts?.dataDir ? resolve(opts.dataDir, "knowledge") : resolve(projectPath);
|
|
69
|
+
for (const fr of fileRows) {
|
|
70
|
+
const rel = relative(root, fr.path);
|
|
71
|
+
if (!rel.startsWith("..") && !isAbsolute(rel)) {
|
|
72
|
+
const parts = rel.split(/[/\\]/);
|
|
73
|
+
for (let i = 1; i < parts.length; i++) {
|
|
74
|
+
folders.add(parts.slice(0, i).join("/"));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch { }
|
|
80
|
+
return Array.from(folders).sort();
|
|
57
81
|
}
|
|
58
82
|
/**
|
|
59
83
|
* List all folders in a project that contain at least one .md or .mmd file.
|
|
60
84
|
* Returns only non-empty folders (useful for publish UI).
|
|
61
85
|
*/
|
|
62
|
-
export function listProjectFoldersWithFiles(projectPath) {
|
|
86
|
+
export function listProjectFoldersWithFiles(projectPath, opts) {
|
|
63
87
|
const folderFileCount = new Map();
|
|
64
88
|
function scan(dir, currentRel) {
|
|
65
89
|
const entries = readdirSync(dir);
|
|
@@ -97,6 +121,25 @@ export function listProjectFoldersWithFiles(projectPath) {
|
|
|
97
121
|
catch (e) {
|
|
98
122
|
console.error("Failed to scan project folders with files:", e);
|
|
99
123
|
}
|
|
124
|
+
// Include non-empty folders from SQLite for inline/local files
|
|
125
|
+
try {
|
|
126
|
+
const db = getDatabase();
|
|
127
|
+
const fileRows = db.prepare("SELECT path FROM files WHERE storage_type = 'local'").all();
|
|
128
|
+
const root = opts?.dataDir ? resolve(opts.dataDir, "knowledge") : resolve(projectPath);
|
|
129
|
+
for (const fr of fileRows) {
|
|
130
|
+
if (isIndexedFile(fr.path)) {
|
|
131
|
+
const rel = relative(root, fr.path);
|
|
132
|
+
if (!rel.startsWith("..") && !isAbsolute(rel)) {
|
|
133
|
+
const parts = rel.split(/[/\\]/);
|
|
134
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
135
|
+
const ancestor = parts.slice(0, i + 1).join("/");
|
|
136
|
+
folderFileCount.set(ancestor, (folderFileCount.get(ancestor) ?? 0) + 1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch { }
|
|
100
143
|
// Return only folders with at least one .md/.mmd file
|
|
101
144
|
const result = [];
|
|
102
145
|
for (const [folder, count] of folderFileCount.entries()) {
|
|
@@ -201,12 +244,11 @@ export async function createFile(opts) {
|
|
|
201
244
|
// UPSERT, and the FTS index can land with the watcher's interpretation
|
|
202
245
|
// of the file (no tags, default title) instead of the caller's.
|
|
203
246
|
return withLock(fileLockKey(filePath), async () => {
|
|
204
|
-
mkdirSync(dirname(filePath), { recursive: true });
|
|
205
247
|
// Stash pre-existing content (if any) so we can fully restore on a
|
|
206
248
|
// DB-txn failure — otherwise writeFileSync below would leave the
|
|
207
249
|
// caller's content sitting under a row that points elsewhere.
|
|
208
250
|
let preExistingContent = null;
|
|
209
|
-
if (existsSync(filePath)) {
|
|
251
|
+
if (storageType === "reference" && existsSync(filePath)) {
|
|
210
252
|
try {
|
|
211
253
|
preExistingContent = readFileSync(filePath);
|
|
212
254
|
}
|
|
@@ -224,13 +266,16 @@ export async function createFile(opts) {
|
|
|
224
266
|
}
|
|
225
267
|
if (format === "html" && !skipHtmlSanitize)
|
|
226
268
|
content = await sanitizeHtml(content);
|
|
227
|
-
|
|
269
|
+
if (storageType === "reference") {
|
|
270
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
271
|
+
writeFileSync(filePath, content, "utf8");
|
|
272
|
+
}
|
|
228
273
|
const contentHash = computeHash(content);
|
|
229
274
|
const contentClass = computeContentClass({ storageType, path: filePath, dataDir });
|
|
230
275
|
// ON CONFLICT(path) absorbs the watcher's stub row if chokidar's `add` won the race.
|
|
231
276
|
const upsertStmt = db.prepare(`
|
|
232
|
-
INSERT INTO files (path, title, project_id, storage_type, content_class, source_path, content_hash)
|
|
233
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
277
|
+
INSERT INTO files (path, title, project_id, storage_type, content_class, source_path, content_hash, content)
|
|
278
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
234
279
|
ON CONFLICT(path) DO UPDATE SET
|
|
235
280
|
title = excluded.title,
|
|
236
281
|
project_id = excluded.project_id,
|
|
@@ -238,6 +283,7 @@ export async function createFile(opts) {
|
|
|
238
283
|
content_class = excluded.content_class,
|
|
239
284
|
source_path = excluded.source_path,
|
|
240
285
|
content_hash = excluded.content_hash,
|
|
286
|
+
content = excluded.content,
|
|
241
287
|
updated_at = datetime('now')
|
|
242
288
|
`);
|
|
243
289
|
const getIdByPathStmt = db.prepare("SELECT id FROM files WHERE path = ?");
|
|
@@ -251,12 +297,12 @@ export async function createFile(opts) {
|
|
|
251
297
|
const setGidStmt = db.prepare("UPDATE files SET gid = ? WHERE id = ?");
|
|
252
298
|
// Snapshot for rollback — upsert may overwrite an existing row.
|
|
253
299
|
const priorRow = db
|
|
254
|
-
.prepare("SELECT id, title, project_id, storage_type, content_class, source_path, content_hash, updated_at FROM files WHERE path = ?")
|
|
300
|
+
.prepare("SELECT id, title, project_id, storage_type, content_class, source_path, content_hash, content, updated_at FROM files WHERE path = ?")
|
|
255
301
|
.get(filePath);
|
|
256
302
|
let fileId;
|
|
257
303
|
try {
|
|
258
304
|
fileId = db.transaction(() => {
|
|
259
|
-
upsertStmt.run(filePath, title, projectId || null, storageType, contentClass, sourcePath || null, contentHash);
|
|
305
|
+
upsertStmt.run(filePath, title, projectId || null, storageType, contentClass, sourcePath || null, contentHash, content);
|
|
260
306
|
const row = getIdByPathStmt.get(filePath);
|
|
261
307
|
if (!row)
|
|
262
308
|
throw new Error(`createFile: row missing after upsert for ${filePath}`);
|
|
@@ -266,6 +312,14 @@ export async function createFile(opts) {
|
|
|
266
312
|
// corrects a watcher stub row that this upsert just absorbed.
|
|
267
313
|
const gid = formatGid(id, getMachineId());
|
|
268
314
|
setGidStmt.run(gid, id);
|
|
315
|
+
// Snapshot revision for local files
|
|
316
|
+
if (storageType === "local") {
|
|
317
|
+
createRevision(db, {
|
|
318
|
+
fileId: id,
|
|
319
|
+
content,
|
|
320
|
+
message: `Create context file: ${title}`,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
269
323
|
if (tags.length > 0) {
|
|
270
324
|
for (const tagName of tags) {
|
|
271
325
|
insertTagStmt.run(tagName);
|
|
@@ -304,24 +358,26 @@ export async function createFile(opts) {
|
|
|
304
358
|
})();
|
|
305
359
|
}
|
|
306
360
|
catch (dbError) {
|
|
307
|
-
if (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
361
|
+
if (storageType === "reference") {
|
|
362
|
+
if (preExistingContent !== null) {
|
|
363
|
+
try {
|
|
364
|
+
writeFileSync(filePath, preExistingContent);
|
|
365
|
+
}
|
|
366
|
+
catch (e) {
|
|
367
|
+
console.error("createFile: failed to restore pre-existing content after DB error:", e);
|
|
368
|
+
}
|
|
313
369
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
370
|
+
else {
|
|
371
|
+
try {
|
|
372
|
+
unlinkSync(filePath);
|
|
373
|
+
}
|
|
374
|
+
catch { }
|
|
318
375
|
}
|
|
319
|
-
catch { }
|
|
320
376
|
}
|
|
321
377
|
// Roll DB back to priorRow (if any) or delete the freshly-inserted row.
|
|
322
378
|
try {
|
|
323
379
|
if (priorRow) {
|
|
324
|
-
db.prepare("UPDATE files SET title=?, project_id=?, storage_type=?, content_class=?, source_path=?, content_hash=?, updated_at=? WHERE id=?").run(priorRow.title, priorRow.project_id, priorRow.storage_type, priorRow.content_class, priorRow.source_path, priorRow.content_hash, priorRow.updated_at, priorRow.id);
|
|
380
|
+
db.prepare("UPDATE files SET title=?, project_id=?, storage_type=?, content_class=?, source_path=?, content_hash=?, content=?, updated_at=? WHERE id=?").run(priorRow.title, priorRow.project_id, priorRow.storage_type, priorRow.content_class, priorRow.source_path, priorRow.content_hash, priorRow.content ?? null, priorRow.updated_at, priorRow.id);
|
|
325
381
|
}
|
|
326
382
|
else {
|
|
327
383
|
db.prepare("DELETE FROM files WHERE path = ?").run(filePath);
|
|
@@ -335,18 +391,20 @@ export async function createFile(opts) {
|
|
|
335
391
|
const fileRecord = db.prepare("SELECT * FROM files WHERE id = ?").get(fileId);
|
|
336
392
|
// Reference files version against their project's own git, not the data dir.
|
|
337
393
|
let gitWarning;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
394
|
+
if (storageType === "reference") {
|
|
395
|
+
try {
|
|
396
|
+
let repoDir = dataDir;
|
|
397
|
+
if (projectId) {
|
|
398
|
+
const project = db.prepare("SELECT path FROM projects WHERE id = ?").get(projectId);
|
|
399
|
+
if (project?.path)
|
|
400
|
+
repoDir = project.path;
|
|
401
|
+
}
|
|
402
|
+
await commitFile(repoDir, filePath, `Create context file: ${title}`);
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
gitWarning = error instanceof Error ? error.message : String(error);
|
|
406
|
+
console.warn("Git auto-commit failed during creation:", error);
|
|
344
407
|
}
|
|
345
|
-
await commitFile(repoDir, filePath, `Create context file: ${title}`);
|
|
346
|
-
}
|
|
347
|
-
catch (error) {
|
|
348
|
-
gitWarning = error instanceof Error ? error.message : String(error);
|
|
349
|
-
console.warn("Git auto-commit failed during creation:", error);
|
|
350
408
|
}
|
|
351
409
|
return {
|
|
352
410
|
...fileRecord,
|
|
@@ -364,7 +422,13 @@ export function readFile(id) {
|
|
|
364
422
|
if (!fileRecord) {
|
|
365
423
|
throw new Error(`File not found: ${id}`);
|
|
366
424
|
}
|
|
367
|
-
|
|
425
|
+
let content;
|
|
426
|
+
if (fileRecord.storage_type === "local" && fileRecord.content !== undefined && fileRecord.content !== null) {
|
|
427
|
+
content = fileRecord.content;
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
content = readFileSync(fileRecord.path, "utf8");
|
|
431
|
+
}
|
|
368
432
|
return {
|
|
369
433
|
...fileRecord,
|
|
370
434
|
content,
|
|
@@ -388,7 +452,7 @@ export async function updateFile(id, content, dataDir) {
|
|
|
388
452
|
// under a row whose content_hash and FTS index still reflect the old
|
|
389
453
|
// content, leaving permanent drift.
|
|
390
454
|
let preExistingContent = null;
|
|
391
|
-
if (existsSync(fileRecord.path)) {
|
|
455
|
+
if (fileRecord.storage_type === "reference" && existsSync(fileRecord.path)) {
|
|
392
456
|
try {
|
|
393
457
|
preExistingContent = readFileSync(fileRecord.path);
|
|
394
458
|
}
|
|
@@ -398,12 +462,14 @@ export async function updateFile(id, content, dataDir) {
|
|
|
398
462
|
}
|
|
399
463
|
if (fileRecord.path.endsWith(".html"))
|
|
400
464
|
content = await sanitizeHtml(content);
|
|
401
|
-
|
|
465
|
+
if (fileRecord.storage_type === "reference") {
|
|
466
|
+
writeFileSync(fileRecord.path, content, "utf8");
|
|
467
|
+
}
|
|
402
468
|
const contentHash = computeHash(content);
|
|
403
469
|
// Atomic so a partial failure can't leave the FTS index pointing at stale content.
|
|
404
470
|
const updateStmt = db.prepare(`
|
|
405
471
|
UPDATE files
|
|
406
|
-
SET content_hash = ?, updated_at = datetime('now')
|
|
472
|
+
SET content = ?, content_hash = ?, updated_at = datetime('now')
|
|
407
473
|
WHERE id = ?
|
|
408
474
|
`);
|
|
409
475
|
const deleteFtsStmt = db.prepare("DELETE FROM fts_index WHERE rowid = ?");
|
|
@@ -413,9 +479,17 @@ export async function updateFile(id, content, dataDir) {
|
|
|
413
479
|
const gid = fileRecord.gid ?? formatGid(fileRecord.id, getMachineId());
|
|
414
480
|
try {
|
|
415
481
|
db.transaction(() => {
|
|
416
|
-
updateStmt.run(contentHash, id);
|
|
482
|
+
updateStmt.run(content, contentHash, id);
|
|
417
483
|
deleteFtsStmt.run(id);
|
|
418
484
|
insertFtsStmt.run(id, fileRecord.title, content);
|
|
485
|
+
// Snapshot revision for local files
|
|
486
|
+
if (fileRecord.storage_type === "local") {
|
|
487
|
+
createRevision(db, {
|
|
488
|
+
fileId: id,
|
|
489
|
+
content,
|
|
490
|
+
message: `Update context file: ${fileRecord.title}`,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
419
493
|
// Enqueue the outbound op atomically with the write (spec 1.3); no-op
|
|
420
494
|
// while applying a remote op (echo suppression, spec 1.4).
|
|
421
495
|
enqueueFileOp({
|
|
@@ -435,7 +509,7 @@ export async function updateFile(id, content, dataDir) {
|
|
|
435
509
|
})();
|
|
436
510
|
}
|
|
437
511
|
catch (dbError) {
|
|
438
|
-
if (preExistingContent !== null) {
|
|
512
|
+
if (fileRecord.storage_type === "reference" && preExistingContent !== null) {
|
|
439
513
|
try {
|
|
440
514
|
writeFileSync(fileRecord.path, preExistingContent);
|
|
441
515
|
}
|
|
@@ -446,18 +520,20 @@ export async function updateFile(id, content, dataDir) {
|
|
|
446
520
|
throw dbError;
|
|
447
521
|
}
|
|
448
522
|
let gitWarning;
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
523
|
+
if (fileRecord.storage_type === "reference") {
|
|
524
|
+
try {
|
|
525
|
+
let repoDir = dataDir;
|
|
526
|
+
if (fileRecord.project_id) {
|
|
527
|
+
const project = db.prepare("SELECT path FROM projects WHERE id = ?").get(fileRecord.project_id);
|
|
528
|
+
if (project?.path)
|
|
529
|
+
repoDir = project.path;
|
|
530
|
+
}
|
|
531
|
+
await commitFile(repoDir, fileRecord.path, `Update context file: ${fileRecord.title}`);
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
gitWarning = error instanceof Error ? error.message : String(error);
|
|
535
|
+
console.warn("Git auto-commit failed during update:", error);
|
|
455
536
|
}
|
|
456
|
-
await commitFile(repoDir, fileRecord.path, `Update context file: ${fileRecord.title}`);
|
|
457
|
-
}
|
|
458
|
-
catch (error) {
|
|
459
|
-
gitWarning = error instanceof Error ? error.message : String(error);
|
|
460
|
-
console.warn("Git auto-commit failed during update:", error);
|
|
461
537
|
}
|
|
462
538
|
const updatedRecord = db.prepare("SELECT * FROM files WHERE id = ?").get(id);
|
|
463
539
|
return {
|
|
@@ -479,19 +555,18 @@ export async function updateFile(id, content, dataDir) {
|
|
|
479
555
|
*/
|
|
480
556
|
export async function deleteFile(id, dataDir) {
|
|
481
557
|
const db = getDatabase();
|
|
482
|
-
const file = db.prepare("SELECT path, project_id, gid FROM files WHERE id = ?").get(id);
|
|
558
|
+
const file = db.prepare("SELECT path, project_id, storage_type, gid FROM files WHERE id = ?").get(id);
|
|
483
559
|
if (!file) {
|
|
484
560
|
throw new Error(`File not found: ${id}`);
|
|
485
561
|
}
|
|
486
562
|
let unlinked = false;
|
|
487
|
-
let inKnowledge = false;
|
|
488
563
|
let filePathResolved = file.path;
|
|
489
|
-
if
|
|
564
|
+
// Only reference files on disk need explicit unlinking/commitDelete if applicable
|
|
565
|
+
if (dataDir && file.storage_type === "reference") {
|
|
490
566
|
const knowledgeRoot = resolve(dataDir, "knowledge");
|
|
491
567
|
filePathResolved = isAbsolute(file.path) ? file.path : resolve(dataDir, file.path);
|
|
492
|
-
inKnowledge =
|
|
493
|
-
filePathResolved
|
|
494
|
-
filePathResolved.startsWith(knowledgeRoot + sep);
|
|
568
|
+
const inKnowledge = filePathResolved === knowledgeRoot ||
|
|
569
|
+
filePathResolved.startsWith(knowledgeRoot + sep);
|
|
495
570
|
if (file.project_id === null && inKnowledge) {
|
|
496
571
|
try {
|
|
497
572
|
if (existsSync(filePathResolved)) {
|
|
@@ -504,7 +579,7 @@ export async function deleteFile(id, dataDir) {
|
|
|
504
579
|
}
|
|
505
580
|
}
|
|
506
581
|
}
|
|
507
|
-
// CASCADE handles file_tags + favorites via the files row deletion.
|
|
582
|
+
// CASCADE handles file_tags + favorites + file_revisions via the files row deletion.
|
|
508
583
|
const deleteFtsStmt = db.prepare("DELETE FROM fts_index WHERE rowid = ?");
|
|
509
584
|
const deleteStmt = db.prepare("DELETE FROM files WHERE id = ?");
|
|
510
585
|
// Read the record's gid (not recomputed) so a REMOTE file's deletion carries
|
|
@@ -524,11 +599,8 @@ export async function deleteFile(id, dataDir) {
|
|
|
524
599
|
deleteFtsStmt.run(id);
|
|
525
600
|
deleteStmt.run(id);
|
|
526
601
|
})();
|
|
527
|
-
// Commit the deletion to git
|
|
528
|
-
|
|
529
|
-
// actually unlinked them) — for project files we leave the source tree
|
|
530
|
-
// untouched. Best-effort; failures don't block the delete.
|
|
531
|
-
if (unlinked && dataDir) {
|
|
602
|
+
// Commit the deletion to git if it was on disk
|
|
603
|
+
if (unlinked && dataDir && file.storage_type === "reference") {
|
|
532
604
|
try {
|
|
533
605
|
await commitDelete(dataDir, filePathResolved, `Delete context file: ${basename(filePathResolved)}`);
|
|
534
606
|
}
|
|
@@ -542,10 +614,17 @@ export async function deleteFile(id, dataDir) {
|
|
|
542
614
|
*/
|
|
543
615
|
export function createFolder(projectPath, folderName, opts) {
|
|
544
616
|
const fullPath = assertPathInside(projectPath, folderName);
|
|
617
|
+
const db = getDatabase();
|
|
545
618
|
if (opts?.dataDir) {
|
|
546
619
|
const knowledgeDir = resolve(opts.dataDir, "knowledge");
|
|
547
620
|
if (resolve(projectPath) === knowledgeDir) {
|
|
548
621
|
validateKnowledgeWrite(folderName, "folder");
|
|
622
|
+
// Record virtual folder in SQLite
|
|
623
|
+
try {
|
|
624
|
+
db.prepare("INSERT OR IGNORE INTO virtual_folders (path) VALUES (?)").run(folderName);
|
|
625
|
+
}
|
|
626
|
+
catch { }
|
|
627
|
+
return fullPath;
|
|
549
628
|
}
|
|
550
629
|
}
|
|
551
630
|
mkdirSync(fullPath, { recursive: true });
|
|
@@ -556,6 +635,7 @@ export function createFolder(projectPath, folderName, opts) {
|
|
|
556
635
|
*/
|
|
557
636
|
export function deleteFolder(projectPath, folderName, opts) {
|
|
558
637
|
const fullPath = assertPathInside(projectPath, folderName);
|
|
638
|
+
const db = getDatabase();
|
|
559
639
|
if (opts?.dataDir) {
|
|
560
640
|
const knowledgeDir = resolve(opts.dataDir, "knowledge");
|
|
561
641
|
if (resolve(projectPath) === knowledgeDir) {
|
|
@@ -563,9 +643,36 @@ export function deleteFolder(projectPath, folderName, opts) {
|
|
|
563
643
|
if (segments.length <= 1) {
|
|
564
644
|
throw new Error(`Cannot delete root knowledge folder '${folderName}'.`);
|
|
565
645
|
}
|
|
646
|
+
try {
|
|
647
|
+
db.prepare("DELETE FROM virtual_folders WHERE path = ? OR path LIKE ?").run(folderName, `${folderName}/%`);
|
|
648
|
+
// Also cascade delete files inside this virtual folder from SQLite, fts_index, and enqueue outbox ops
|
|
649
|
+
const pattern = `${knowledgeDir}/${folderName}/%`;
|
|
650
|
+
const patternWin = `${knowledgeDir}\\${folderName}\\%`;
|
|
651
|
+
const matchingFiles = db
|
|
652
|
+
.prepare("SELECT id, path, gid FROM files WHERE path LIKE ? OR path LIKE ?")
|
|
653
|
+
.all(pattern, patternWin);
|
|
654
|
+
db.transaction(() => {
|
|
655
|
+
for (const mf of matchingFiles) {
|
|
656
|
+
const gid = mf.gid ?? formatGid(mf.id, getMachineId());
|
|
657
|
+
enqueueFileOp({
|
|
658
|
+
gid,
|
|
659
|
+
kind: "file.delete",
|
|
660
|
+
origin: getMachineId(),
|
|
661
|
+
base_version: 0,
|
|
662
|
+
payload: { path: mf.path, rel_path: toRelPath(mf.path) ?? undefined },
|
|
663
|
+
created_at: Date.now(),
|
|
664
|
+
});
|
|
665
|
+
db.prepare("DELETE FROM fts_index WHERE rowid = ?").run(mf.id);
|
|
666
|
+
db.prepare("DELETE FROM files WHERE id = ?").run(mf.id);
|
|
667
|
+
}
|
|
668
|
+
})();
|
|
669
|
+
}
|
|
670
|
+
catch { }
|
|
566
671
|
}
|
|
567
672
|
}
|
|
568
|
-
|
|
673
|
+
if (existsSync(fullPath)) {
|
|
674
|
+
rmSync(fullPath, { recursive: true, force: true });
|
|
675
|
+
}
|
|
569
676
|
}
|
|
570
677
|
/**
|
|
571
678
|
* List files with optional filters
|
|
@@ -710,50 +817,45 @@ export function moveFile(id, newPath, dataDir) {
|
|
|
710
817
|
}
|
|
711
818
|
}
|
|
712
819
|
const oldPath = fileRecord.path;
|
|
713
|
-
if (
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
const buf = readFileSync(oldPath);
|
|
728
|
-
writeFileSync(tmpDest, buf);
|
|
729
|
-
renameSync(tmpDest, newPath);
|
|
730
|
-
unlinkSync(oldPath);
|
|
731
|
-
}
|
|
732
|
-
catch (copyErr) {
|
|
820
|
+
if (fileRecord.storage_type === "reference") {
|
|
821
|
+
if (newPath !== oldPath && existsSync(newPath)) {
|
|
822
|
+
throw new Error(`moveFile: destination already exists: ${newPath}`);
|
|
823
|
+
}
|
|
824
|
+
mkdirSync(dirname(newPath), { recursive: true });
|
|
825
|
+
try {
|
|
826
|
+
renameSync(oldPath, newPath);
|
|
827
|
+
}
|
|
828
|
+
catch (err) {
|
|
829
|
+
if (err?.code === "EXDEV") {
|
|
830
|
+
// Cross-device move (e.g. Docker bind mount → tmpfs). renameSync can't
|
|
831
|
+
// span devices on POSIX; fall back to copy + unlink, atomic on the
|
|
832
|
+
// destination via .tmp + rename trick.
|
|
833
|
+
const tmpDest = `${newPath}.${process.pid}.${Date.now()}.tmp`;
|
|
733
834
|
try {
|
|
734
|
-
|
|
735
|
-
|
|
835
|
+
const buf = readFileSync(oldPath);
|
|
836
|
+
writeFileSync(tmpDest, buf);
|
|
837
|
+
renameSync(tmpDest, newPath);
|
|
838
|
+
unlinkSync(oldPath);
|
|
736
839
|
}
|
|
737
|
-
catch {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
840
|
+
catch (copyErr) {
|
|
841
|
+
try {
|
|
842
|
+
if (existsSync(tmpDest))
|
|
843
|
+
unlinkSync(tmpDest);
|
|
844
|
+
}
|
|
845
|
+
catch { }
|
|
846
|
+
try {
|
|
847
|
+
if (existsSync(newPath) && !existsSync(oldPath))
|
|
848
|
+
renameSync(newPath, oldPath);
|
|
849
|
+
}
|
|
850
|
+
catch { }
|
|
851
|
+
throw copyErr;
|
|
741
852
|
}
|
|
742
|
-
catch { }
|
|
743
|
-
throw copyErr;
|
|
744
853
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
854
|
+
else {
|
|
855
|
+
throw err;
|
|
856
|
+
}
|
|
748
857
|
}
|
|
749
858
|
}
|
|
750
|
-
// If the DB UPDATE fails (UNIQUE conflict, etc.) we'd be left with the
|
|
751
|
-
// file at newPath but the row pointing at oldPath — in the web app the
|
|
752
|
-
// watcher would then unlink the row (losing tags/favorites). Roll the
|
|
753
|
-
// disk rename back so the system stays consistent. (Best-effort: if the
|
|
754
|
-
// original move went EXDEV the rollback path may also need a copy
|
|
755
|
-
// fallback, but in practice rollback is on the same device that just
|
|
756
|
-
// hosted the file.)
|
|
757
859
|
// Only touch content_class when dataDir is known — otherwise preserve the existing value rather than silently wiping it to null.
|
|
758
860
|
try {
|
|
759
861
|
// Read the record's gid (not recomputed) so a REMOTE file's move carries
|
|
@@ -790,12 +892,14 @@ export function moveFile(id, newPath, dataDir) {
|
|
|
790
892
|
})();
|
|
791
893
|
}
|
|
792
894
|
catch (e) {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
`
|
|
895
|
+
if (fileRecord.storage_type === "reference") {
|
|
896
|
+
try {
|
|
897
|
+
renameSync(newPath, oldPath);
|
|
898
|
+
}
|
|
899
|
+
catch (rollbackErr) {
|
|
900
|
+
throw new Error(`moveFile failed and rollback also failed; disk and DB are out of sync. ` +
|
|
901
|
+
`update error: ${e?.message ?? e}; rollback error: ${rollbackErr?.message ?? rollbackErr}`);
|
|
902
|
+
}
|
|
799
903
|
}
|
|
800
904
|
throw e;
|
|
801
905
|
}
|