@unieai/rabi-file-reference 0.0.0-stage → 0.2.1-rc.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
- # Temporary Holding Version
1
+ # @unieai/rabi-file-reference
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ File-reference discovery contract and shared @file grammar
4
+
5
+ Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
6
+ not meant to be used on its own.
7
+
8
+ See LICENSE for the license and copyright of this package.
package/lib/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import { Service } from "@unieai/cordis";
2
+ //#region lib/types/grammar.js
3
+ /**
4
+ * Browser-safe `@file` token grammar shared by terminal and web clients.
5
+ *
6
+ * @module @unieai/rabi-file-reference/grammar
7
+ */
8
+ /**
9
+ * Extract an `@path` or `@"path with spaces` token at the cursor. An `@`
10
+ * inside another token, such as an email address, is not a completion trigger.
11
+ * @param line - current editor line.
12
+ * @param cursorCol - cursor column within that line.
13
+ * @returns the active token, or `undefined` outside an `@` token.
14
+ */
15
+ function activeAtToken(line, cursorCol) {
16
+ const beforeCursor = line.slice(0, cursorCol);
17
+ const quoted = /(?:^|\s)(@"([^"]*))$/u.exec(beforeCursor);
18
+ if (quoted?.[1] !== void 0 && quoted[2] !== void 0) return {
19
+ prefix: quoted[1],
20
+ query: quoted[2],
21
+ quoted: true
22
+ };
23
+ const plain = /(?:^|\s)(@([^\s]*))$/u.exec(beforeCursor);
24
+ if (plain?.[1] === void 0 || plain[2] === void 0) return void 0;
25
+ return {
26
+ prefix: plain[1],
27
+ query: plain[2],
28
+ quoted: false
29
+ };
30
+ }
31
+ /**
32
+ * Format a selected path as prompt text. Whitespace uses the quoted
33
+ * `@"path"` grammar; a quoted directory keeps that quote open after its
34
+ * trailing slash so completion can descend another level.
35
+ * @param candidate - selected file or directory.
36
+ * @param preserveQuote - retain an explicitly opened quote even when unnecessary.
37
+ * @returns the insertion value, or `undefined` for a path the editor grammar cannot represent safely.
38
+ */
39
+ function formatFileMention(candidate, preserveQuote) {
40
+ const path = candidate.kind === "directory" ? `${candidate.path}/` : candidate.path;
41
+ if (/[\u0000-\u001f\u007f-\u009f"]/u.test(path)) return void 0;
42
+ if (!(preserveQuote || /\s/u.test(path))) return `@${path}`;
43
+ if (candidate.kind === "directory") return `@"${path}`;
44
+ return `@"${path}"`;
45
+ }
46
+ //#endregion
47
+ //#region lib/types/index.js
48
+ /**
49
+ * File-reference discovery seam shared by host-backed user interfaces.
50
+ *
51
+ * @module @unieai/rabi-file-reference
52
+ */
53
+ /** Model guidance for path-only references selected by a user interface. */
54
+ 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.";
55
+ /** Host capability for cancellable file-reference discovery. */
56
+ var FileReferenceService = class extends Service {
57
+ constructor(ctx) {
58
+ super(ctx, "fileReferences");
59
+ }
60
+ };
61
+ //#endregion
62
+ export { FILE_REFERENCE_PROMPT, FileReferenceService, FileReferenceService as default, activeAtToken, formatFileMention };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Browser-safe `@file` token grammar shared by terminal and web clients.
3
+ *
4
+ * @module @unieai/rabi-file-reference/grammar
5
+ */
6
+ import type { FileReferenceCandidate } from './types.ts';
7
+ /** Active `@` token ending at the editor cursor. */
8
+ export interface ActiveAtToken {
9
+ /** Complete token replaced when the user accepts a completion. */
10
+ prefix: string;
11
+ /** Path query after `@` or `@"`. */
12
+ query: string;
13
+ /** Whether the user opened a quoted path. */
14
+ quoted: boolean;
15
+ }
16
+ /**
17
+ * Extract an `@path` or `@"path with spaces` token at the cursor. An `@`
18
+ * inside another token, such as an email address, is not a completion trigger.
19
+ * @param line - current editor line.
20
+ * @param cursorCol - cursor column within that line.
21
+ * @returns the active token, or `undefined` outside an `@` token.
22
+ */
23
+ export declare function activeAtToken(line: string, cursorCol: number): ActiveAtToken | undefined;
24
+ /**
25
+ * Format a selected path as prompt text. Whitespace uses the quoted
26
+ * `@"path"` grammar; a quoted directory keeps that quote open after its
27
+ * trailing slash so completion can descend another level.
28
+ * @param candidate - selected file or directory.
29
+ * @param preserveQuote - retain an explicitly opened quote even when unnecessary.
30
+ * @returns the insertion value, or `undefined` for a path the editor grammar cannot represent safely.
31
+ */
32
+ export declare function formatFileMention(candidate: FileReferenceCandidate, preserveQuote: boolean): string | undefined;
33
+ //# sourceMappingURL=grammar.d.ts.map
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Browser-safe `@file` token grammar shared by terminal and web clients.
3
+ *
4
+ * @module @unieai/rabi-file-reference/grammar
5
+ */
6
+ /**
7
+ * Extract an `@path` or `@"path with spaces` token at the cursor. An `@`
8
+ * inside another token, such as an email address, is not a completion trigger.
9
+ * @param line - current editor line.
10
+ * @param cursorCol - cursor column within that line.
11
+ * @returns the active token, or `undefined` outside an `@` token.
12
+ */
13
+ export function activeAtToken(line, cursorCol) {
14
+ const beforeCursor = line.slice(0, cursorCol);
15
+ const quoted = /(?:^|\s)(@"([^"]*))$/u.exec(beforeCursor);
16
+ if (quoted?.[1] !== undefined && quoted[2] !== undefined) {
17
+ return { prefix: quoted[1], query: quoted[2], quoted: true };
18
+ }
19
+ const plain = /(?:^|\s)(@([^\s]*))$/u.exec(beforeCursor);
20
+ if (plain?.[1] === undefined || plain[2] === undefined)
21
+ return undefined;
22
+ return { prefix: plain[1], query: plain[2], quoted: false };
23
+ }
24
+ /**
25
+ * Format a selected path as prompt text. Whitespace uses the quoted
26
+ * `@"path"` grammar; a quoted directory keeps that quote open after its
27
+ * trailing slash so completion can descend another level.
28
+ * @param candidate - selected file or directory.
29
+ * @param preserveQuote - retain an explicitly opened quote even when unnecessary.
30
+ * @returns the insertion value, or `undefined` for a path the editor grammar cannot represent safely.
31
+ */
32
+ export function formatFileMention(candidate, preserveQuote) {
33
+ const path = candidate.kind === 'directory' ? `${candidate.path}/` : candidate.path;
34
+ if (/[\u0000-\u001f\u007f-\u009f"]/u.test(path))
35
+ return undefined;
36
+ const quoted = preserveQuote || /\s/u.test(path);
37
+ if (!quoted)
38
+ return `@${path}`;
39
+ if (candidate.kind === 'directory')
40
+ return `@"${path}`;
41
+ return `@"${path}"`;
42
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * File-reference discovery seam shared by host-backed user interfaces.
3
+ *
4
+ * @module @unieai/rabi-file-reference
5
+ */
6
+ import { Service, type Context } from '@unieai/cordis';
7
+ import type { Agent } from '@unieai/rabi-agent';
8
+ import type { FileReferenceCandidate } from './types.ts';
9
+ export { activeAtToken, formatFileMention } from './grammar.ts';
10
+ export type { ActiveAtToken } from './grammar.ts';
11
+ export type { FileReferenceCandidate } from './types.ts';
12
+ /** Model guidance for path-only references selected by a user interface. */
13
+ export declare 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.";
14
+ declare module '@unieai/cordis' {
15
+ interface Context {
16
+ fileReferences: FileReferenceService;
17
+ }
18
+ }
19
+ /** Host capability for cancellable file-reference discovery. */
20
+ export declare abstract class FileReferenceService extends Service {
21
+ constructor(ctx: Context);
22
+ /**
23
+ * List file and directory candidates for one agent's working directory.
24
+ * @param agent - target agent whose session cwd bounds discovery.
25
+ * @param query - path text following `@` or `@"`.
26
+ * @param signal - caller cancellation.
27
+ * @returns deterministic path-only candidates.
28
+ */
29
+ abstract list(agent: Agent, query: string, signal: AbortSignal): Promise<FileReferenceCandidate[]>;
30
+ }
31
+ export default FileReferenceService;
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * File-reference discovery seam shared by host-backed user interfaces.
3
+ *
4
+ * @module @unieai/rabi-file-reference
5
+ */
6
+ import { Service } from '@unieai/cordis';
7
+ export { activeAtToken, formatFileMention } from "./grammar.js";
8
+ /** Model guidance for path-only references selected by a user interface. */
9
+ 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.';
10
+ /** Host capability for cancellable file-reference discovery. */
11
+ export class FileReferenceService extends Service {
12
+ constructor(ctx) {
13
+ super(ctx, 'fileReferences');
14
+ }
15
+ }
16
+ export default FileReferenceService;
@@ -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
+ /** One path-only completion candidate inside the target session cwd. */
7
+ export interface FileReferenceCandidate {
8
+ /** User-facing path accepted by normal prompts and filesystem tools. */
9
+ path: string;
10
+ /** Directories keep completion open; files finish the mention. */
11
+ kind: 'file' | 'directory';
12
+ }
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,6 @@
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
+ export {};
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@unieai/rabi-file-reference",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "File-reference discovery contract and shared @file grammar",
4
+ "version": "0.2.1-rc.3",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "lib/index.js",
10
+ "types": "lib/types/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/types/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./grammar": {
17
+ "types": "./lib/types/grammar.d.ts",
18
+ "default": "./lib/types/grammar.js"
19
+ },
20
+ "./types": {
21
+ "types": "./lib/types/types.d.ts",
22
+ "default": "./lib/types/types.js"
23
+ },
24
+ "./src/*": "./src/*",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "lib/index.js",
29
+ "lib/types/**/*.js",
30
+ "lib/types/**/*.d.ts",
31
+ "README.md"
32
+ ],
33
+ "license": "MIT",
34
+ "peerDependencies": {
35
+ "@unieai/rabi-agent": "0.2.1-rc.3",
36
+ "@unieai/cordis": "4.0.5"
37
+ }
38
+ }