ref: 90671e4fafe7c674b2e46f60cf8fa82b782105b8
parent: 01c530c683dd814db02f49d733fbdabd7dcea5fb
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Feb 24 17:33:05 EST 2026
adds man page access
--- a/oai.c
+++ b/oai.c
@@ -15,6 +15,8 @@
static int trusted = 0;
static int quiet = 0;
+static char *callfunc(char*);
+
static int
allowed(OToolcall toolcall)
{@@ -159,6 +161,85 @@
" \"required\": [ \"file\" ]"
"}";
+static char*
+lookman(OToolcall tc, void*)
+{+ JSON *j, *jk;
+ char *s, *cmd;
+
+ if (!allowed(tc))
+ return abortcall(tc);
+
+ j = jsonparse(tc.arguments);
+ jk = jsonbyname(j, "keyword");
+ s = jsonstr(jk);
+ if (!(s && s[0]))
+ return strdup("lookman: missing keyword");+
+ cmd = smprint("lookman '%s'", s);+ jsonfree(j);
+ s = callfunc(cmd);
+ free(cmd);
+ return s;
+}
+
+static char *lookmandesc = "Search the man pages for the specified keyword. The result shows the name of the man page and the section number.";
+static char *lookmanargs = "{"+" \"type\": \"object\","
+" \"properties\": {"+" \"keyword\": {"+" \"type\": \"string\","
+" \"description\": \"keyword to search for in the man pages\""
+" }"
+" },"
+" \"required\": [ \"keyword\" ]"
+"}";
+
+static char*
+man(OToolcall tc, void*)
+{+ JSON *j, *js, *jn;
+ char *sec, *name;
+ char *s, *cmd;
+
+ if (!allowed(tc))
+ return abortcall(tc);
+
+ j = jsonparse(tc.arguments);
+ js = jsonbyname(j, "section");
+ jn = jsonbyname(j, "name");
+
+ sec = jsonstr(js);
+ name = jsonstr(jn);
+ if (!(sec && name))
+ return strdup("man: missing section or name");+
+ if (!(sec[0] && name[0]))
+ return strdup("man: empty section or name");+
+ cmd = smprint("man '%s' '%s'", sec, name);+ jsonfree(j);
+ s = callfunc(cmd);
+ free(cmd);
+ return s;
+}
+
+static char *mandesc = "get the contents of the specified man page.";
+static char *manargs = "{"+" \"type\": \"object\","
+" \"properties\": {"+" \"section\": {"+" \"type\": \"string\","
+" \"description\": \"section number of the man page\""
+" },"
+" \"name\": {"+" \"type\": \"string\","
+" \"description\": \"name of the section\""
+" }"
+" },"
+" \"required\": [ \"section\", \"name\" ]"
+"}";
+
OTool *tools = nil;
static void
@@ -166,6 +247,8 @@
{tools = maketool(tools, Function, "list_files", listfilesdesc, listfilesargs, list_files, nil);
maketool(tools, Function, "read_file", readfiledesc, readfileargs, read_file, nil);
+ maketool(tools, Function, "lookman", lookmandesc, lookmanargs, lookman, nil);
+ maketool(tools, Function, "man", mandesc, manargs, man, nil);
}
static char*
@@ -231,7 +314,7 @@
return nil;
}
-#define COMMONPROMPT "When writing code or text, you are serious and helpful. Your replies are NOT formatted as markdown. You DO NOT make a lot of words. Do NOT assume this is a unix or linux system. You first plan your steps before executing them. DO NOT simulate running commands. DO NOT invent files, folders or commands. Use the provided tools to proactively increase the context. Use the tools to solve the problem."
+#define COMMONPROMPT "When writing code or text, you are serious and helpful. Your replies are NOT formatted as markdown. You DO NOT make a lot of words. Do NOT assume this is a unix or linux system. You first plan your steps before executing them. DO NOT simulate running commands. DO NOT invent files, folders or commands. Use the provided tools to proactively increase the context. Use the tools to solve the problem. Learn about Plan 9 by reading the 0intro man page in section 1. If unsure, search the man pages."
char *plan9prompt = "You are a helpful AI assistant on a Plan 9 system. Your name is Glenda. Your tone is serious. Be friendly and concise.\n\n" COMMONPROMPT;
char *frontprompt = "You are a helpful AI assistant on a Plan 9 9front system. Your name is Glenda. You are sometimes trolling. Be concise.\n\n" COMMONPROMPT;
--- a/oailib.c
+++ b/oailib.c
@@ -475,6 +475,11 @@
JSON *jres;
jreq = req2json(req);
+ if (!jreq) {+ fprint(2, "error: %r\n");
+ ret.success = 0;
+ return ret;
+ }
ctlfd = open("/mnt/web/clone", ORDWR);if (ctlfd < 0)
--
⑨