dsh-mishu 0.5.0 → 0.5.4

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.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Restarting DSH after plugins were reinstalled or upgraded.
3
+ *
4
+ * In the desktop app, DSH runs as a child of the app's main process
5
+ * (Electron as Node, `ELECTRON_RUN_AS_NODE=1`). The `dsh` command runs on
6
+ * the same binary the same way, so the test is the parent: only when the
7
+ * parent process IS this app binary is there an app to restart (from a
8
+ * terminal the parent is a shell, and `__CFBundleIdentifier` names the
9
+ * terminal app — never trusted). A restart asks the app to
10
+ * quit the normal way — so it still asks first when a task is running — and
11
+ * opens it again once it is gone. That is done by a small detached helper,
12
+ * because this process ends with the app.
13
+ *
14
+ * macOS AppleScript `quit`, then `open -b <bundle id>` (tested)
15
+ * Windows `taskkill /PID` without /F (a close request), then the app again
16
+ * Linux SIGTERM to the app, then the app again
17
+ *
18
+ * DSH started with the `dsh` command is not restarted from here: its web
19
+ * address (with a new sign-in token) is printed in that terminal, which a
20
+ * detached replacement could not reach. The page says what to do instead.
21
+ */
22
+ import { type Bi } from './i18n.ts';
23
+ export type RestartPlan = {
24
+ kind: 'macos-app';
25
+ bundleId: string;
26
+ appPid: number;
27
+ } | {
28
+ kind: 'desktop-app';
29
+ platform: 'win32' | 'linux';
30
+ exe: string;
31
+ appPid: number;
32
+ } | {
33
+ kind: 'none';
34
+ why: Bi;
35
+ };
36
+ export interface ProcessFacts {
37
+ env: NodeJS.ProcessEnv;
38
+ platform: NodeJS.Platform;
39
+ execPath: string;
40
+ ppid: number;
41
+ electron: string | undefined;
42
+ /** The parent process's executable, when it can be read. */
43
+ parentExe: string | undefined;
44
+ /** macOS: CFBundleIdentifier from the Info.plist of the .app holding `execPath`. */
45
+ bundleId: string | undefined;
46
+ }
47
+ /** How DSH can be restarted from here, or why it cannot. */
48
+ export declare function restartPlan(facts?: ProcessFacts): RestartPlan;
49
+ /** The programs the macOS helper runs; tests point them at stand-ins. */
50
+ export interface MacTools {
51
+ osascript: string;
52
+ open: string;
53
+ }
54
+ /**
55
+ * Source of the detached helper: ask the app to quit, wait until it is gone
56
+ * (giving up quietly when you cancel the quit), open it again, and check it
57
+ * came back. Every step is noted in `log`, the only account of a restart
58
+ * once this process is gone.
59
+ *
60
+ * The helper itself runs as Node (`ELECTRON_RUN_AS_NODE=1`), and whatever it
61
+ * launches inherits its environment — `open` included ("Opened applications
62
+ * inherit environment variables", open(1)). So the app is always started
63
+ * without that variable; with it, the app starts as bare Node and exits.
64
+ */
65
+ export declare function restartHelperSource(plan: Exclude<RestartPlan, {
66
+ kind: 'none';
67
+ }>, log: string, tools?: MacTools): string;
68
+ /** Start the helper and return where it logs. Runs with this process's Node (Electron as Node in the app). */
69
+ export declare function scheduleRestart(plan: Exclude<RestartPlan, {
70
+ kind: 'none';
71
+ }>): {
72
+ log: string;
73
+ };
@@ -10,20 +10,30 @@
10
10
  * stored under the service name "dsh-mishu". When no keychain is available,
11
11
  * `secretFromEnv` is the documented fallback.
12
12
  */
13
+ import { type Bi } from './i18n.ts';
13
14
  export declare const SERVICE = "dsh-mishu";
15
+ /** Whether secrets can be kept here, and if not, why and what to do. */
16
+ export type SecretStatus = {
17
+ available: true;
18
+ } | {
19
+ available: false;
20
+ why: Bi;
21
+ };
14
22
  export interface SecretStore {
15
23
  /** Where secrets go, for the settings page ("macOS 钥匙串"). */
16
24
  readonly kind: 'macos' | 'windows' | 'linux' | 'memory';
17
- available(): Promise<boolean>;
25
+ status(): Promise<SecretStatus>;
18
26
  get(account: string): Promise<string | undefined>;
19
27
  set(account: string, secret: string): Promise<void>;
20
28
  delete(account: string): Promise<void>;
21
29
  }
22
- /** For tests: secrets in memory only. */
30
+ /** For tests: secrets in memory only; `unavailable` plays a machine without a keychain. */
23
31
  export declare class MemorySecrets implements SecretStore {
24
32
  readonly kind: "memory";
25
33
  private readonly map;
26
- available(): Promise<boolean>;
34
+ private readonly unavailable;
35
+ constructor(unavailable?: Bi);
36
+ status(): Promise<SecretStatus>;
27
37
  get(account: string): Promise<string | undefined>;
28
38
  set(account: string, secret: string): Promise<void>;
29
39
  delete(account: string): Promise<void>;
@@ -9,7 +9,7 @@ import type { MarkReadMode } from './github/sync.ts';
9
9
  import { type Lang } from './i18n.ts';
10
10
  import { type MailAccount } from './mail/account.ts';
11
11
  import { type Category } from './recur.ts';
12
- import type { SecretStore } from './secrets.ts';
12
+ import { type SecretStore } from './secrets.ts';
13
13
  import type { MishuStore } from './store.ts';
14
14
  export interface Defaults {
15
15
  language: 'auto' | Lang;
@@ -30,7 +30,9 @@ export declare function mailAccounts(store: MishuStore): MailAccount[];
30
30
  /**
31
31
  * Add (no id) or update an account. A new password, when given, goes to the
32
32
  * keychain before the account is saved, so a failed keychain write leaves
33
- * nothing half-saved.
33
+ * nothing half-saved. Without a usable keychain the password is not kept
34
+ * anywhere: the account is saved and reads it from the environment variable
35
+ * shown on the settings page (`secretEnvName`).
34
36
  */
35
37
  export declare function saveMailAccount(store: MishuStore, secrets: SecretStore, input: Partial<MailAccount>, password: string | undefined, now: number): Promise<MailAccount>;
36
38
  /** Remove an account, its keychain entry, and close what is still open from it. */
@@ -4,7 +4,7 @@
4
4
  * what you set on the settings page on top), the keychain, and one sync of
5
5
  * every source at a time.
6
6
  */
7
- import { type Defaults, type Lang, type MailAccount, type MailFetcher, type MailSyncReport, type MishuStore, type SecretStore } from '../core/index.ts';
7
+ import { type Defaults, type Lang, type MailAccount, type MailFetcher, type MailSyncReport, type MishuStore, type RestartPlan, type SecretStore, type TokenResult } from '../core/index.ts';
8
8
  import type { MishuConfig } from './config.ts';
9
9
  interface Logger {
10
10
  info(message: string): void;
@@ -17,6 +17,15 @@ export declare class Runtime {
17
17
  readonly fetcher: MailFetcher;
18
18
  private readonly logger;
19
19
  private syncing;
20
+ /** How DSH restarts; tests swap it so they never restart anything. */
21
+ restarter: {
22
+ plan(): RestartPlan;
23
+ schedule(plan: Exclude<RestartPlan, {
24
+ kind: 'none';
25
+ }>): {
26
+ log: string;
27
+ };
28
+ };
20
29
  constructor(config: MishuConfig, logger: Logger, secrets?: SecretStore, fetcher?: MailFetcher);
21
30
  defaults(): Defaults;
22
31
  settings(): Defaults;
@@ -27,6 +36,8 @@ export declare class Runtime {
27
36
  brief(lang?: Lang): string;
28
37
  /** The password for an account: keychain first, then the documented environment variable. */
29
38
  mailPassword(id: number): Promise<string | undefined>;
39
+ /** The GitHub token: environment, then the keychain, then the GitHub CLI. */
40
+ githubToken(): Promise<TokenResult>;
30
41
  private syncGithubNow;
31
42
  /** One account; the result is also kept as its last report. */
32
43
  syncMailAccount(account: MailAccount): Promise<MailSyncReport | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mishu",
3
- "version": "0.5.0",
3
+ "version": "0.5.4",
4
4
  "description": "DSH secretary (小秘书) for DeepSeek Harness (dsh): watches GitHub notifications and the dated things you tell it (bills, renewals, documents, birthdays), closes what is already resolved, and keeps a short list of what actually needs you. Bilingual (中文 / English), macOS / Windows / Linux. · DSH 小秘书:提醒、通知、待办、消息、收件箱、秘书。GitHub 通知按当前状态分诊,交代一句就记下到期和周期事项。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",