Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/moss-repo-indexer-js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
dist/
.env
*.log
.DS_Store
62 changes: 62 additions & 0 deletions packages/moss-repo-indexer-js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# @moss-tools/repo-indexer

Clone or walk a repository, chunk **code** and **Markdown**, and build a searchable Moss index.

TypeScript twin of the Python package [`moss-repo-indexer`](../moss-repo-indexer). Both emit the same `DocumentInfo` metadata contract.

## Install

```bash
npm install @moss-tools/repo-indexer @moss-dev/moss
```

## Usage

```ts
import { buildDocuments, sync } from '@moss-tools/repo-indexer'

const docs = buildDocuments('./my-repo', { repoName: 'my-repo' })

const dry = await sync({
source: './my-repo', // or https://github.com/org/repo.git
creds: {
projectId: process.env.MOSS_PROJECT_ID!,
projectKey: process.env.MOSS_PROJECT_KEY!,
indexName: 'my-codebase',
},
dryRun: true,
})

const uploaded = await sync({
source: './my-repo',
creds: {
projectId: process.env.MOSS_PROJECT_ID!,
projectKey: process.env.MOSS_PROJECT_KEY!,
indexName: 'my-codebase',
},
})

// Destructive recreate (opt-in)
await sync({
source: './my-repo',
creds: {
projectId: process.env.MOSS_PROJECT_ID!,
projectKey: process.env.MOSS_PROJECT_KEY!,
indexName: 'my-codebase',
},
replace: true,
})
```

## Document metadata contract

Same keys as the Python package (`path`, `language`, `type`, `start_line`, `end_line`, `symbol`, `repo`, `ref`, `title`, `navigation`). See `metadataContract()`.

## Scripts

```bash
pnpm install
pnpm test
pnpm build
pnpm example:dry-run
```
32 changes: 32 additions & 0 deletions packages/moss-repo-indexer-js/example/dry-run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Dry-run a local path into Moss document chunks (no upload).
*
* pnpm example:dry-run
* pnpm exec tsx example/dry-run.ts /path/to/repo
*/
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { sync } from '../src/index.js'

const here = path.dirname(fileURLToPath(import.meta.url))
const source = process.argv[2] ?? path.resolve(here, '..')

const result = await sync({
source,
creds: {
projectId: 'unused-in-dry-run',
projectKey: 'unused-in-dry-run',
indexName: 'repo-dry-run',
},
dryRun: true,
})

console.log(`repo=${result.repoName} chunks=${result.documents.length} dryRun=${result.dryRun}`)
for (const doc of result.documents.slice(0, 5)) {
const meta = doc.metadata ?? {}
console.log(`- ${doc.id} [${meta.type}] ${meta.navigation}`)
}
if (result.documents.length > 5) {
console.log(`... and ${result.documents.length - 5} more`)
}
Loading
Loading