@unieai/rabi-file-reference 0.2.1-rc.3 → 0.2.2-rc.5
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/package.json +6 -3
- package/src/grammar.ts +55 -0
- package/src/index.ts +45 -0
- package/src/types.ts +13 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-file-reference",
|
|
3
3
|
"description": "File-reference discovery contract and shared @file grammar",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2-rc.5",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -28,11 +28,14 @@
|
|
|
28
28
|
"lib/index.js",
|
|
29
29
|
"lib/types/**/*.js",
|
|
30
30
|
"lib/types/**/*.d.ts",
|
|
31
|
+
"lib/types/**/*.d.ts.map",
|
|
32
|
+
"lib/**/*.js.map",
|
|
33
|
+
"src",
|
|
31
34
|
"README.md"
|
|
32
35
|
],
|
|
33
36
|
"license": "MIT",
|
|
34
37
|
"peerDependencies": {
|
|
35
|
-
"@unieai/rabi-agent": "0.2.
|
|
36
|
-
"@unieai/cordis": "4.0
|
|
38
|
+
"@unieai/rabi-agent": "0.2.2-rc.5",
|
|
39
|
+
"@unieai/cordis": "4.1.0"
|
|
37
40
|
}
|
|
38
41
|
}
|
package/src/grammar.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe `@file` token grammar shared by terminal and web clients.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-file-reference/grammar
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { FileReferenceCandidate } from './types.ts'
|
|
8
|
+
|
|
9
|
+
/** Active `@` token ending at the editor cursor. */
|
|
10
|
+
export interface ActiveAtToken {
|
|
11
|
+
/** Complete token replaced when the user accepts a completion. */
|
|
12
|
+
prefix: string
|
|
13
|
+
/** Path query after `@` or `@"`. */
|
|
14
|
+
query: string
|
|
15
|
+
/** Whether the user opened a quoted path. */
|
|
16
|
+
quoted: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Extract an `@path` or `@"path with spaces` token at the cursor. An `@`
|
|
21
|
+
* inside another token, such as an email address, is not a completion trigger.
|
|
22
|
+
* @param line - current editor line.
|
|
23
|
+
* @param cursorCol - cursor column within that line.
|
|
24
|
+
* @returns the active token, or `undefined` outside an `@` token.
|
|
25
|
+
*/
|
|
26
|
+
export function activeAtToken(line: string, cursorCol: number): ActiveAtToken | undefined {
|
|
27
|
+
const beforeCursor = line.slice(0, cursorCol)
|
|
28
|
+
const quoted = /(?:^|\s)(@"([^"]*))$/u.exec(beforeCursor)
|
|
29
|
+
if (quoted?.[1] !== undefined && quoted[2] !== undefined) {
|
|
30
|
+
return { prefix: quoted[1], query: quoted[2], quoted: true }
|
|
31
|
+
}
|
|
32
|
+
const plain = /(?:^|\s)(@([^\s]*))$/u.exec(beforeCursor)
|
|
33
|
+
if (plain?.[1] === undefined || plain[2] === undefined) return undefined
|
|
34
|
+
return { prefix: plain[1], query: plain[2], quoted: false }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Format a selected path as prompt text. Whitespace uses the quoted
|
|
39
|
+
* `@"path"` grammar; a quoted directory keeps that quote open after its
|
|
40
|
+
* trailing slash so completion can descend another level.
|
|
41
|
+
* @param candidate - selected file or directory.
|
|
42
|
+
* @param preserveQuote - retain an explicitly opened quote even when unnecessary.
|
|
43
|
+
* @returns the insertion value, or `undefined` for a path the editor grammar cannot represent safely.
|
|
44
|
+
*/
|
|
45
|
+
export function formatFileMention(
|
|
46
|
+
candidate: FileReferenceCandidate,
|
|
47
|
+
preserveQuote: boolean,
|
|
48
|
+
): string | undefined {
|
|
49
|
+
const path = candidate.kind === 'directory' ? `${candidate.path}/` : candidate.path
|
|
50
|
+
if (/[\u0000-\u001f\u007f-\u009f"]/u.test(path)) return undefined
|
|
51
|
+
const quoted = preserveQuote || /\s/u.test(path)
|
|
52
|
+
if (!quoted) return `@${path}`
|
|
53
|
+
if (candidate.kind === 'directory') return `@"${path}`
|
|
54
|
+
return `@"${path}"`
|
|
55
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File-reference discovery seam shared by host-backed user interfaces.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-file-reference
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Service, type Context } from '@unieai/cordis'
|
|
8
|
+
import type { Agent } from '@unieai/rabi-agent'
|
|
9
|
+
|
|
10
|
+
import type { FileReferenceCandidate } from './types.ts'
|
|
11
|
+
|
|
12
|
+
export { activeAtToken, formatFileMention } from './grammar.ts'
|
|
13
|
+
export type { ActiveAtToken } from './grammar.ts'
|
|
14
|
+
export type { FileReferenceCandidate } from './types.ts'
|
|
15
|
+
|
|
16
|
+
/** Model guidance for path-only references selected by a user interface. */
|
|
17
|
+
export const FILE_REFERENCE_PROMPT = 'Tokens prefixed with @ are paths the user explicitly referenced. Relative paths resolve from the workspace root; absolute paths identify files or directories on the host. A trailing slash marks a directory: list it when its contents matter. Anything else is a file: use the read tool when its contents are needed, and do not claim to have inspected it before reading. @"..." quotes a path containing spaces.'
|
|
18
|
+
|
|
19
|
+
declare module '@unieai/cordis' {
|
|
20
|
+
interface Context {
|
|
21
|
+
fileReferences: FileReferenceService
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Host capability for cancellable file-reference discovery. */
|
|
26
|
+
export abstract class FileReferenceService extends Service {
|
|
27
|
+
constructor(ctx: Context) {
|
|
28
|
+
super(ctx, 'fileReferences')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* List file and directory candidates for one agent's working directory.
|
|
33
|
+
* @param agent - target agent whose session cwd bounds discovery.
|
|
34
|
+
* @param query - path text following `@` or `@"`.
|
|
35
|
+
* @param signal - caller cancellation.
|
|
36
|
+
* @returns deterministic path-only candidates.
|
|
37
|
+
*/
|
|
38
|
+
abstract list(
|
|
39
|
+
agent: Agent,
|
|
40
|
+
query: string,
|
|
41
|
+
signal: AbortSignal,
|
|
42
|
+
): Promise<FileReferenceCandidate[]>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default FileReferenceService
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public file-reference discovery records. This module contains types only so
|
|
3
|
+
* generated Remote clients can consume it without Host runtime code.
|
|
4
|
+
* @module @unieai/rabi-file-reference/types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** One path-only completion candidate inside the target session cwd. */
|
|
8
|
+
export interface FileReferenceCandidate {
|
|
9
|
+
/** User-facing path accepted by normal prompts and filesystem tools. */
|
|
10
|
+
path: string
|
|
11
|
+
/** Directories keep completion open; files finish the mention. */
|
|
12
|
+
kind: 'file' | 'directory'
|
|
13
|
+
}
|