@haaaiawd/second-nature 0.1.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.
package/index.ts ADDED
@@ -0,0 +1,157 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ interface RegisterApi {
4
+ registerService(service: { id: string; start: () => unknown }): void;
5
+ registerCli(registrar: (ctx: { program: unknown }) => void, options?: { commands?: string[] }): void;
6
+ registerCommand(command: {
7
+ name: string;
8
+ description: string;
9
+ acceptsArgs?: boolean;
10
+ handler: (ctx: { args?: string }) => Promise<{ text: string }> | { text: string };
11
+ }): void;
12
+ registerTool(tool: unknown, options?: unknown): void;
13
+ }
14
+
15
+ const lifecycleState = {
16
+ registerCount: 0,
17
+ };
18
+
19
+ function createFallbackCommands(): Array<{
20
+ name: string;
21
+ description: string;
22
+ execute: (input?: Record<string, unknown>) => Promise<Record<string, unknown>>;
23
+ }> {
24
+ const commandNames = ["status", "policy", "credential", "quiet", "report", "session", "audit", "explain"];
25
+
26
+ return commandNames.map((name) => ({
27
+ name,
28
+ description: `Fallback command shell for ${name}`,
29
+ execute: async (_input?: Record<string, unknown>) => ({
30
+ ok: false,
31
+ command: name,
32
+ message: "Plugin loaded in packaging fallback mode; reinstall full workspace build for command runtime.",
33
+ }),
34
+ }));
35
+ }
36
+
37
+ function resolveCommandRouterSafe(): {
38
+ commands: Array<{ name: string; description: string; execute: (input?: Record<string, unknown>) => Promise<Record<string, unknown>> }>;
39
+ resolve(name: string): { name: string; description: string; execute: (input?: Record<string, unknown>) => Promise<Record<string, unknown>> } | undefined;
40
+ } {
41
+ const require = createRequire(import.meta.url);
42
+
43
+ try {
44
+ const mod = require("../src/cli/index.js") as { createCommandRouter: () => { commands: any[]; resolve: (name: string) => any } };
45
+ if (mod?.createCommandRouter) {
46
+ return mod.createCommandRouter();
47
+ }
48
+ } catch {
49
+ // fall through to fallback router
50
+ }
51
+
52
+ const commands = createFallbackCommands();
53
+ return {
54
+ commands,
55
+ resolve(name: string) {
56
+ return commands.find((command) => command.name === name);
57
+ },
58
+ };
59
+ }
60
+
61
+ const serviceShell = {
62
+ id: "second-nature-runtime",
63
+ start() {
64
+ return;
65
+ },
66
+ };
67
+
68
+ export default {
69
+ id: "second-nature",
70
+ name: "Second Nature",
71
+ description: "Registers command/tool/service surface with load-reload lifecycle semantics.",
72
+ register(api: RegisterApi) {
73
+ lifecycleState.registerCount += 1;
74
+ const lifecycleEvent = lifecycleState.registerCount === 1 ? "load" : "reload";
75
+ const router = resolveCommandRouterSafe();
76
+
77
+ api.registerService(serviceShell);
78
+
79
+ api.registerService({
80
+ id: "second-nature-lifecycle",
81
+ start() {
82
+ return;
83
+ },
84
+ });
85
+
86
+ api.registerCli(
87
+ ({ program }) => {
88
+ void program;
89
+ },
90
+ { commands: ["second-nature"] },
91
+ );
92
+
93
+ api.registerCommand({
94
+ name: "second-nature",
95
+ description: "Route Agent-facing operational commands for Second Nature.",
96
+ acceptsArgs: true,
97
+ handler: async (ctx: { args?: string }) => {
98
+ const command = ctx.args?.trim();
99
+ if (!command) {
100
+ return {
101
+ text: JSON.stringify({ ok: false, message: "Missing command argument." }),
102
+ };
103
+ }
104
+
105
+ const resolved = router.resolve(command);
106
+ if (!resolved) {
107
+ return {
108
+ text: JSON.stringify({ ok: false, command, message: "Unknown Second Nature command." }),
109
+ };
110
+ }
111
+
112
+ const result = await resolved.execute();
113
+ return {
114
+ text: JSON.stringify(result),
115
+ };
116
+ },
117
+ });
118
+
119
+ api.registerTool({
120
+ name: "second_nature_ops",
121
+ description: "Access the Second Nature command surface through a single tool shell.",
122
+ parameters: {
123
+ type: "object",
124
+ additionalProperties: false,
125
+ properties: {
126
+ command: { type: "string" },
127
+ args: { type: "object", additionalProperties: true }
128
+ },
129
+ required: ["command"]
130
+ },
131
+ async execute(_id: string, params: { command: string; args?: Record<string, unknown> }) {
132
+ const resolved = router.resolve(params.command);
133
+ if (!resolved) {
134
+ return {
135
+ content: [
136
+ {
137
+ type: "text",
138
+ text: JSON.stringify({ ok: false, message: "Unknown Second Nature command." }),
139
+ },
140
+ ],
141
+ };
142
+ }
143
+
144
+ const result = await resolved.execute(params.args);
145
+
146
+ return {
147
+ content: [
148
+ {
149
+ type: "text",
150
+ text: JSON.stringify(result),
151
+ },
152
+ ],
153
+ };
154
+ },
155
+ });
156
+ },
157
+ };
@@ -0,0 +1,17 @@
1
+ {
2
+ "id": "second-nature",
3
+ "name": "Second Nature",
4
+ "version": "0.1.0",
5
+ "entry": "./index.ts",
6
+ "description": "OpenClaw native plugin package for continuity, explain, and recovery operations.",
7
+ "capabilities": {
8
+ "commands": ["second-nature"],
9
+ "tools": ["second_nature_ops"],
10
+ "services": ["second-nature-runtime", "second-nature-lifecycle"]
11
+ },
12
+ "configSchema": {
13
+ "type": "object",
14
+ "additionalProperties": false,
15
+ "properties": {}
16
+ }
17
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@haaaiawd/second-nature",
3
+ "version": "0.1.1",
4
+ "description": "OpenClaw native plugin for long-running agent continuity, Quiet memory curation, and explainable operator flows.",
5
+ "keywords": [
6
+ "openclaw",
7
+ "plugin",
8
+ "agent",
9
+ "continuity",
10
+ "quiet",
11
+ "memory",
12
+ "observability",
13
+ "operator"
14
+ ],
15
+ "license": "Apache-2.0",
16
+ "type": "module",
17
+ "main": "./index.ts",
18
+ "files": [
19
+ "index.ts",
20
+ "openclaw.plugin.json"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "openclaw": {
26
+ "manifest": "./openclaw.plugin.json",
27
+ "extensions": [
28
+ "./index.ts"
29
+ ]
30
+ }
31
+ }