weacpx 0.5.2 → 0.6.1

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.
Files changed (51) hide show
  1. package/README.md +15 -3
  2. package/dist/bridge/bridge-main.js +160 -4
  3. package/dist/channels/channel-scope.d.ts +8 -0
  4. package/dist/channels/types.d.ts +11 -0
  5. package/dist/channels/weixin-channel.d.ts +1 -0
  6. package/dist/cli.js +1115 -119
  7. package/dist/commands/command-hints.d.ts +11 -0
  8. package/dist/commands/command-list.d.ts +3 -0
  9. package/dist/commands/config-clone.d.ts +2 -0
  10. package/dist/commands/handlers/agent-handler.d.ts +6 -0
  11. package/dist/commands/handlers/config-handler.d.ts +5 -0
  12. package/dist/commands/handlers/later-handler.d.ts +21 -0
  13. package/dist/commands/handlers/orchestration-handler.d.ts +16 -0
  14. package/dist/commands/handlers/permission-handler.d.ts +9 -0
  15. package/dist/commands/handlers/session-handler.d.ts +37 -0
  16. package/dist/commands/handlers/workspace-handler.d.ts +8 -0
  17. package/dist/commands/help/help-registry.d.ts +4 -0
  18. package/dist/commands/help/help-types.d.ts +12 -0
  19. package/dist/commands/parse-command.d.ts +175 -0
  20. package/dist/commands/router-types.d.ts +144 -0
  21. package/dist/commands/workspace-name.d.ts +4 -0
  22. package/dist/commands/workspace-path.d.ts +4 -0
  23. package/dist/config/agent-templates.d.ts +4 -0
  24. package/dist/config/config-store.d.ts +13 -0
  25. package/dist/config/load-config.d.ts +10 -0
  26. package/dist/config/resolve-agent-command.d.ts +2 -0
  27. package/dist/formatting/render-text.d.ts +23 -0
  28. package/dist/orchestration/async-mutex.d.ts +4 -0
  29. package/dist/orchestration/build-coordinator-prompt.d.ts +66 -0
  30. package/dist/orchestration/orchestration-service.d.ts +471 -0
  31. package/dist/orchestration/progress-line-parser.d.ts +19 -0
  32. package/dist/orchestration/render-delegate-group-result.d.ts +6 -0
  33. package/dist/orchestration/render-delegate-question-package.d.ts +21 -0
  34. package/dist/orchestration/render-delegate-result.d.ts +2 -0
  35. package/dist/orchestration/task-watch-timeouts.d.ts +5 -0
  36. package/dist/plugin-api.d.ts +1 -0
  37. package/dist/scheduled/parse-later-time.d.ts +11 -0
  38. package/dist/scheduled/scheduled-render.d.ts +7 -0
  39. package/dist/scheduled/scheduled-service.d.ts +41 -0
  40. package/dist/scheduled/scheduled-types.d.ts +29 -0
  41. package/dist/sessions/session-service.d.ts +83 -0
  42. package/dist/state/state-store.d.ts +8 -0
  43. package/dist/state/types.d.ts +44 -0
  44. package/dist/transport/tool-event-mode.d.ts +14 -0
  45. package/dist/transport/types.d.ts +129 -0
  46. package/dist/util/path.d.ts +4 -0
  47. package/dist/util/sanitize.d.ts +10 -0
  48. package/dist/util/text.d.ts +3 -0
  49. package/dist/version.d.ts +2 -0
  50. package/dist/weixin/auth/accounts.d.ts +0 -1
  51. package/package.json +1 -1
@@ -0,0 +1,83 @@
1
+ import type { AppConfig } from "../config/types";
2
+ import { AsyncMutex } from "../orchestration/async-mutex";
3
+ import type { StateStore } from "../state/state-store";
4
+ import type { AppState } from "../state/types";
5
+ import type { AgentSession, ResolvedSession } from "../transport/types";
6
+ interface SessionListItem {
7
+ alias: string;
8
+ internalAlias: string;
9
+ agent: string;
10
+ workspace: string;
11
+ isCurrent: boolean;
12
+ }
13
+ interface NativeSessionAttachmentInput {
14
+ alias: string;
15
+ agent: string;
16
+ workspace: string;
17
+ transportSession: string;
18
+ transportAgentCommand?: string;
19
+ agentSessionId: string;
20
+ title?: string | null;
21
+ updatedAt?: string;
22
+ }
23
+ interface NativeSessionListInput {
24
+ agent: string;
25
+ workspace?: string;
26
+ cwd: string;
27
+ sessions: AgentSession[];
28
+ nextCursor?: string | null;
29
+ }
30
+ interface NativeSessionListResult {
31
+ agent: string;
32
+ workspace?: string;
33
+ cwd: string;
34
+ sessions: AgentSession[];
35
+ nextCursor?: string | null;
36
+ }
37
+ interface SessionServiceOptions {
38
+ stateMutex?: AsyncMutex;
39
+ now?: () => number;
40
+ }
41
+ export declare class SessionService {
42
+ private readonly config;
43
+ private readonly stateStore;
44
+ private readonly state;
45
+ private readonly stateMutex;
46
+ private readonly now;
47
+ constructor(config: AppConfig, stateStore: Pick<StateStore, "save">, state: AppState, options?: SessionServiceOptions);
48
+ createSession(alias: string, agent: string, workspace: string): Promise<ResolvedSession>;
49
+ /**
50
+ * All currently-known logical sessions resolved to transport sessions, deduped by
51
+ * transport session. Sessions whose agent or workspace is no longer registered are
52
+ * skipped (toResolvedSession would throw). Used by shutdown cleanup to reap warm
53
+ * acpx queue owners; never throws.
54
+ */
55
+ listAllResolvedSessions(): ResolvedSession[];
56
+ resolveSession(alias: string, agent: string, workspace: string, transportSession: string): ResolvedSession;
57
+ attachSession(alias: string, agent: string, workspace: string, transportSession: string, transportAgentCommand?: string): Promise<ResolvedSession>;
58
+ attachNativeSession(input: NativeSessionAttachmentInput): Promise<ResolvedSession>;
59
+ getSession(alias: string): Promise<ResolvedSession | null>;
60
+ getPreferredSessionForTransport(transportSession: string): Promise<ResolvedSession | null>;
61
+ findAttachedNativeSession(chatKey: string, agent: string, agentSessionId: string): Promise<ResolvedSession | null>;
62
+ useSession(chatKey: string, alias: string): Promise<void>;
63
+ resolveAliasForChat(chatKey: string, displayAlias: string): Promise<string>;
64
+ buildDefaultTransportSessionForChat(chatKey: string, displayAlias: string): string;
65
+ listInternalAliases(): string[];
66
+ setCurrentSessionMode(chatKey: string, modeId: string | undefined): Promise<void>;
67
+ setCurrentSessionReplyMode(chatKey: string, replyMode: "stream" | "final" | "verbose" | undefined): Promise<void>;
68
+ getCurrentSession(chatKey: string): Promise<ResolvedSession | null>;
69
+ listSessions(chatKey: string): Promise<SessionListItem[]>;
70
+ countAliasesSharingTransport(transportSession: string, excludeAlias?: string): number;
71
+ removeSession(alias: string): Promise<{
72
+ wasActive: boolean;
73
+ }>;
74
+ cacheNativeSessionList(chatKey: string, input: NativeSessionListInput): Promise<void>;
75
+ getNativeSessionList(chatKey: string, ttlMs?: number): Promise<NativeSessionListResult | null>;
76
+ private toResolvedSession;
77
+ setSessionTransportAgentCommand(alias: string, transportAgentCommand: string | undefined): Promise<void>;
78
+ private mutate;
79
+ private persist;
80
+ private createLogicalSession;
81
+ private validateSession;
82
+ }
83
+ export {};
@@ -0,0 +1,8 @@
1
+ import { type AppState } from "./types";
2
+ export declare function parseState(raw: unknown, path: string): AppState;
3
+ export declare class StateStore {
4
+ private readonly path;
5
+ constructor(path: string);
6
+ load(): Promise<AppState>;
7
+ save(state: AppState): Promise<void>;
8
+ }
@@ -0,0 +1,44 @@
1
+ import { type OrchestrationState } from "../orchestration/orchestration-types";
2
+ import type { ScheduledTaskRecord } from "../scheduled/scheduled-types";
3
+ export type LogicalSessionSource = "weacpx" | "agent-side";
4
+ export interface NativeSessionCacheEntry {
5
+ session_id: string;
6
+ cwd?: string;
7
+ title?: string | null;
8
+ updated_at?: string;
9
+ }
10
+ export interface NativeSessionListCacheRecord {
11
+ created_at: string;
12
+ agent: string;
13
+ workspace?: string;
14
+ cwd: string;
15
+ sessions: NativeSessionCacheEntry[];
16
+ next_cursor?: string | null;
17
+ }
18
+ export interface LogicalSession {
19
+ alias: string;
20
+ agent: string;
21
+ workspace: string;
22
+ transport_session: string;
23
+ source?: LogicalSessionSource;
24
+ agent_session_id?: string;
25
+ agent_session_title?: string;
26
+ agent_session_updated_at?: string;
27
+ attached_at?: string;
28
+ transport_agent_command?: string;
29
+ mode_id?: string;
30
+ reply_mode?: "stream" | "final" | "verbose";
31
+ created_at: string;
32
+ last_used_at: string;
33
+ }
34
+ export interface ChatContextState {
35
+ current_session: string;
36
+ }
37
+ export interface AppState {
38
+ sessions: Record<string, LogicalSession>;
39
+ chat_contexts: Record<string, ChatContextState>;
40
+ native_session_lists: Record<string, NativeSessionListCacheRecord>;
41
+ orchestration: OrchestrationState;
42
+ scheduled_tasks: Record<string, ScheduledTaskRecord>;
43
+ }
44
+ export declare function createEmptyState(): AppState;
@@ -0,0 +1,14 @@
1
+ import type { ToolUseEvent } from "../channels/types.js";
2
+ export type ToolEventMode = "text" | "structured" | "both";
3
+ /**
4
+ * Resolves the effective tool-event rendering mode.
5
+ *
6
+ * Resolution order (hard contract — preserves Phase 0 invariant):
7
+ * 1. Explicit `toolEventMode` always wins.
8
+ * 2. `onToolEvent` present → "structured" (structured consumer, suppress text tool calls).
9
+ * 3. Default → "text" (legacy text tool calls; no structured consumer).
10
+ */
11
+ export declare function resolveToolEventMode(input?: {
12
+ toolEventMode?: ToolEventMode;
13
+ onToolEvent?: (event: ToolUseEvent) => void | Promise<void>;
14
+ }): ToolEventMode;
@@ -0,0 +1,129 @@
1
+ import type { NonInteractivePermissions, PermissionMode } from "../config/types";
2
+ import type { QuotaManager } from "../weixin/messaging/quota-manager.js";
3
+ import type { ToolUseEvent } from "../channels/types.js";
4
+ import type { ToolEventMode } from "./tool-event-mode.js";
5
+ export type { ToolEventMode } from "./tool-event-mode.js";
6
+ export interface ReplyQuotaContext {
7
+ chatKey: string;
8
+ quota: QuotaManager;
9
+ }
10
+ export interface PromptMedia {
11
+ type: "image" | "audio" | "video" | "file";
12
+ filePath: string;
13
+ mimeType: string;
14
+ fileName?: string;
15
+ }
16
+ export interface PermissionPolicy {
17
+ permissionMode: PermissionMode;
18
+ nonInteractivePermissions: NonInteractivePermissions;
19
+ permissionPolicy?: string;
20
+ }
21
+ export interface ResolvedSession {
22
+ alias: string;
23
+ agent: string;
24
+ agentCommand?: string;
25
+ workspace: string;
26
+ transportSession: string;
27
+ source?: "weacpx" | "agent-side";
28
+ agentSessionId?: string;
29
+ agentSessionTitle?: string;
30
+ agentSessionUpdatedAt?: string;
31
+ attachedAt?: string;
32
+ mcpCoordinatorSession?: string;
33
+ mcpSourceHandle?: string;
34
+ modeId?: string;
35
+ replyMode?: "stream" | "final" | "verbose";
36
+ cwd: string;
37
+ /**
38
+ * True for a non-persisted, single-use session (e.g. a `/later` temp-mode
39
+ * scheduled run). Transport errors for such a session must not suggest
40
+ * `/session new`/`attach`, and missing-session recovery (which mutates
41
+ * persisted state by alias) does not apply.
42
+ */
43
+ transient?: boolean;
44
+ }
45
+ export interface AgentSession {
46
+ sessionId: string;
47
+ cwd?: string;
48
+ title?: string | null;
49
+ updatedAt?: string;
50
+ _meta?: Record<string, unknown>;
51
+ }
52
+ export interface AgentSessionListQuery {
53
+ agent: string;
54
+ agentCommand?: string;
55
+ cwd: string;
56
+ cursor?: string;
57
+ filterCwd?: string;
58
+ }
59
+ export interface AgentSessionListResult {
60
+ source: "agent";
61
+ sessions: AgentSession[];
62
+ cursor?: string;
63
+ nextCursor?: string | null;
64
+ cwd?: string;
65
+ }
66
+ export type EnsureSessionProgressStage = "spawn" | "initializing" | "ready";
67
+ export type EnsureSessionProgress = EnsureSessionProgressStage | {
68
+ kind: "note";
69
+ text: string;
70
+ };
71
+ export type PromptMediaInput = PromptMedia | PromptMedia[];
72
+ export interface PromptOptions {
73
+ onSegment?: (text: string) => void | Promise<void>;
74
+ /**
75
+ * Structured side-channel for tool calls. See `toolEventMode` for routing.
76
+ *
77
+ * Async semantics: callbacks are invoked in event order and serialized —
78
+ * each invocation is awaited before the next is dispatched. The transport
79
+ * waits for all callbacks to settle before resolving the prompt. If any
80
+ * invocation throws or returns a rejected promise, the prompt rejects
81
+ * with the first observed error (matching `onSegment` behavior).
82
+ */
83
+ onToolEvent?: (event: ToolUseEvent) => void | Promise<void>;
84
+ /**
85
+ * Optional structured side-channel for the agent's thinking/reasoning.
86
+ *
87
+ * Each acpx `agent_thought_chunk` is forwarded raw (no buffering, no
88
+ * paragraph splitting). Channels that register this callback opt in to
89
+ * receiving thoughts and are responsible for their own accumulation /
90
+ * rendering. When omitted, thought chunks are dropped at the transport
91
+ * boundary — the built-in WeChat channel does not register it.
92
+ *
93
+ * Async semantics match `onSegment`: invocations are serialized and the
94
+ * transport awaits all of them before resolving the prompt; the first
95
+ * error observed rejects the prompt.
96
+ */
97
+ onThought?: (chunk: string) => void | Promise<void>;
98
+ /**
99
+ * How tool_call / tool_call_update events are surfaced for this prompt.
100
+ *
101
+ * - "text" (default when no handler): legacy emoji-prefixed segments in the reply stream.
102
+ * - "structured" (default when a handler is provided): events go to `onToolEvent` only.
103
+ * - "both": events go to `onToolEvent` AND legacy text segments — useful for migration.
104
+ *
105
+ * Resolved at the transport boundary via `resolveToolEventMode`.
106
+ */
107
+ toolEventMode?: ToolEventMode;
108
+ media?: PromptMediaInput;
109
+ }
110
+ export interface SessionTransport {
111
+ ensureSession(session: ResolvedSession, onProgress?: (progress: EnsureSessionProgress) => void): Promise<void>;
112
+ tailSessionHistory(session: ResolvedSession, lines: number): Promise<{
113
+ text: string;
114
+ }>;
115
+ prompt(session: ResolvedSession, text: string, reply?: (text: string) => Promise<void>, replyContext?: ReplyQuotaContext, options?: PromptOptions): Promise<{
116
+ text: string;
117
+ }>;
118
+ setMode(session: ResolvedSession, modeId: string): Promise<void>;
119
+ cancel(session: ResolvedSession): Promise<{
120
+ cancelled: boolean;
121
+ message: string;
122
+ }>;
123
+ hasSession(session: ResolvedSession): Promise<boolean>;
124
+ listAgentSessions?(query: AgentSessionListQuery): Promise<AgentSessionListResult | undefined>;
125
+ resumeAgentSession?(session: ResolvedSession, agentSessionId: string): Promise<void>;
126
+ removeSession?(session: ResolvedSession): Promise<void>;
127
+ updatePermissionPolicy?(policy: PermissionPolicy): Promise<void>;
128
+ dispose?(): Promise<void>;
129
+ }
@@ -0,0 +1,4 @@
1
+ export declare function normalizePath(input: string): string;
2
+ export declare function basenameForPath(input: string): string;
3
+ export declare function isSamePath(left: string, right: string): boolean;
4
+ export declare function isWindowsLikePath(input: string): boolean;
@@ -0,0 +1,10 @@
1
+ export interface SanitizeOptions {
2
+ allow?: RegExp;
3
+ deny?: RegExp;
4
+ replacement?: string;
5
+ collapse?: boolean;
6
+ trim?: boolean;
7
+ lowercase?: boolean;
8
+ fallback?: string;
9
+ }
10
+ export declare function sanitizeString(input: string, options?: SanitizeOptions): string;
@@ -0,0 +1,3 @@
1
+ export declare function truncateText(text: string, maxLength: number, ellipsis?: string): string;
2
+ export declare function escapeForDoubleQuotes(input: string): string;
3
+ export declare function quoteIfNeeded(input: string): string;
package/dist/version.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export declare function readVersion(moduleUrl?: string): string;
2
+ /** weacpx 核心版本,派生自 package.json(经 readVersion 动态读取,无硬编码漂移)。 */
3
+ export declare const WEACPX_CORE_VERSION: string;
@@ -1,6 +1,5 @@
1
1
  export declare const DEFAULT_BASE_URL = "https://ilinkai.weixin.qq.com";
2
2
  export declare const CDN_BASE_URL = "https://novac2c.cdn.weixin.qq.com/c2c";
3
- /** Normalize an account ID to a filesystem-safe string. */
4
3
  export declare function normalizeAccountId(raw: string): string;
5
4
  /**
6
5
  * Pattern-based reverse of normalizeWeixinAccountId for known weixin ID suffixes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weacpx",
3
- "version": "0.5.2",
3
+ "version": "0.6.1",
4
4
  "description": "使用微信 ClawBot 随时随地通过 `acpx` 控制 Claude Code、Codex 等 Agents。",
5
5
  "keywords": [
6
6
  "acpx",