You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/08/20 09:39:44 UTC

(maka) branch main updated: refactor(cli): remove skill-token module and integrate functionality into pi-tui-pickers (#3267)

This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/maka.git


The following commit(s) were added to refs/heads/main by this push:
     new 9d4392c85 refactor(cli): remove skill-token module and integrate functionality into pi-tui-pickers (#3267)
9d4392c85 is described below

commit 9d4392c854ac63e1b5137b925c762d270b1fa72b
Author: Sean <11...@users.noreply.github.com>
AuthorDate: Thu Aug 20 17:39:40 2026 +0800

    refactor(cli): remove skill-token module and integrate functionality into pi-tui-pickers (#3267)
    
    This commit deletes the skill-token module and moves the skill invocation prefix logic into pi-tui-pickers. The skill invocation prefix function is now defined directly in pi-tui-pickers, streamlining the codebase. Additionally, the import statement for SKILL_INVOCATION_TOKEN_SOURCE has been updated in skill-highlight-editor to reflect the new structure.
---
 packages/cli/src/pi-tui-pickers.ts         | 13 +++-
 packages/cli/src/skill-highlight-editor.ts |  2 +-
 packages/cli/src/skill-token.ts            | 99 ------------------------------
 3 files changed, 13 insertions(+), 101 deletions(-)

diff --git a/packages/cli/src/pi-tui-pickers.ts b/packages/cli/src/pi-tui-pickers.ts
index 91d8e6b9b..1ef0f38a8 100644
--- a/packages/cli/src/pi-tui-pickers.ts
+++ b/packages/cli/src/pi-tui-pickers.ts
@@ -21,7 +21,6 @@ import type { ThinkingLevel } from '@maka/core/model-thinking';
 import type { InvocableSkillEntry } from '@maka/runtime/skill-invocation';
 import { PROVIDER_DEFAULTS, type ModelInfo, type ProviderType } from '@maka/core/llm-connections';
 import type { ModelChoice, OnboardingProviderEntry } from './pi-tui-contracts.js';
-import { skillInvocationPrefixAt } from './skill-token.js';
 import { ansi, editorTheme, selectListTheme, stripAnsi } from './tui-ansi.js';
 
 export class MakaAutocompleteProvider implements AutocompleteProvider {
@@ -266,6 +265,18 @@ function slashCommandPrefix(lines: string[], cursorLine: number, cursorCol: numb
     : null;
 }
 
+function skillInvocationPrefixAt(
+  lines: string[],
+  cursorLine: number,
+  cursorCol: number,
+): { prefix: string; query: string } | null {
+  const currentLine = lines[cursorLine] || '';
+  const beforeCursor = currentLine.slice(0, cursorCol);
+  const match = /(?:^|\s)(\/skill:([A-Za-z0-9._-]*))$/.exec(beforeCursor);
+  if (!match) return null;
+  return { prefix: match[1], query: match[2] };
+}
+
 // A `/`-token that begins mid-message (after whitespace) on the first line,
 // excluding the `/skill:` form (handled by skillInvocationPrefixAt above) and
 // line-start (handled by slashCommandPrefix). Used to offer `/skill:xxx`
diff --git a/packages/cli/src/skill-highlight-editor.ts b/packages/cli/src/skill-highlight-editor.ts
index 840a2463a..b414093d4 100644
--- a/packages/cli/src/skill-highlight-editor.ts
+++ b/packages/cli/src/skill-highlight-editor.ts
@@ -1,6 +1,6 @@
 import { Editor } from '@earendil-works/pi-tui';
+import { SKILL_INVOCATION_TOKEN_SOURCE } from '@maka/core/skill-invocation-token';
 import { ansi } from './tui-ansi.js';
-import { SKILL_INVOCATION_TOKEN_SOURCE } from './skill-token.js';
 
 // A `/`-token that begins mid-message (after whitespace). Only `/skill:` has
 // semantic value mid-message (a parseable invocation token); plain commands
diff --git a/packages/cli/src/skill-token.ts b/packages/cli/src/skill-token.ts
deleted file mode 100644
index 517103849..000000000
--- a/packages/cli/src/skill-token.ts
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * `/skill:<name>` invocation tokens (issue #1148) — the TUI's serialization
- * of an explicit skill invocation. A token is valid anywhere in the input as
- * long as it starts the text or follows whitespace (so paths and URLs never
- * produce false positives); `<name>` uses the skill id charset, and
- * resolution downstream matches by id first, then by display name.
- *
- * This module owns the TUI's use of the token syntax: parsing for submit-time
- * injection, stripping for message composition, and the line pattern the
- * editor highlighter and autocomplete run per line. The grammar itself is
- * `SKILL_INVOCATION_TOKEN_SOURCE` in `@maka/core`, shared with the Desktop
- * composer; loading/gating/composing lives in `@maka/runtime`'s
- * skill-invocation module.
- */
-
-import { SKILL_INVOCATION_TOKEN_SOURCE } from '@maka/core/skill-invocation-token';
-
-export interface SkillInvocationToken {
-  /** The id-or-name captured after the `/skill:` prefix, exactly as typed. */
-  name: string;
-  /** Start offset of the full token (including the prefix) in the source text. */
-  start: number;
-  /** End offset (exclusive) of the full token in the source text. */
-  end: number;
-}
-
-/** Re-exported so per-line consumers in this package keep one import site. */
-export { SKILL_INVOCATION_TOKEN_SOURCE };
-
-const TOKEN_PATTERN = new RegExp(SKILL_INVOCATION_TOKEN_SOURCE, 'g');
-
-/**
- * Parse the distinct invocation tokens in `text`, in first-appearance order,
- * deduped case-insensitively by name. Positions point at the first
- * occurrence of each name.
- */
-export function parseSkillInvocationTokens(text: string): SkillInvocationToken[] {
-  const tokens: SkillInvocationToken[] = [];
-  const seen = new Set<string>();
-  for (const match of text.matchAll(TOKEN_PATTERN)) {
-    const name = match[1];
-    const key = name.toLowerCase();
-    if (seen.has(key)) continue;
-    seen.add(key);
-    const start = match.index;
-    tokens.push({ name, start, end: start + match[0].length });
-  }
-  return tokens;
-}
-
-/**
- * Remove every occurrence of the named tokens from `text`. Only lines that
- * actually contained a removed token are tidied (adjacent whitespace
- * collapsed around the hole; the line is dropped if left empty) — every
- * other line passes through byte-identical, so code blocks and intentional
- * spacing elsewhere are untouched. The result is NOT global-trimmed: leading
- * or trailing whitespace that is not itself a removed-token line is kept so
- * indented code/YAML after a token-only line survives.
- */
-export function stripSkillInvocationTokens(text: string, names: ReadonlySet<string>): string {
-  const pattern = new RegExp(SKILL_INVOCATION_TOKEN_SOURCE, 'g');
-  const lines = text.split('\n');
-  const out: string[] = [];
-  for (const line of lines) {
-    let touched = false;
-    const stripped = line.replace(pattern, (whole, name: string) => {
-      if (!names.has(name.toLowerCase())) return whole;
-      touched = true;
-      return '';
-    });
-    if (!touched) {
-      out.push(line);
-      continue;
-    }
-    // Collapse spaces left by the token hole on this line only. Untouched
-    // lines (including indented code after a token-only line) stay byte-identical
-    // because we never global-trim the joined result.
-    const tidied = stripped.replace(/[ \t]+/g, ' ').trim();
-    if (tidied.length > 0) out.push(tidied);
-  }
-  return out.join('\n');
-}
-
-/**
- * The token prefix directly before the cursor on the cursor's own line, if
- * any — the autocomplete trigger shape. `query` is the partial name typed so
- * far (may be empty); `prefix` is the full `/skill:<query>` span to replace.
- */
-export function skillInvocationPrefixAt(
-  lines: string[],
-  cursorLine: number,
-  cursorCol: number,
-): { prefix: string; query: string } | null {
-  const currentLine = lines[cursorLine] || '';
-  const beforeCursor = currentLine.slice(0, cursorCol);
-  const match = /(?:^|\s)(\/skill:([A-Za-z0-9._-]*))$/.exec(beforeCursor);
-  if (!match) return null;
-  return { prefix: match[1], query: match[2] };
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org