-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJafima.java
More file actions
97 lines (85 loc) · 2.88 KB
/
Jafima.java
File metadata and controls
97 lines (85 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.jafima.agents;
/*
* Jafima – Java-based Autonomous Framework for Intelligent Multi-Agent Architecture
*
* Overview:
* - Provides a modular, layered agent architecture (actions, beliefs,
* collaboration, mobility, reasoner, sensory, society, translation).
* - This entrypoint starts the `JafimaAgent` orchestrator and offers an
* optional interactive REPL for quick manual testing.
*
* Notes:
* - First check-in scaffold: layers are initialized with minimal behavior
* and can be extended incrementally.
*
* Skeleton:
* - This is skeleton placeholder code until each layer is updated from the
* original Year 2000 codebase. We are actively bringing Jafima up to date.
* Each layer will be updated and its availability will be published and
* announced.
*
* Authors: Jafima team
*/
import java.time.Instant;
import java.util.Objects;
import java.util.Scanner;
import org.jafima.agents.core.JafimaAgent;
public final class Jafima {
public static void main(String[] args) throws Exception {
CliOptions options = CliOptions.parse(args);
println("Jafima starting...");
JafimaAgent agent = new JafimaAgent();
agent.start();
if (options.interactive) {
println("Interactive mode. Type 'exit' to stop.");
try (Scanner scanner = new Scanner(System.in)) {
while (true) {
String line = scanner.nextLine();
if (line == null) break;
if ("exit".equalsIgnoreCase(line.trim())) break;
String response = agent.send(line);
println("agent> " + response);
}
}
}
if (options.blockUntilShutdown) {
println("Press Ctrl+C to stop or wait for shutdown.");
agent.blockUntilShutdown();
} else {
agent.stop();
}
println("Jafima stopped.");
}
private static void println(String s) {
System.out.println("[" + Instant.now() + "] " + s);
}
static final class CliOptions {
final boolean interactive;
final boolean blockUntilShutdown;
CliOptions(boolean interactive, boolean blockUntilShutdown) {
this.interactive = interactive;
this.blockUntilShutdown = blockUntilShutdown;
}
static CliOptions parse(String[] args) {
boolean interactive = false;
boolean block = false;
for (String a : args == null ? new String[0] : args) {
String v = a.trim().toLowerCase();
if (Objects.equals(v, "--interactive") || Objects.equals(v, "-i")) interactive = true;
else if (Objects.equals(v, "--block") || Objects.equals(v, "-b")) block = true;
else if (Objects.equals(v, "--help") || Objects.equals(v, "-h")) {
printHelpAndExit();
}
}
return new CliOptions(interactive, block);
}
static void printHelpAndExit() {
System.out.println("Usage: java -jar jafima.jar [options]\n" +
"Options:\n" +
" -i, --interactive Start interactive REPL for agent\n" +
" -b, --block Keep process running until shutdown\n" +
" -h, --help Show this help");
System.exit(0);
}
}
}